⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 right14-1.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>第 14 章</title>
<base target="rbottom">
<style>
<!--
.右标题   { font-size: 10pt; color: #000080; text-indent: 0; margin: 0 }
.右内容   { font-size: 10pt; text-align: left; text-indent: 0; line-height: 100%; margin: 
               0 }
-->
</style>
</head>

<body>

<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="position: absolute; left: 4; top: -8"><img border="0" src="1.gif" width="63" height="70"></span></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                                         
&nbsp;&nbsp;&nbsp; <span style="background-color: #CCFF99">第 14 章</span><span style="background-color: #CCFF99">&nbsp;                                                
</span>&gt;<span style="background-color: #CCFF99"> 第 1 节 </span>&gt;<span style="background-color: #CCFF99">  
 14.1 控件概述</span></p>                   
<hr color="#008000" size="1">

<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">虽然控件的外观和功能各不相同,但它们是都是以子窗口的形式存在的,在控件创建、消息处理和控制方面有许多相似之处。</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">1.   
<font LANG="ZH-CN">控件</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><a href="picture14-1.htm"><font lang="ZH-CN" size="2">控件示例图</font></a></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">2.   
<font LANG="ZH-CN">控件的创建</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">控件的创建方式有两种。</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 10; margin-bottom: 0"><font LANG="ZH-CN" size="2">(1)   
在对话框中指定控件</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">先创建对话框资源和控件资源,在对话框中指定控件,这样当应用程序启动该对话框时就可以为对话框指定控件。</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">在对话框中创建控件的一般形式为:</font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">Control-type   
    [Title,] ID,X,Y,nWidth,nHeight[,Style]</font></p>  
  </blockquote>
</blockquote>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">其中:</font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Control-type<font LANG="ZH-CN">为控件类型,常用对话框控件类型及其说明见<a href="table14-1.htm" target="_blank">表</a></font><a href="table14-1.htm" target="_blank">14-1</a><font LANG="ZH-CN">。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Style<font LANG="ZH-CN">为控件的样式。控件创建过程的重点是控件样式的选取。不同样式的选取不但关系到控件的外形,而且决定控件所能实现的功能。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 10; margin-bottom: 0"><font LANG="ZH-CN" size="2">(2)   
调用函数创建控件</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">可以调用函数</font>CreateWindow(   
)<font LANG="ZH-CN">或</font>CreateWindowEx( )<font LANG="ZH-CN">来创建控件。用</font>CreateWindow(   
)<font LANG="ZH-CN">或</font>CreateWindowEx( )<font LANG="ZH-CN">函数创建窗口类控件,必须指定控件的窗口类,通常程序员使用的是</font>Windows<font LANG="ZH-CN">系统预定义的窗口类。</font></font></p>  
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN"><a href="table14-2.htm" target="_blank">表</a></font><a href="table14-2.htm" target="_blank">14-2</a><font LANG="ZH-CN">列出静态控件、按钮、滚动条等六种常见的控件所预定义的窗口类。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">3.   
<font LANG="ZH-CN">控件的消息</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">应用程序可以向控件发消息,控件也可以向应用程序发消息,此类消息被称为通知消息。</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 10; margin-bottom: 0"><font LANG="ZH-CN" size="2">(1)   
向应用程序发送消息</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">当子窗口控件的状态发生改变时,控件通过向其父窗口(应用程序窗口)发</font>WM_COMMAND<font LANG="ZH-CN">消息进行通信。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 10; margin-bottom: 0"><font LANG="ZH-CN" size="2">(2)   
向控件发送消息</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN"><span style="font-size:10.5pt;mso-bidi-font-size:10.0pt;
font-family:宋体;mso-bidi-font-family:&quot;Times New Roman&quot;;mso-font-kerning:10.5pt;
mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">① </span>应用程序窗口可调用函数</font>SendMessage<font LANG="ZH-CN">向特定的子窗口发送消息,以指示其动作。函数</font>SendMessage<font LANG="ZH-CN">的原型如下:</font></font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">LRESULT   
    SendMessage(HWND hWnd<font LANG="ZH-CN">,</font>UINT Msg<font LANG="ZH-CN">,</font>WPARAM   
    wParam<font LANG="ZH-CN">,</font>LPARAM lParam)<font LANG="ZH-CN">;</font></font></p>  
  </blockquote>
</blockquote>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">参数说明:</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">hWnd<font LANG="ZH-CN">:其窗口程序将接收消息的窗口句柄。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">如用户单击单选按钮时,应用程序窗口可调用函数</font>SendMessage<font LANG="ZH-CN">向该单选按钮发送</font>BM_SETCHECK<font LANG="ZH-CN">消息,为该按钮设置选中符号,其原型为:</font></font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">SendMessage(hwndRadioButton,BM_SETCHECK,1,0)<font LANG="ZH-CN">;</font></font></p>
  </blockquote>
</blockquote>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2"><span style="font-size:10.5pt;mso-bidi-font-size:10.0pt;
font-family:宋体;mso-bidi-font-family:&quot;Times New Roman&quot;;mso-font-kerning:10.5pt;
mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">②</span></font><font size="2"><font LANG="ZH-CN"><span style="font-size: 10.5pt; mso-bidi-font-size: 10.0pt; font-family: 宋体; mso-bidi-font-family: Times New Roman; mso-font-kerning: 10.5pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"> 
</span>使用对话框控件时,应用程序可调用函数</font>SendDlgItemMessage<font LANG="ZH-CN">向指定的对话框控件发送消息,其原型为:</font></font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">LONG   
    SendDlgltemMessage(HWND hDlg,int nIDDlgltem,UINT Msg,WPARAM wParam,LPARAM   
    lParam);</font></p>
  </blockquote>
</blockquote>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">参数说明:</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">hDlg<font LANG="ZH-CN">:指定含有控件的对话框。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">nIDDigltem<font LANG="ZH-CN">:指定接收消息的控件的标识符。</font></font></p>
<font SIZE="3">
</font>

<hr size="1" color="#008000">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>            

<p style="line-height: 100%; margin-top: 0; margin-bottom: 0">&nbsp;&nbsp; <span style="position: absolute; left: 34; top: 913"><a href="right13-3.htm" target="_self"><img border="0" src="rightd1.gif" width="113" height="70"></a></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="position: absolute; left: 504; top: 917"><a href="right14-2.htm" target="_self"><img border="0" src="rightd2.gif" width="124" height="63"></a></span></p>                   

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -