如何让Dialog响应WM_CHAR消息
展开全部
为了截获键盘击键的值,需要用到WM_CHAR消息。但在Project中添加该消息后会发现,程序无法响应该消息。即击键后程序并没有执行到该消息对应的函数处。参考MSDN对该消息的描述:This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function. 关键的意思是要执行WM_CHAR消息,程序焦点必须在主窗口上。但不幸的是,程序运行以后,焦点在按钮上。解决的方式是使用PreTranslateMessage消息,进行处理,将焦点设置到主窗口上。具体代码如下:BOOL CTTDlg::PreTranslateMessage(MSG* pMsg){// TODO: Add your specialized code here and/or call the base class if ( pMsg->message == WM_KEYDOWN ||pMsg->message == WM_CHAR){pMsg->hwnd = m_hWnd;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询