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

📄 right13-2.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 HTM
📖 第 1 页 / 共 3 页
字号:
    </td>
    <td width="251" valign="top" style="mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right: .5pt solid windowtext; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><font size="2"><span style="mso-bidi-font-size: 10.0pt; font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">按下了鼠标的左键,等同于</span><span lang="EN-US" style="mso-bidi-font-size: 10.0pt">WM_LBUTTON<o:p>
      </o:p> 
      </span></font></p>
    </td>
    <td width="104" valign="top" style="mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right: .5pt solid windowtext; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><span lang="EN-US" style="mso-bidi-font-size: 10.0pt"><font size="2">MK_CONTROL<o:p>
      </o:p>
      </font></span></p>
    </td>
    <td width="134" valign="top" style="mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><font size="2"><span style="mso-bidi-font-size: 10.0pt; font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">按下了键盘上的</span><span lang="EN-US" style="mso-bidi-font-size: 10.0pt">Ctrl</span><span style="mso-bidi-font-size: 10.0pt; font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">键</span><span lang="EN-US" style="mso-bidi-font-size: 10.0pt"><o:p>
      </o:p>
      </span></font></p>
    </td>
  </tr>
  <tr>
    <td width="92" valign="top" style="mso-border-top-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right: .5pt solid windowtext; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><span lang="EN-US" style="mso-bidi-font-size: 10.0pt"><font size="2">MK_MBUTTON<o:p>
      </o:p> 
      </font></span></p>
    </td>
    <td width="251" valign="top" style="mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right: .5pt solid windowtext; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><font size="2"><span style="mso-bidi-font-size: 10.0pt; font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">按下了鼠标的中键,等同于</span><span lang="EN-US" style="mso-bidi-font-size: 10.0pt">WM_MBUTTON<o:p>
      </o:p> 
      </span></font></p>
    </td>
    <td width="104" valign="top" style="mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right: .5pt solid windowtext; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><span lang="EN-US" style="mso-bidi-font-size: 10.0pt"><font size="2">MK_SHIFT<o:p>
      </o:p>
      </font></span></p>
    </td>
    <td width="134" valign="top" style="mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><font size="2"><span style="mso-bidi-font-size: 10.0pt; font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">按下了键盘上的</span><span lang="EN-US" style="mso-bidi-font-size: 10.0pt">Shift</span><span style="mso-bidi-font-size: 10.0pt; font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">键</span><span lang="EN-US" style="mso-bidi-font-size: 10.0pt"><o:p>
      </o:p>
      </span></font></p>
    </td>
  </tr>
  <tr>
    <td width="92" valign="top" style="mso-border-top-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right: .5pt solid windowtext; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><span lang="EN-US" style="mso-bidi-font-size: 10.0pt"><font size="2">MK_RBUTTON<o:p>
      </o:p> 
      </font></span></p>
    </td>
    <td width="251" valign="top" style="mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right: .5pt solid windowtext; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><font size="2"><span style="mso-bidi-font-size: 10.0pt; font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">按下了鼠标的右键,等同于</span><span lang="EN-US" style="mso-bidi-font-size: 10.0pt">WM_MBUTTON<o:p>
      </o:p> 
      </span></font></p>
    </td>
    <td width="104" valign="top" style="mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right: .5pt solid windowtext; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><font size="2">&nbsp;<span lang="EN-US" style="mso-bidi-font-size: 10.0pt"><o:p>
      </o:p>
      </span></font></p>
    </td>
    <td width="134" valign="top" style="mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom: .5pt solid windowtext; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; padding-bottom: 0cm">
      <p class="MsoNormal"><font size="2">&nbsp;<span lang="EN-US" style="mso-bidi-font-size: 10.0pt"><o:p>
      </o:p>
      </span></font></p>
    </td>
  </tr>
</table>
<p ALIGN="justify" style="line-height: 150%; 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>
<blockquote>
  <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">1.  
  不检测SHIFT键和CTRL键的状态</font></p>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">case  
    WM_LBUTTONDOWN: //<font LANG="ZH-CN">鼠标左键被按下</font></font></p> 
    <font SIZE="1">
    <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">break;</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">case  
    WM_LBUTTONUP:&nbsp; //<font LANG="ZH-CN">鼠标左键被释放</font></font></p> 
    <font SIZE="1">
    <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">break;</font></p>
  </blockquote>
  <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">2.  
  检测SHIFT键和CTRL键的状态</font></p>
  <blockquote>
    <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">case  
    WM_LBUTTONDOWN: //<font LANG="ZH-CN">鼠标左键被按下</font></font></p> 
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">if((wParam&amp;MK_CONTROL)&amp;&amp;(wParam&amp;MK_SHIFT))  
    //SHIFT<font LANG="ZH-CN">键和</font>CTRL<font LANG="ZH-CN">都被按下</font></font></p>
    <font SIZE="1">
    <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">break;</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">case  
    WM_LBUTTONUP:&nbsp; //<font LANG="ZH-CN">鼠标左键被释放</font></font></p> 
    <font SIZE="1">
    <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">break;</font></p>
  </blockquote>
</blockquote>
<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 size="2"><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"><font size="2"><font LANG="ZH-CN">要实现鼠标的捕获,可以使用函数</font>SetCapture<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">SetCapture(hWnd);</font></p>
  </blockquote>
</blockquote>
<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>Windows向<font LANG="ZH-CN">窗口句柄为</font>hWnd<font LANG="ZH-CN">的窗口发送所有的鼠标消息,此时鼠标光标的坐标仍然相对于客户区左上角,因此此时鼠标位置值有可能为负值。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">一旦某个窗口捕获了鼠标,系统的键盘功能会失效,其它窗口将无法得到鼠标消息,因此,当窗口不再需要捕获鼠标消息时,应及时使用</font><font color="#008000">ReleaseCapture</font><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">4.  
<font LANG="ZH-CN">鼠标应用示例</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN"><a href="example13-2.htm" target="_blank">【例</a></font><a href="example13-2.htm" target="_blank">13-2<font LANG="ZH-CN">】</font></a><font LANG="ZH-CN">单击鼠标左键并拖动鼠标画出一个矩形框,放开鼠标的左键,填充矩形框。</font></font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left"> </p>

<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: 32; top: 1104"><a href="right13-1.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: 503; top: 1113"><a href="right13-3.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 + -