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

📄 2_1_2.htm

📁 何志丹讲VC学习
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html>

<head>
<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>增加消息映射项</title>
</head>

<body>

<table border="0" width="1024" height="542">
  <tr>
    <td width="800" height="200">
    <iframe id=adframe marginwidth=0 marginheight=0 frameborder=0 scrolling=no src='..\..\top.htm' width=800 height=200></iframe>
    </td>
    <td rowspan="3" height="224" valign="top" align="left">
    <iframe id=adframe marginwidth=0 marginheight=0 frameborder=0 scrolling=no src='..\..\right.htm' width=224 height=600></iframe>
    </td>
  </tr>
  <tr>
    <td width="800" height="8"> 
      <h3><span lang="EN-US">1.2.2<span style="mso-spacerun: yes">&nbsp; </span></span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">增加消息映射项</span></h3>
      <p class="MsoNormal"><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">本节介绍了如何增加消息映射项。</span></p>
      <h4><span lang="EN-US">1</span><span style="font-family:黑体;mso-ascii-font-family:
&quot;Times New Roman&quot;">.实例说明</span></h4>
      <p class="MsoNormal"><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">本示例是一个简单的打字练习软件,程序在第一个编辑框随机显示一个大写字母,当用户在第</span><span lang="EN-US">2</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">个编辑框中输入一个字符后,程序会在第一个编辑框中重新显示一个新字符。用户单击“确定”按钮结束练习时,可以获得正确输入的总次数,效果如图</span><span lang="EN-US">1-46</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">所示。</span></p>
      <p class="MsoNormal" align="center" style="text-align:center"><span lang="EN-US"><!--[if gte vml 1]><v:shapetype
 id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
 path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
 <v:stroke joinstyle="miter"/>
 <v:formulas>
  <v:f eqn="if lineDrawn pixelLineWidth 0"/>
  <v:f eqn="sum @0 1 0"/>
  <v:f eqn="sum 0 0 @1"/>
  <v:f eqn="prod @2 1 2"/>
  <v:f eqn="prod @3 21600 pixelWidth"/>
  <v:f eqn="prod @3 21600 pixelHeight"/>
  <v:f eqn="sum @0 0 1"/>
  <v:f eqn="prod @6 1 2"/>
  <v:f eqn="prod @7 21600 pixelWidth"/>
  <v:f eqn="sum @8 21600 0"/>
  <v:f eqn="prod @7 21600 pixelHeight"/>
  <v:f eqn="sum @10 21600 0"/>
 </v:formulas>
 <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
 <o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:186.75pt;
 height:110.25pt'>
 <v:imagedata src="file:///C:/DOCUME~1/user/LOCALS~1/Temp/msoclip1/01/clip_image001.png"
  o:title=""/>
</v:shape><![endif]-->
      <img src="2_1_2.1.jpg" v:shapes="_x0000_i1025" width="249" height="147"></span></p>
      <p class="a0"><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">图</span><span lang="EN-US">1-46 
      Ex010202.exe</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">效果图</span></p>
      <p class="MsoNormal" align="center" style="text-align:center"><span lang="EN-US">&nbsp;<o:p>
      </o:p>
      </span></p>
      <h4><span lang="EN-US">2</span><span style="font-family:黑体;mso-ascii-font-family:
&quot;Times New Roman&quot;">.实现</span></h4>
      <p class="MsoNormal"><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">本实例的具体操作步骤如下。</span></p>
      <p class="a5"><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">(</span><span lang="EN-US">1</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">)新建一个基于对话框的工程</span><span lang="EN-US">Ex010202</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">。</span></p>
      <p class="a5"><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">(</span><span lang="EN-US">2</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">)在对话框上增加两个编辑框,</span><span lang="EN-US">ID</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">分别为</span><span lang="EN-US">ID_SHOW</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">和</span><span lang="EN-US">ID_INPUT</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">。打开类向导,为</span><span lang="EN-US">ID_SHOW</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">关联一个</span><span lang="EN-US">CEdit</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">型的变量</span><span lang="EN-US">m_show</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">,为</span><span lang="EN-US">ID_INPUT</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">关联一个</span><span lang="EN-US">CEdit</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">型的变量</span><span lang="EN-US">m_input</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">。</span></p>
      <p class="a5"><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">(</span><span lang="EN-US">3</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">)打开类向导,类名和</span><span lang="EN-US">Object 
      IDs</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">都选择</span><span lang="EN-US">CEx010202Dlg</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">,</span><span lang="EN-US">Messages</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">中选择</span><span lang="EN-US">WM_INITDIALOG</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">,类向导会自动选中对应的函数,双击此函数就可以编辑它了,如图</span><span lang="EN-US">1-47</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">所示。</span></p>
      <p class="a5" align="center" style="margin-left:0cm;text-align:center"><span lang="EN-US"><!--[if gte vml 1]><v:shape id="_x0000_i1026" type="#_x0000_t75"
 style='width:313.5pt;height:204pt'>
 <v:imagedata src="file:///C:/DOCUME~1/user/LOCALS~1/Temp/msoclip1/01/clip_image003.png"
  o:title=""/>
</v:shape><![endif]-->
      <img src="2_1_2.2.jpg" v:shapes="_x0000_i1026" width="418" height="272"></span></p>
      <p class="a0"><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">图</span><span lang="EN-US">1-47<span style="mso-spacerun: yes">&nbsp; 
      </span></span><span style="font-family:宋体;
mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">编辑函数</span></p>
      <p class="a5"><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">(</span><span lang="EN-US">4</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">)在此函数中禁用第一个编辑框,并为它生成初始值。</span></p>
      <p class="ac"><span lang="EN-US">BOOL CEx010202Dlg::OnInitDialog()</span></p>
      <p class="ac"><span lang="EN-US">{</span></p>
      <p class="ac"><span lang="EN-US"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </span>CDialog::OnInitDialog();</span></p>
      <p class="ac"><span lang="EN-US">&nbsp;<o:p>
      </o:p>
      </span></p>
      <p class="ac"><span lang="EN-US"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </span>m_show.SetReadOnly();//</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">设置只读</span></p>
      <p class="ac"><span lang="EN-US"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </span>char ch = 'A' + rand()% 26 ;//</span><span style="font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">随机生成一个大写字母</span></p>
      <p class="ac"><span lang="EN-US"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </span>CString strShow = ch ;</span></p>
      <p class="ac"><span lang="EN-US"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </span>m_show.SetWindowText(strShow);</span></p>
      <p class="ac"><span lang="EN-US">//…</span></p>
      <p class="ac"><span lang="EN-US">}</span></p>
      <p class="a5"><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">(</span><span lang="EN-US">5</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">)为</span><span lang="EN-US">CEx010202Dlg</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">类增加一个保护级的成员变量</span><span lang="EN-US">int 
      m_iRightNum</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">,并在</span><span lang="EN-US">CEx010202Dlg</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">类的构造函数中将其初始化为零,此变量用来记录正确输入次数。</span></p>
      <p class="a5"><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">(</span><span lang="EN-US">6</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">)当用户输入后,必须检查用户的输入是否正确,并重新生成数据。打开类向导,类名选择</span><span lang="EN-US">CEx010202Dlg</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">,“</span><span lang="EN-US">Object IDs</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">”选择“</span><span lang="EN-US">IDC_INPUT</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">”,“</span><span lang="EN-US">Messages</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">”选择“</span><span lang="EN-US">EN_CHANGE</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">”,单击“</span><span lang="EN-US">Add 
      Function</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:&quot;Times New Roman&quot;">”按钮,如图</span><span lang="EN-US">1-48</span><span style="font-family:楷体_GB2312;mso-ascii-font-family:
&quot;Times New Roman&quot;">所示。</span></p>
      <p class="MsoNormal" align="center" style="text-align:center;text-indent:0cm"><span lang="EN-US"><!--[if gte vml 1]><v:shape id="_x0000_i1027" type="#_x0000_t75"
 style='width:313.5pt;height:204pt'>
 <v:imagedata src="file:///C:/DOCUME~1/user/LOCALS~1/Temp/msoclip1/01/clip_image005.png"
  o:title=""/>
</v:shape><![endif]-->
      <img src="2_1_2.3.jpg" v:shapes="_x0000_i1027" width="418" height="272"></span></p>

⌨️ 快捷键说明

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