1. First define the message (such as DebugApp. h)
# Define WM_DEBUG WM_USER + 1
2. Add the header file in the window (for example, MainFrame. h)
Class CMainFrame: public CFrameWnd
{
// Generated message map functions
//} AFX_MSG
Afx_msg LRESULT OnDebug (WPARAM wParam, LPARAM lParam );
...
}
3. Add in the cpp file of the window (for example, MainFrame. cpp)
BEGIN_MESSAGE_MAP (CMainFrame, CFrameWnd)
...
ON_MESSAGE (WM_DEBUG, OnDebug)
END_MESSAGE_MAP ()
...
LRESULT CMainFrame
: OnDebug (WPARAM wParam, LPARAM lParam)
{
Return 0;
}
4. messages can be sent elsewhere (for example, add a message to the event with the left mouse of DebugView. cpp)
Void CDebugView: OnLButtonDown (UINT nFlags, CPoint point)
{
CFrameWnd * pFrame;
// Obtain the main window pointer
PFrame = (CFrameWnd *) AfxGetApp ()-> m_pMainWnd;
PFrame-> SendMessage (WM_DEBUG, 0, 0 );
CView: OnLButtonDown (nFlags, point );
}