Where did my WM_COMMAND go?
-
Hello, In my CDialog, I use the following line to send a command to a dialog bar:
(((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_SchedDlgBar1).PostMessage(ID_TEST);
My m_SchedDlgBar1 class has the following:BEGIN_MESSAGE_MAP(CDiagGlobalSched, CDialogBar) ... ON_COMMAND(ID_TEST, RefreshSchedBar) END_MESSAGE_MAP()
I have overidden the CMainFrm class's OnCmdMsg to see if this message ever shows up:BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { TRACE1("id:%d ", nID); if (m_SchedDlgBar1.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); }
... and based on nID never being equal to ID_TEST (and my code not executing the designated function) it never shows up!? I've looked at examples and my code is exactly how they show it should be. Where did my message go? Why did it not show up? thanks! JennyP -
Hello, In my CDialog, I use the following line to send a command to a dialog bar:
(((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_SchedDlgBar1).PostMessage(ID_TEST);
My m_SchedDlgBar1 class has the following:BEGIN_MESSAGE_MAP(CDiagGlobalSched, CDialogBar) ... ON_COMMAND(ID_TEST, RefreshSchedBar) END_MESSAGE_MAP()
I have overidden the CMainFrm class's OnCmdMsg to see if this message ever shows up:BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { TRACE1("id:%d ", nID); if (m_SchedDlgBar1.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); }
... and based on nID never being equal to ID_TEST (and my code not executing the designated function) it never shows up!? I've looked at examples and my code is exactly how they show it should be. Where did my message go? Why did it not show up? thanks! JennyPUse 'PostMessage(WM_COMMAND, ID_TEST)'. Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
-
Use 'PostMessage(WM_COMMAND, ID_TEST)'. Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
-
Perfect! Thanks Tomasz! So MSDN says: BOOL PostMessage( UINT message, WPARAM wParam = 0, LPARAM lParam = 0 ); ...and my custom message ID was supposed to be a WPARAM, not a UINT (message)? I'm confused.... but I'll just have to get over it. :) JennyP
WM_COMMAND is message id. WM_COMMAND is sent in response to menu selections, accelerator keys being pressed and some events in controls like edit boxes. wParam contains the command id/control id. message id != command id. Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
-
WM_COMMAND is message id. WM_COMMAND is sent in response to menu selections, accelerator keys being pressed and some events in controls like edit boxes. wParam contains the command id/control id. message id != command id. Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
Thanks Tomasz, I feel bemused by the fact that I couldn't find such a seemingly basic concept in the MSDN... do you know where such a thing would be documented? The MSDN page on CWnd.SendMessage() just says that wParam depends on the command being sent--nothing more. I would be interested to understand the messaging better. Thanks! JennyP
-
Thanks Tomasz, I feel bemused by the fact that I couldn't find such a seemingly basic concept in the MSDN... do you know where such a thing would be documented? The MSDN page on CWnd.SendMessage() just says that wParam depends on the command being sent--nothing more. I would be interested to understand the messaging better. Thanks! JennyP
JennyP wrote: The MSDN page on CWnd.SendMessage() just says that wParam depends on the command being sent--nothing more. Sorry, it says that wParam depends on MESSAGE being sent, not command. You should understand the difference if you want to succeed in developing software for Windows. Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.