Analysis and understanding message reflex mechanism

xiaoxiao2021-03-06  50

Preface:

I have written an article to analyze the notification message WM_NOTIFY. The message reflection is the method of processing the notification message in the MFC. Therefore, I wrote this article, I hope to describe the notification message. Complete impression.

Basic knowledge of message reflection

1. Message Reflection Interpretation: The parent window sends the control sub-window to its notification message, first reflect the back sub-window to process (that is, a chance to the control sub-window, let the control sub-window processes this message), so that the message will have a chance The quilt window itself can be processed.

2, the reason for introducing message reflection in the MFC: In Windows message processing, the notification message issued by the control sub-window to its parent window can only be processed by its parent window, which makes the self-energy performance of the control sub-window (you Think, it will change your own background colors, handle a self-scrolling problem to complete the parent window to complete), in order to solve this problem, introduce the concept of reflection message "Reflect Message" in the MFC, perform message reflection, can make control The sub-window can handle some messages related to itself, enhance the encapsulation, thereby increasing the reusability of the control sub-window.

Works of message reflection (regardless of OLE control)

First, the message reflection process flow diagram: 1. After the parent window receives the notification message sent by the control sub-window, call its virtual function CWnd :: OnNotify.cWnd :: Onnotify () body section: {if (Reflectlastmsg (hwndctrl, PRESULT)) // At this time, hWndCtrl, for the send window, the window handle return true; // sub-window has been processed this message AFX_NOTIFY NOTIFY; NOTIFY.PRESULT = PRESULT; Notify.PnmHDR = PNMHDR; Return ONCMDMSG NID, Makelong (ncode, wm_notify), ?ness, null;

Analysis: First, call the REFLECTLASTMSG (HCTRLCHILDWND, ...) to a sub-window a chance, reflect the message to the child window, the function returns True, indicating that the sub-window has handled this message. Conversely, the represented sub-window does not process this message. At this time, calling onCmdmsg (...) is performed by the parent window.

2, REFLECTLASTMSG: Mainly called SendChildNotifylastmsg (...) of the sending window.

3, SendChildNotifylastmsg: Call the virtual function onchildNotify function of the send window for processing. If there is no processing, call the REFLEctChildNotify (...) function for the message mapping process of the standard reflection message.

Preface:

I have written an article to analyze the notification message WM_NOTIFY. The message reflection is the method of processing the notification message in the MFC. Therefore, I wrote this article, I hope to describe the notification message. Complete impression.

Basic knowledge of message reflection

1. Message Reflection Interpretation: The parent window sends the control sub-window to its notification message, first reflect the back sub-window to process (that is, a chance to the control sub-window, let the control sub-window processes this message), so that the message will have a chance The quilt window itself can be processed.

2, the reason for introducing message reflection in the MFC: In Windows message processing, the notification message issued by the control sub-window to its parent window can only be processed by its parent window, which makes the self-energy performance of the control sub-window (you Think, it will change your own background colors, handle a self-scrolling problem to complete the parent window to complete), in order to solve this problem, introduce the concept of reflection message "Reflect Message" in the MFC, perform message reflection, can make control The sub-window can handle some messages related to itself, enhance the encapsulation, thereby increasing the reusability of the control sub-window. Works of message reflection (regardless of OLE control)

First, the message reflection process flow diagram: 1. After the parent window receives the notification message sent by the control sub-window, call its virtual function CWnd :: OnNotify.cWnd :: Onnotify () body section: {if (Reflectlastmsg (hwndctrl, PRESULT)) // At this time, hWndCtrl, for the send window, the window handle return true; // sub-window has been processed this message AFX_NOTIFY NOTIFY; NOTIFY.PRESULT = PRESULT; Notify.PnmHDR = PNMHDR; Return ONCMDMSG NID, Makelong (ncode, wm_notify), ?ness, null;

Analysis: First, call the REFLECTLASTMSG (HCTRLCHILDWND, ...) to a sub-window a chance, reflect the message to the child window, the function returns True, indicating that the sub-window has handled this message. Conversely, the represented sub-window does not process this message. At this time, calling onCmdmsg (...) is performed by the parent window.

2, REFLECTLASTMSG: Mainly called SendChildNotifylastmsg (...) of the sending window.

3, SendChildNotifylastmsg: Call the virtual function onchildNotify function of the send window for processing. If there is no processing, call the REFLEctChildNotify (...) function for the message mapping process of the standard reflection message.

转载请注明原文地址:https://www.9cbs.com/read-80155.html

New Post(0)