. Home Feedback Contents Search

Message 

Back Up Next

User Defined Messages

There are times when the existing standard messages are not enough. Although it is common practice to define a user message at WM_USER plus some constant value, this can have rare problems with MFC. There are some controls that use messages that start with WM_USER and go up from there. The safest way to use user defined messages is to let Windows generate a guaranteed unique system message.

UINT g_uiMsg = RegisterWindowMessage ( _T(“User Message”) );

Of course, defining a message is just part of the battle. Now you have to actually USE it.

BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
    //{{AFX_MSG_MAP(CChildFrame)
    //}}AFX_MSG_MAP
    ON_REGISTERED_MESSAGE( g_uiMsg, OnMsg )
END_MESSAGE_MAP()

And, of course, we have to declare the method to be used.

In the class header:

    //{{AFX_MSG(CChildFrame)
    afx_msg void OnSettingsSs();
    //}}AFX_MSG
    afx_msg LRESULT OnMsg ();
    DECLARE_MESSAGE_MAP()

And the implementation:

LRESULT CChildFrame::OnMsg ()
    {
    return 0;
    }

Back Up Next