11.21. How do I handle my own registered messages?

[Editor Note: In this FAQ, Dean is telling a guy how to handle WM_CHKTBLTOGGLE, which is some message that dude is trying to handle. The guy was doing it a wrong way before, I've left that in for educational reasons.]

Use ON_MESSAGE:

ON_MESSAGE(WM_CHKTBLTOGGLE, OnChkTblToggle)

In your class definition:

afx_msg LRESULT OnChkTblToggle(WPARAM wParam, LPARAM lParam);

In your message map:

#define ON_WM_CHKTBLTOGGLE()
{
    WM_CHKTBLTOGGLE, 0, AfxSig_vwp, (AFX_PMSG)(AFX_PMSGW)(BOOL
    (AFX_MSG_CALL CWnd::*)(BYTE, BYTE))OnChkTblToggle
},

In your code:

LRESULT CMyView::OnChkTblToggle(WPARAM wParam, LPARAM lParam)
{
    // TODO: write your code here
}

You told MFC that your function is:

void CMYView::OnChkTblToggle(UINT, CPoint)

That's what the signature AfxSig_vwp means... and definitely not what you want.

ON_MESSAGE and ON_REGISTERED_MESSAGE are intended to allow you to extend the message handlers to your own custom message handlers. Please don't rely on specific AfxSig_* values or on the message map structure -- it may change without notice.

Dean McCrory, mfc-l, 8/19/95