Windows Messages
-
Hmm.. As usual something that has first appeared obvious to me.. isn't. I am using a class that sends the view a User Defined Message to notify it of some events that are taking place. However after setting up the command handlers for the view I realized that the view was not recieving or processing the message.. so I decided to setup a test message.. and it is not working either.. so I must be doing something wrong.. and I just can't figure it out. I setup the test message handler as such. afx_msg void OnTestMsg(WPARAM wParam, LPARAM lParam); ON_COMMAND(WM_TESTMSG, OnTestMsg) void CMyView::OnTestMsg(WPARAM wParam, LPARAM lParam) { TRACE("Test Message"); } defined message in view header as such #define WM_TESTMSG WM_USER + 5 Created a command ID with the following SendMessage(WM_TESTMSG); SendMessage(WM_TESTMSG,0,0); ::SendMessage(GetSafeHwnd(), WM_TESTMSG); ::SendMessage(GetSafeHwnd(), WM_TESTMSG,0,0); but the message function is never fired.. Anybody see anything obvious that I am doing wrong. Thank you.
-
Hmm.. As usual something that has first appeared obvious to me.. isn't. I am using a class that sends the view a User Defined Message to notify it of some events that are taking place. However after setting up the command handlers for the view I realized that the view was not recieving or processing the message.. so I decided to setup a test message.. and it is not working either.. so I must be doing something wrong.. and I just can't figure it out. I setup the test message handler as such. afx_msg void OnTestMsg(WPARAM wParam, LPARAM lParam); ON_COMMAND(WM_TESTMSG, OnTestMsg) void CMyView::OnTestMsg(WPARAM wParam, LPARAM lParam) { TRACE("Test Message"); } defined message in view header as such #define WM_TESTMSG WM_USER + 5 Created a command ID with the following SendMessage(WM_TESTMSG); SendMessage(WM_TESTMSG,0,0); ::SendMessage(GetSafeHwnd(), WM_TESTMSG); ::SendMessage(GetSafeHwnd(), WM_TESTMSG,0,0); but the message function is never fired.. Anybody see anything obvious that I am doing wrong. Thank you.
ON_COMMAND
is not used for handling user defined messages. For user define messages you should rather use the macroON_MESSAGE
. In addition, the handler function for user defined messages, or that should be passed forON_MESSAGE
macro takes the follwing form:LRESULT OnTestMsg(WPARAM wParam, LPARAM lParam);
Therefore, your code should be like this#define WM_TESTMSG WM_USER + 5 . afx_msg LRESULT OnTestMsg(WPARAM wParam, LPARAM lParam); ON_MESSAGE(WM_TESTMSG, OnTestMsg) . . . LRESULT CMyView::OnTestMsg(WPARAM wParam, LPARAM lParam) { TRACE("Test Message"); } . . . SendMessage(WM_TESTMSG);
-
ON_COMMAND
is not used for handling user defined messages. For user define messages you should rather use the macroON_MESSAGE
. In addition, the handler function for user defined messages, or that should be passed forON_MESSAGE
macro takes the follwing form:LRESULT OnTestMsg(WPARAM wParam, LPARAM lParam);
Therefore, your code should be like this#define WM_TESTMSG WM_USER + 5 . afx_msg LRESULT OnTestMsg(WPARAM wParam, LPARAM lParam); ON_MESSAGE(WM_TESTMSG, OnTestMsg) . . . LRESULT CMyView::OnTestMsg(WPARAM wParam, LPARAM lParam) { TRACE("Test Message"); } . . . SendMessage(WM_TESTMSG);
LOL... Thank you.. first simple solution I have ran across. Thank you very much for your help