9.2. Message Handling
9.2.1. How do I intercept WM_SETTEXT messages?
Because MFC didn't provide generic support for overriding WM_SETTEXT, you can use OnMessage(WM_SETTEXT, OnSetText) in the message map and then define your own method:
LRESULT CMyClass::OnSetText(wParam, lParam); //
[email protected], programmer.tools, 8/17/95
9.2.2. 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
NEW!! 9.2.3. Is it possible to process a range of messages without creating a message-map entry for each message in the range?
NEW!! 9.2.4. Is it possible to enable/disable a range of menu items without creating a message-map entry for each message in the range?
Yes and yes, respectively. See the article "Message Map: Ranges of Messages" in the VC++ on-line help. This article explains how to use the following message-map macros:
- ON_COMMAND_RANGE
- ON_UPDATE_COMMAND_RANGE
- ON_CONTROL_RANGE
Eric Bergman-Terrell, [email protected], 5/16/97
NEW!! 9.2.5. How do I capture a windows message from any window fired?
For windows belonging to the calling thread, useGetMessage().
For windows outside the calling thread, SetWindowsHookEx().
Darren Ford [[email protected]], VCPP mailing list, 6/17/98