📄 subject_28916.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&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); // item, control, or accelerator identifier <BR>HWND hwndCtl = (HWND) lParam; // handle of control <BR><BR>//<BR>BOOL CMyDlg::OnCommand(WPARAM wParam, LPARAM lParam) <BR>{<BR> // TODO: Add your specialized code here and/or call the base class<BR> WORD wID = LOWORD(wParam); <BR> switch(wID)<BR> {<BR> case ID_XXXXX: //与某键对应的命令ID<BR> AfxMessageBox("you select some key"); //某键<BR> break;<BR> ......<BR> }<BR> return CDialog::OnCommand(wParam, lParam);<BR>}<BR><BR>//也可直接在PreTranslateMessage(pMsg)处理按键消息:<BR>BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) <BR>{<BR> // TODO: Add your specialized code here and/or call the base class<BR> ::TranslateAccelerator(this->GetSafeHwnd(),m_hAccel,pMsg);<BR> if(pMsg->message == WM_KEYDOWN)<BR> {<BR> int nVirtKey = (int)(pMsg->wParam);<BR> switch(nVirtKey)<BR> {<BR> case VK_LEFT:<BR> AfxMessageBox("Left");<BR> break;<BR> case VK_RIGHT:<BR> AfxMessageBox("Right");<BR> break;<BR> }<BR><BR> }<BR> 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; // virtual-key code <BR>lKeyData = lParam; // 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 + -