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?
- Begin_message_map (ctestdlgdlg, cdialog)
- ......
- On_notify (hdn_begintrack, 0, & ctestdlgdlg: onhdnbegintracklist1)
- ......
- End_message_map ()
- VoidCtestdlgdlg: onhdnbegintracklist1 (nmhdr * pnmhdr,Lresult* Presult)
- {
- Lpnmheader phdr =Reinterpret_cast<Lpnmheader> (pnmhdr );
- // Todo: add your control notification handler code here
- Afxmessagebox (text ("Cheaderctrl hdn_begintrack message! "));
- * Presult = 0;
- }
- </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?
- LresultCwnd: windowproc (UintMessage,WparamWparam,LparamLparam)
- {
- // Onwndmsg does most of the work, response t for defwindowproc call
- LresultLresult = 0;
- If(! Onwndmsg (message, wparam, lparam, & lresult ))
- Lresult = defwindowproc (message, wparam, lparam );
- ReturnLresult;
- }
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?
- Begin_message_map (cmylistctrl, clistctrl)
- On_notify (hdn_begintracka, 0, & cmylistctrl: onhdnbegintrack)
- On_notify (hdn_begintrackw, 0, & cmylistctrl: onhdnbegintrack)
- End_message_map ()
- VoidCmylistctrl: onhdnbegintrack (nmhdr * pnmhdr,Lresult* Presult)
- {
- Lpnmheader phdr =Reinterpret_cast<Lpnmheader> (pnmhdr );
- // Todo: add your control notification handler code here
- Afxmessagebox (text ("Cmylistctrl processes the hdn_begintrack message"));
- * Presult = 0;
- }
- </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