The MFC dialog box customizes the method of message mapping

  • 2020-04-02 03:09:20
  • OfStack

This article illustrates the MFC dialog box custom message mapping method. Share with you for your reference. The specific implementation method is as follows:

1. Define the message:

#define WM_MYMSG (WM_USER+100)

2. Define the message response function:


LPESULT CSLYARDlg::OnMymsg(WPARAM wParam, LPARAM lParam)
{
// TODO
return 0;
}

3. Declare the message response function in the AFX_MSG of the window header file:


// Generated message map functions
//{{AFX_MSG(CSLYARDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg LRESULT OnMymsg(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG

4. Declare the message map in the MESSAGE_MAP of the window class implementation file, where the ON_MESSAGE macro is needed:


BEGIN_MESSAGE_MAP(CSLYARDlg, CDialog)
//{{AFX_MSG_MAP(CSLYARDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_MYMSG, OnMymsg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Hope that this article is helpful to everyone's MFC programming.


Related articles: