Hooked MDIChild window ---> problem
-
Hi ! I managed to hook a MDIChild window to a class of mine, which is derived from the class CHookWnd , supplied by J.P.Naughter (see article http://www.naughter.com/hookwnd.html) I additionally do attach a Toolbar programmatically to the hooked MDIChild window, all works fine, meaning that 1)the toolbar is created and attached, 2) the messages are rerouted to my WindowProc. There is one problem , though: I am not able to intercept the WM_COMMAND message sent, whenever I click on one of the toolbar buttons, this message is sent directly to the child and not rerouted. I also DO NOT want to induce a redirection of the message from within the MDI child window, that would be pointless in my case. QUESTION : How can I intercept the WM_COMMAND messages issued upon clicking the toolbar buttons such, that they will be redirected automatically to my WindowProc procedure. The whole project is available upon request, thanks to anyone trying to help, Rubi
-
Hi ! I managed to hook a MDIChild window to a class of mine, which is derived from the class CHookWnd , supplied by J.P.Naughter (see article http://www.naughter.com/hookwnd.html) I additionally do attach a Toolbar programmatically to the hooked MDIChild window, all works fine, meaning that 1)the toolbar is created and attached, 2) the messages are rerouted to my WindowProc. There is one problem , though: I am not able to intercept the WM_COMMAND message sent, whenever I click on one of the toolbar buttons, this message is sent directly to the child and not rerouted. I also DO NOT want to induce a redirection of the message from within the MDI child window, that would be pointless in my case. QUESTION : How can I intercept the WM_COMMAND messages issued upon clicking the toolbar buttons such, that they will be redirected automatically to my WindowProc procedure. The whole project is available upon request, thanks to anyone trying to help, Rubi
The problem is due to the way MFC routes the messages in the OnCmdMsg() function.
BOOL CFrameWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo)
{
CPushRoutingFrame push(this);// pump through current view FIRST CView\* pView = GetActiveView(); if (pView != NULL && pView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // then pump through frame if (CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // last but not least, pump through app CWinApp\* pApp = AfxGetApp(); if (pApp != NULL && pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; return FALSE;
}
If you override this function in your mainframe you can add an extra stage to query the CMdiChild window. e.g.
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo)
{
CPushRoutingFrame push(this);// pump through current view FIRST CView\* pView = GetActiveView(); if (pView != NULL) { CWnd \*pParent = pView->GetParent(); if (pParent != NULL && pParent->OnCmdMdg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; } if (pView != NULL && pView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // then pump through frame if (CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // last but not least, pump through app CWinApp\* pApp = AfxGetApp(); if (pApp != NULL && pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; return FALSE;
}
If you vote me down, my score will only get lower
-
The problem is due to the way MFC routes the messages in the OnCmdMsg() function.
BOOL CFrameWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo)
{
CPushRoutingFrame push(this);// pump through current view FIRST CView\* pView = GetActiveView(); if (pView != NULL && pView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // then pump through frame if (CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // last but not least, pump through app CWinApp\* pApp = AfxGetApp(); if (pApp != NULL && pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; return FALSE;
}
If you override this function in your mainframe you can add an extra stage to query the CMdiChild window. e.g.
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo)
{
CPushRoutingFrame push(this);// pump through current view FIRST CView\* pView = GetActiveView(); if (pView != NULL) { CWnd \*pParent = pView->GetParent(); if (pParent != NULL && pParent->OnCmdMdg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; } if (pView != NULL && pView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // then pump through frame if (CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // last but not least, pump through app CWinApp\* pApp = AfxGetApp(); if (pApp != NULL && pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; return FALSE;
}
If you vote me down, my score will only get lower
Thanks , but I should have explained better. What I needed to achieve was a way to cause my DLL to plug into an existing application by some other programmer, without having to involve the the other programmer .This way , he wouldn't have to change a bit. There would be only his application with a few MDI child windows created by him, while I hook up to those MDI child windows, I induce the creation of different toolbars for the respective MDI child and intercept all the messages to those windows, thus taking over the MDI children. I achieved it, everything works fine now. As I explained in the former posting, I do receive the rerouted messages. The WM_COMMAND message cannot be intercepted by me, it is intercepted in the MDI child, but I found a way around it. Whenever I create the toolbar, I keep record of the amount of buttons and record the rectangles within the toolbar, where they are located. Now, I need just to catch the WM_LBUTTONDOWN and ..BUTTONUP messages, thus enabling me to detect which button was pressed and take action... Works great ! Thank you for your interest ! Rubi