Wm_notify message process instance analysis.

Source: Internet
Author: User

Take the clistctrl control as an example to analyze the wm_notify message. The clistctrl control contains the cheaderctrl header control in the report style, that is, the cheaderctrl header control is a subcontrol of the clistctrl control, so it is not difficult to understand, drag the column separation bar of the cheaderctrl header control to deliver the hdn_begintrack message (wm_notify message, and the notification code is hdn_begintrack) to the clistctrl control of its parent window.

However, we can also receive the hdn_begintrack message of the cheaderctrl header control in the dialog box. What is the explanation?

As shown in the following figure: the hdn_begintrack message is returned in the dialog box. When you start to drag the header control, a message box is displayed.

[CPP] View plaincopyprint?
  1. Begin_message_map (ctestdlgdlg, cdialog)
  2. ......
  3. On_notify (hdn_begintrack, 0, & ctestdlgdlg: onhdnbegintracklist1)
  4. ......
  5. End_message_map ()
  6. VoidCtestdlgdlg: onhdnbegintracklist1 (nmhdr * pnmhdr,Lresult* Presult)
  7. {
  8. Lpnmheader phdr =Reinterpret_cast<Lpnmheader> (pnmhdr );
  9. // Todo: add your control notification handler code here
  10. Afxmessagebox (text ("Cheaderctrl hdn_begintrack message! "));
  11. * Presult = 0;
  12. }
  13. </Lpnmheader>
 
Begin_message_map (ctestdlgdlg, cdialog )...... on_notify (hdn_begintrack, 0, & ctestdlgdlg: onhdnbegintracklist1 )...... end_message_map () void ctestdlgdlg: onhdnbegintracklist1 (nmhdr * pnmhdr, lresult * presult) {lpnmheader phdr = reinterpret_cast (pnmhdr); // todo: add your control notification handler code hereafxmessagebox (text ("cheaderctrl hdn_begintrack message! "); * Presult = 0 ;}

The effect is as follows:

InArticleThe following figure shows that the clistctrl control window callsCodeProcessing:

[CPP] View plaincopyprint?
  1. LresultCwnd: windowproc (UintMessage,WparamWparam,LparamLparam)
  2. {
  3. // Onwndmsg does most of the work, response t for defwindowproc call
  4. LresultLresult = 0;
  5. If(! Onwndmsg (message, wparam, lparam, & lresult ))
  6. Lresult = defwindowproc (message, wparam, lparam );
  7. ReturnLresult;
  8. }
 
Lresult cwnd: windowproc (uint message, wparam, lparam) {// onwndmsg does most of the work, limits t for defwindowproc call lresult = 0; If (! Onwndmsg (message, wparam, lparam, & lresult) lresult = defwindowproc (message, wparam, lparam); Return lresult ;}

Obviously, no corresponding message processing function is available for hdn_begintrack messages in the clistctrl message ing table, and no corresponding reflected message processing function is available in the cheaderctrl message ing table. Therefore, the above code onwndmsg (message, wparam, lparam, & lresult) will return false, so it will be processed by the default message processing function defwindowproc (message, wparam, lparam, this function will ship the message to the corresponding window (message. hwnd), that is, the dialog box window (of course, the corresponding message. hwnd is changed to the dialog box window), so that the dialog box window will have the opportunity to process the message and the message box will pop up.

If the hdn_begintrack message is processed in clistctrl, It is not processed in the dialog box.

Therefore, we add cmylistctrl, which inherits from clistctrl and processes the hdn_begintrack message in cmylistctrl.

[CPP] View plaincopyprint?
  1. Begin_message_map (cmylistctrl, clistctrl)
  2. On_notify (hdn_begintracka, 0, & cmylistctrl: onhdnbegintrack)
  3. On_notify (hdn_begintrackw, 0, & cmylistctrl: onhdnbegintrack)
  4. End_message_map ()
  5. VoidCmylistctrl: onhdnbegintrack (nmhdr * pnmhdr,Lresult* Presult)
  6. {
  7. Lpnmheader phdr =Reinterpret_cast<Lpnmheader> (pnmhdr );
  8. // Todo: add your control notification handler code here
  9. Afxmessagebox (text ("Cmylistctrl processes the hdn_begintrack message"));
  10. * Presult = 0;
  11. }
  12. </Lpnmheader>
 
Publish (cmylistctrl, clistctrl) on_notify (hdn_begintracka, 0, & cmylistctrl: Success) on_notify (success, 0, & cmylistctrl: onhdnbegintrack) publish () void cmylistctrl :: onhdnbegintrack (nmhdr * pnmhdr, lresult * presult) {lpnmheader phdr = reinterpret_cast (pnmhdr); // todo: add your control notification handler code hereafxmessagebox (text ("cmylistctrl processes the hdn_begintrack message"); * presult = 0 ;}

Change clistctrl m_list in the dialog box to cmylistctrl m_list. The effect is as follows:

Instance code: http://download.csdn.net/detail/wangyao1052/4633804

 

From: http://blog.csdn.net/wangyao1052/article/details/8057828

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.