CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    3

    Sending CMFCToolBar messages to another process

    I have an application which creates a CMFCToolBar from a toolbar resource in another application and docks it to its own window, thus:

    // load the module containing the resource
    HINSTANCE hInstance = LoadLibrary(OLE2T(bstrModule));

    if(hInstance)
    {
    // Set owner to this window, so messages are delivered to correct app
    if(IsWindow(hOwnerWnd))
    {
    m_wndToolBar.SetOwner(hOwnerWnd);
    }
    else
    {
    OutputDebugString(_T("Owner invalid"));
    }

    // make sure we load the bitmap image from the correct module
    HINSTANCE old = AfxGetResourceHandle();
    AfxSetResourceHandle(hInstance);

    // get the main frame window that we want to add the toolbar to
    CMDIFrameWndEx* pMainFrame = dynamic_cast<CMDIFrameWndEx*>(CMainFrame::GetFrame());

    // Create toolbar on client's frame window
    if (!m_wndToolBar.Create(pMainFrame) ||
    !m_wndToolBar.LoadToolBar(lResourceId))
    {
    OutputDebugString(_T("Failed to create toolbar" ));
    return FALSE;
    }
    AfxSetResourceHandle(old);

    m_wndToolBar.SetWindowText(_T("MyToolbar"));
    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);

    pMainFrame->DockPane((CPane*)&m_wndToolBar);
    m_wndToolBar.ShowPane(TRUE, FALSE, TRUE);
    }

    SetOwner is then called on the toolbar, passing in the window of the other application (the one containing the resource) so that it can receive the messages generated by the toolbar.

    The toolbar is created and displayed as expected, however the messages (ON_COMMAND and ON_UPDATE_COMMAND_UI) do not reach the owner..

    Am I missing something? Presumably this is possible across processes?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Sending CMFCToolBar messages to another process

    Quote Originally Posted by bimble View Post
    ... the messages (ON_COMMAND and ON_UPDATE_COMMAND_UI) do not reach the owner..
    They are NOT "the messages", they are macros thar are usually inserted in a message map by ClassWizard or manually...
    Have you (or has ClassWizard) inserted these macros in a message map?
    Have you (or has ClassWizard) implemented message handlers for them?
    Victor Nijegorodov

  3. #3
    Join Date
    Sep 2009
    Posts
    3

    Re: Sending CMFCToolBar messages to another process

    Thanks for your response.. I do realise that they are the message map macros - that was badly worded.

    I have now resolved the issue though - you need to call SetOwner after calling Create, unlike many of the examples I have seen!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured