VC + + dialog box program does not respond to OnChar and onkeydown event handler functions __jquery

Source: Internet
Author: User
VC + + generated dialog box by default will not respond to OnChar and onkeydown messages, will be blocked by other controls
if you do not modify the code, use will be found not to enter the two event response function, you must modify the rewrite PreTranslateMessage () Virtual functions can correctly
In response to these two message functions, the implementation is as follows:
  
   BOOL Ctestdlg::P retranslatemessage (msg* pMsg)
    {
  
   SendMessage (pmsg->message,pmsg- >wparam,pmsg->lparam);
  
   return 0;
  
   Return CDialog::P retranslatemessage (PMSG);
    }
 This allows the program to correctly invoke both the onkeydown and OnChar functions, and onkeydown () is processed before Oncchar ().

This allows you to respond to WM_CHAR, WM_KEYDOWM messages in a dialog box, and notice that when you send WM_CHAR, you actually send three messages
  
that WM_CHAR
  
   wm_keydowm
  
   wm_keyup
  
So if you have the following code:
  
void Cmy1dlg::onchar (UINT nChar, UINT nrepcnt, UINT nflags)
  {
  //todo:add your message Handl ER code here and/or call default
  if (nchar== ' a ')
   MessageBox ("a");
  Cdialog::onchar (NChar, nrepcnt, nflags);
 }
  
Two messages dialog boxes pop up, so it's best to handle the events individually in WM_KEYDOWM or wm_keyup.

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.