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

📄 subject_28916.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:28916 发表者:乔毅 发表日期:2003-01-26 01:01:47
<br>主题:当对话框为主窗口的时候,如何对键盘输入进行处理?
<br>内容:书上说采用快捷方式,可是写得不清晰.请告诉我在产生WM_COMMAND后,该怎么办?<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:tjhe 回复日期:2003-01-26 01:13:23
<br>内容:http://www.copathway.com/cndevforum/subject_view.asp?subject_id=27754&amp;forum_id=59<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:tjhe 回复日期:2003-01-26 01:56:36
<br>内容:WM_COMMAND :<BR>WORD wNotifyCode = HIWORD(wParam); // notification code <BR>WORD wID = LOWORD(wParam);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // item, control, or accelerator identifier <BR>HWND hwndCtl = (HWND) lParam;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// handle of control <BR><BR>//<BR>BOOL CMyDlg::OnCommand(WPARAM wParam, LPARAM lParam) <BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;// TODO: Add your specialized code here and/or call the base class<BR>&nbsp;&nbsp;&nbsp;&nbsp;WORD wID = LOWORD(wParam);&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch(wID)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case ID_XXXXX:&nbsp;&nbsp;&nbsp;&nbsp; //与某键对应的命令ID<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox("you select some key");&nbsp;&nbsp; //某键<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ......<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;return CDialog::OnCommand(wParam, lParam);<BR>}<BR><BR>//也可直接在PreTranslateMessage(pMsg)处理按键消息:<BR>BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) <BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;// TODO: Add your specialized code here and/or call the base class<BR>&nbsp;&nbsp;&nbsp;&nbsp;::TranslateAccelerator(this-&gt;GetSafeHwnd(),m_hAccel,pMsg);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(pMsg-&gt;message == WM_KEYDOWN)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int nVirtKey = (int)(pMsg-&gt;wParam);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(nVirtKey)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case VK_LEFT:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox("Left");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case VK_RIGHT:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox("Right");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return CDialog::PreTranslateMessage(pMsg);<BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:乔毅 回复日期:2003-01-27 11:10:44
<br>内容:我想知道在lparam中有什么具体的消息内容?如果我想得到wm_keydown()中的nRepCnt,nFlags的参数怎么办?<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:tjhe 回复日期:2003-01-27 16:45:00
<br>内容:WM_KEYDOWN <BR>nVirtKey = (int) wParam;&nbsp;&nbsp;&nbsp;&nbsp;// virtual-key code <BR>lKeyData = lParam;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// key data <BR> <BR>Parameters<BR>nVirtKey <BR>Value of wParam. Specifies the virtual-key code of the nonsystem key. <BR>lKeyData <BR>Value of lParam. Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. Value Description <BR>0–15 Specifies the repeat count for the current message. The value is the number of times the keystroke is auto-repeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative. //重复次数<BR>16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM). //扫描码<BR>24 Specifies whether the key is an extended key, such as the right-hand alt and ctrl keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. //是否扩展键<BR>25–28 Reserved; do not use. <BR>29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message. <BR>30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up. <BR>31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN message. <BR><BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:tjhe 回复日期:2003-01-27 16:49:40
<br>内容:nRepCnt = LOWORD(lParam);<BR>nFlags = HIWORD(lParam);
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

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