MFC dialog Box Dialog response keyboard events

Source: Internet
Author: User
  1. OnKeyDown, No.

The dialog program originally did not respond directly to keyboard events, and if you use onkeydown you will find that it does not work.
So you want to press "left button", "W Key", "9 keyboard" should be how to respond?
the bool PreTranslateMessage (msg* PMSG) function of the overloaded base class

  1. The simplest keyboard response function

Header File declaration:
BOOL PreTranslateMessage (msg* pMsg);
source file Definition:
BOOL Cmfcdlg::P retranslatemessage (msg* pMsg)
{
if (pmsg->message = = Wm_keydown)
{
Switch (Pmsg->wparam)
{
Case vk_escape://Shielded ESCAPE key
return TRUE;
Vk_a-vk_z is the same as ASCII ' A '-' Z ' (0x41-0x5a) is case insensitive
Case ' A ':
AfxMessageBox (_t ("A key Down"); return TRUE;
Case Vk_right:
AfxMessageBox (_t ("-Key Down")); return TRUE;
Case ' 0 ':
AfxMessageBox (_t ("0 key Down"); return TRUE;
Default
return TRUE;
}
}
return CDialogEx::P retranslatemessage (PMSG);
}

MFC dialog Box Dialog response keyboard events

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.