Return key response

Source: Internet
Author: User

Most of the time, you need to click a button after entering the parameter to perform some operations. More people are used to hitting the Enter key on the keyboard to respond to the event.

So how to respond to the Return key?

Of course, if we use the system's default OK key in MFC as the response key, no additional settings are needed. However, we often have a response to the manually added button.

Search for example:

Enter a keyword in the text box and press the Enter key to respond to the filter key.

In essence: The response Keyboard Message is to reload the pretranslatemessage () function.

Bool ctestdlg: pretranslatemessage (MSG * PMSG)
{
// Todo: Add dedicated code and/or call the base class here

Switch (PMSG-> message)
{
Case wm_keydown:
Switch (PMSG-> wparam)
{
// Process the Escape key message
Case vk_escape:
Return true;
Case vk_return:
If (: getdlgctrlid (PMSG-> hwnd) = idc_edit1) // text box ID: idc_edit1
{// Button ID: idc_button1
Postmessage (wm_command, makewparam (idc_button1, bn_clicked), (lparam) getdlgitem (idc_button1)-> m_hwnd );

}
Return true;
Default:
Break;
}
Break;
Default:
Break;
}
Return cdialog: pretranslatemessage (PMSG );
}

 

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.