INFO: Use ON_MESSAGE() Macro to Map Less-Common Messages

Article translations Article translations
Article ID: 99848 - View products that this article applies to.
This article was previously published under Q99848
Expand all | Collapse all

SUMMARY

The Microsoft Foundation Class Library includes macros that an application can include in the message map of a CWnd or CWnd derived object.These macros, such as ON_WM_PAINT() and ON_WM_SIZE(), map common messages to default handler functions. The Microsoft Foundation Class Library provides macros for all standard window messages. To process user-defined message or less-common window messages (like WM_COMMNOTIFY), use the ON_MESSAGE() macro. The ON_MESSAGE macro must be used in a CWnd derived class. For example, it cannot be used in a CWinApp class or a CDocument class because neither of these classes is derived from CWnd.

MORE INFORMATION

Here's an example of how an application could use ON_MESSAGE:
  // inside the class declaration
  afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);

  ...

  #define WM_MYMESSAGE (WM_USER + 100)

  BEGIN_MESSAGE_MAP(CMyWnd, CMyParentWndClass)
     ON_MESSAGE(WM_MYMESSAGE, OnMyMessage)
  END_MESSAGE_MAP()

  LRESULT CMyWnd::OnMyMessage(WPARAM WParam, LPARAM LParam)
  {
     return (LRESULT)0;
  }
				
The function specified by the second parameter of the ON_MESSAGE macro must be a function that takes two parameters, a WPARAM and an LPARAM, and returns a LRESULT. For more information about the ON_MESSAGE() macro, see Technical Note #6 in the MFC Tech Notes Help file distributed with Microsoft Visual C++ version 1.0 and in the MFC Technical Notes included in the Visual C++ Books Online. Or search the Visual C++ Books Online on the keyword "ON_MESSAGE."

Properties

Article ID: 99848 - Last Review: November 21, 2006 - Revision: 3.1
APPLIES TO
  • Microsoft Foundation Class Library 4.2, when used with:
    • Microsoft C/C++ Professional Development System 7.0
    • Microsoft Visual C++ 1.0 Professional Edition
    • Microsoft Visual C++ 1.5 Professional Edition
    • Microsoft Visual C++ 1.51
    • Microsoft Visual C++ 1.52 Professional Edition
    • Microsoft Visual C++ 1.0 Professional Edition
    • Microsoft Visual C++ 2.0 Professional Edition
    • Microsoft Visual C++ 2.1
    • Microsoft Visual C++ 4.0 Standard Edition
    • Microsoft Visual C++ 5.0 Standard Edition
    • Microsoft Visual C++ 6.0 Service Pack 5
    • Microsoft Visual C++ .NET 2002 Standard Edition
Keywords: 
kbinfo kbarchitecture KB99848

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com