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?
Re: Sending CMFCToolBar messages to another process
Quote:
Originally Posted by
bimble
... 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?
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!