MFC message flow for controls?

In MFC, suppose I have a dialog and it has a child CListCtrl in that field, then I use my mouse to click that CListCtrl, we know that ultimately the WM_LBUTTONDOWN message is sent to CListCtrl. My question is how is this WM_LBUTTONDOWN message? Two possibilities:

  • The dialog box first receives this WM_LBUTTONDOWN message, and detects that a mouse click occurs in its child window, then it forwards this message to CListCtrl.
  • CListCtrl first receives this WM_LBUTTONDOWN message, it can process this message, and if it doesn't care, it will send this message to the parent window, i.e. the dialog box for further processing.

Which one is true?

Thank.

+3


source to share


1 answer


Input messages are never sent to the window. They are placed on the message queue associated with the window, waiting to be recovered through one of the message lookup functions ( GetMessage , PeekMessage , etc.).

Depending on whether the dialog is modal or non-modal, messages are retrieved by a nested modal loop (for modal dialogs) or an application message outline. The message is then passed to DispatchMessage to find the recipient (starting at the topmost visible window under the mouse pointer, which is neither disabled nor transparent) and call the appropriate window window procedure. The window procedure can decide whether it processes the message or not. A window procedure usually calls DefWindowProc to perform default processing if it does not process a message.



To summarize, the application message loop (or nested modular message loop) allows the message to be seen first and instructs the window manager to deliver the message to the appropriate recipient.

<h / "> A detailed description of Windows message handling can be found in About Messages and Message Queuing . Description is specific to the Windows API. Since MFC is just a wrapper around the Windows API, the content also applies to MFC, although some of the concepts are hidden in a typical application MFC.

+2


source







All Articles