MFC receives keyboard input instructions

Source: Internet
Author: User

It is a very common function for the program to receive keyboard input and to make corresponding feedback, which is provided in MFC wm_keydown,wm_keyup These messages to our programming, but this is only applicable if the form has no other controls. When there are other controls, other controls (which are actually forms) will definitely have a focus to invalidate these messages, and we can do this by overloading the PreTranslateMessage (msg* pMsg) virtual function of the dialog program.

First, in the dialog box class, first declare the following:

BOOL PreTranslateMessage (msg* pMsg);
you can then process the keyboard message directly, as shown in the following example:

BOOL DLG::P retranslatemessage (msg* pMsg)//dlg for dialog box class {if (Pmsg->message = wm_keydown) {switch (Pmsg->wparam) {case vk_up:printf ("up\n"); Break;case vk_down:printf ("down\n"); Break;case vk_left:printf ("left\n"); Break;case vk_right:printf ("right\n"); Break;default:break;}} Return CDialog::P retranslatemessage (PMSG);}
This code can also be found, we can not only respond to the keyboard message, as long as you want to, you can define a message loop here to handle what you want to do.




MFC receives keyboard input instructions

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.