Print Page | Close Window

Dll embeded FrameWnd wont load menu bar

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=15040
Printed Date: 27 February 2025 at 2:40pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Dll embeded FrameWnd wont load menu bar
Posted By: johnmichael
Subject: Dll embeded FrameWnd wont load menu bar
Date 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



Replies:
Posted By: Oleg
Date 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


Posted By: johnmichael
Date 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.?


Posted By: Oleg
Date 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


Posted By: johnmichael
Date Posted: 26 August 2009 at 3:44am
//removed in favour of second post


Posted By: johnmichael
Date 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.



Posted By: johnmichael
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net