Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Hooked MDIChild window ---> problem

Hooked MDIChild window ---> problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionhtmlcom
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ro_land
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • R Ro_land

      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

      R Offline
      R Offline
      Roger Allen
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • R Roger Allen

        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

        R Offline
        R Offline
        Ro_land
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups