Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Dll embeded FrameWnd wont load menu bar
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Dll embeded FrameWnd wont load menu bar

 Post Reply Post Reply
Author
Message
johnmichael View Drop Down
Groupie
Groupie


Joined: 30 June 2009
Location: United Kingdom
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnmichael Quote  Post ReplyReply Direct Link To This Post Topic: Dll embeded FrameWnd wont load menu bar
    Posted: 25 August 2009 at 3:41am
Hey,

I'm developing a view pane that can be docked to the main window of the application. The view pane has a commandbar. I got this all working fine but then I had need to seperate the entire viewpane and its children out into a seperate dll and now the menu bar fails to load. I'll give you the following snippet from the dll.

<code>
BOOL CComponentEditorDialog::OnInitDialog()
{
    LoadAccelTable( MAKEINTRESOURCE(IDR_COMPONENT_EDITOR_MENU) ); //this is the menu I wish to load and show on the toolbars

    CRect rc;
    GetClientRect( &rc );


    try
    {
        if (!InitCommandBars()) //this succeeds
        {
            return -1;
        }
    }   
    catch (CResourceException *e)
    {
        e->Delete();
        return -1;
    }

    // Get a pointer to the command bars object.
    CXTPCommandBars* pCommandBars = GetCommandBars(); //this returns a valid pointer
    if(pCommandBars == NULL)
    {
        TRACE0("Failed to create command bars object.\n");
        return -1;
    }

    // Add the menu bar
    CXTPCommandBar* pMenuBar = pCommandBars->SetMenu( _T("Menu Bar"), IDR_COMPONENT_EDITOR_MENU); //this fails

    if ( pMenuBar == NULL )
    {
        TRACE0("Failed to create menu bar\n");
    }
    else
    {
        pMenuBar->SetFlags(xtpFlagStretched);
        pMenuBar->EnableCustomization(FALSE);
    }


    GetDockingPaneManager()->InstallDockingPanes(this);
    GetDockingPaneManager()->SetTheme(xtpPaneThemeOffice2003);
    GetDockingPaneManager()->SetThemedFloatingFrames(TRUE);
    GetDockingPaneManager()->SetAlphaDockingContext(TRUE);
    GetDockingPaneManager()->SetShowDockingContextStickers(TRUE);

    m_componentGraph.Create(WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,rc,this,AFX_IDW_PANE_FIRST);
   
    return TRUE;
}
</code>

Its almost like the codejock function is not looking at the correct module instance to extract the resources from. I've also tried to load the menu my self which seems to work but it still fails to attach to the commandbar. Any help would be appreciated. CComponentEditorDialog is a CXTPFrameWnd.

regards
Jm
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 25 August 2009 at 5:42am
Hi,
 
You can load it manually and set wthi pMenuBar->LoadMenu() method.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
johnmichael View Drop Down
Groupie
Groupie


Joined: 30 June 2009
Location: United Kingdom
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnmichael Quote  Post ReplyReply Direct Link To This Post Posted: 25 August 2009 at 6:07am
Can you give a little more code:

here is my manual attemp at loading it:

<code>
BOOL CComponentEditorDialog::OnInitDialog()
{
    LoadAccelTable( MAKEINTRESOURCE(IDR_COMPONENT_EDITOR_MENU) );

    CRect rc;
    GetClientRect( &rc );

    CMenu * pMenu = new CMenu();
    if ( pMenu )
    {
        if ( pMenu->LoadMenu(IDR_COMPONENT_EDITOR_MENU) ) //this command fails
        {
            TRACE0("success created menu bar\n");
        }
        else
        {
            TRACE0("Failed to create menu bar\n");
        }
    }

    GetDockingPaneManager()->InstallDockingPanes(this);
    GetDockingPaneManager()->SetTheme(xtpPaneThemeOffice2003);
    GetDockingPaneManager()->SetThemedFloatingFrames(TRUE);
    GetDockingPaneManager()->SetAlphaDockingContext(TRUE);
    GetDockingPaneManager()->SetShowDockingContextStickers(TRUE);

    m_componentGraph.Create(WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,rc,this,AFX_IDW_PANE_FIRST);
   
    OnFileOpen();
   
    return TRUE;
}
</code>

I've also tried this:

<code>
BOOL CComponentEditorDialog::OnInitDialog()
{
    LoadAccelTable( MAKEINTRESOURCE(IDR_COMPONENT_EDITOR_MENU) );

    CRect rc;
    GetClientRect( &rc );

    HMENU menu = LoadMenu(GetHInstance(),MAKEINTRESOURCE(IDR_COMPONENT_EDITOR_MENU));
    CMenu * pMenu = new CMenu();
    if ( pMenu )
    {
        if ( pMenu->Attach(menu) )
        {
            TRACE0("success created menu bar\n");
        }
        else
        {
            TRACE0("Failed to create menu bar\n");
        }
    }

    GetDockingPaneManager()->InstallDockingPanes(this);
    GetDockingPaneManager()->SetTheme(xtpPaneThemeOffice2003);
    GetDockingPaneManager()->SetThemedFloatingFrames(TRUE);
    GetDockingPaneManager()->SetAlphaDockingContext(TRUE);
    GetDockingPaneManager()->SetShowDockingContextStickers(TRUE);

    m_componentGraph.Create(WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,rc,this,AFX_IDW_PANE_FIRST);
   
    OnFileOpen();
   
    return TRUE;
}
</code>

This last method seems to work but the menu bar does not appear on the the screen.?
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 26 August 2009 at 3:32am
Yes, you need second method but after you load menu, convert this pMenu to pMenuBar:
 
pMenuBar->LoadMenu(pMenu) ;
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
johnmichael View Drop Down
Groupie
Groupie


Joined: 30 June 2009
Location: United Kingdom
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnmichael Quote  Post ReplyReply Direct Link To This Post Posted: 26 August 2009 at 3:44am
//removed in favour of second post
Back to Top
johnmichael View Drop Down
Groupie
Groupie


Joined: 30 June 2009
Location: United Kingdom
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnmichael Quote  Post ReplyReply Direct Link To This Post Posted: 26 August 2009 at 3:57am
Okay here is the full solution:

<code>
BOOL CComponentEditorDialog::OnInitDialog()
{
    LoadAccelTable( MAKEINTRESOURCE(IDR_COMPONENT_EDITOR_MENU) );

    CRect rc;
    GetClientRect( &rc );

    HMENU menu = LoadMenu(GetHInstance(),MAKEINTRESOURCE(IDR_COMPONENT_EDITOR_MENU));
    CMenu * pMenu = new CMenu();
    if ( pMenu )
    {
        if ( pMenu->Attach(menu) )
        {
            TRACE0("success created menu bar\n");
        }
        else
        {
            TRACE0("Failed to create menu bar\n");
        }
    }

    try
    {
        if (!InitCommandBars())
        {
            return -1;
        }
    }   
    catch (CResourceException *e)
    {
        e->Delete();
        return -1;
    }

    // Get a pointer to the command bars object.
    CXTPCommandBars* pCommandBars = GetCommandBars();
    if(pCommandBars == NULL)
    {
        TRACE0("Failed to create command bars object.\n");
        return -1;
    }

    CXTPCommandBar * pMenuBar = pCommandBars->Add(_T("Menu Bar"),xtpBarTop); //creates a generic toolbar
    if ( pMenuBar == NULL )
    {
        TRACE0("Failed to create menu bar\n");
    }
    else
    {
        pMenuBar->LoadMenu(pMenu); //then load the menu into it
        pMenuBar->SetFlags(xtpFlagStretched);
        pMenuBar->EnableCustomization(FALSE);
    }

    GetDockingPaneManager()->InstallDockingPanes(this);
    GetDockingPaneManager()->SetTheme(xtpPaneThemeOffice2003);
    GetDockingPaneManager()->SetThemedFloatingFrames(TRUE);
    GetDockingPaneManager()->SetAlphaDockingContext(TRUE);
    GetDockingPaneManager()->SetShowDockingContextStickers(TRUE);

    m_componentGraph.Create(WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,rc,this,AFX_IDW_PANE_FIRST);
   
    return TRUE;
}
</code>


So if this is possible through manual loading of the menu and setting, there is a bug in the CXTPCommandBars::SetMenu function which does not look to load the resource from the correct module instance?

below is the GetHInstance function which return the module instance handle for the current module:

<code>
//////////////////////////////////////////////////////////////////////////
HINSTANCE GetHInstance()
{   
    MEMORY_BASIC_INFORMATION mbi;
    CHAR szModule[MAX_PATH];

    SetLastError(ERROR_SUCCESS);
    if (VirtualQuery(GetHInstance,&mbi,sizeof(mbi)))
    {
        if (GetModuleFileName((HINSTANCE)mbi.AllocationBase,szModule,sizeof(szModule)))
        {
            return (HINSTANCE)mbi.AllocationBase;
        }       
    }
    return NULL;
}
</code>

This can then be used to load the resource from, I propose that the CXTPCommandBars::SetMenu function needs to handle the case of loading menu resources from the current module.

Back to Top
johnmichael View Drop Down
Groupie
Groupie


Joined: 30 June 2009
Location: United Kingdom
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnmichael Quote  Post ReplyReply Direct Link To This Post Posted: 28 August 2009 at 4:11am
please follow the final solution in the following post for a better solution:

http://forum.codejock.com/forum_posts.asp?TID=15051
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.047 seconds.