MFC dialog Box Dialog response keyboard events (key combination CTRL + a)

Source: Internet
Author: User

On the basis of the previous article, we describe how to capture the key combinations here, with Ctrl + A as an example
This is done by holding down CTRL with a static member variable to save CTRL is pressed, set to True when CTRL is pressed, and set to False when the CTRL key is lifted

Other key combinations are developed using this example extrapolate.

Header File Declaration

    BOOL PreTranslateMessage(MSG* pMsg);

source file definition

BOOLCmfcdlg::P retranslatemessage (msg* pMsg) {Static BOOLM_ctrl_down =false;//This function is initialized when first called    if(Pmsg->message = = Wm_keydown) {Switch(Pmsg->wparam) {//vk_a-vk_z is the same as ASCII ' A '-' Z ' (0x41-0x5a) is case insensitive         Case ' A '://ctrl + A            if(M_ctrl_down) {AfxMessageBox (_t ("Ctrl + A key Down"));return TRUE; } Break; CaseVk_control:m_ctrl_down =true;return TRUE;default:return TRUE; }    }if(Pmsg->message = = Wm_keyup) {Switch(Pmsg->wparam) { CaseVk_control:m_ctrl_down =false;return TRUE; }    }returnCDialogEx::P retranslatemessage (PMSG);}

MFC dialog Box Dialog response keyboard events (key combination CTRL + a)

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.