Print Page | Close Window

Dll embeded FrameWnd wont load Toolbars

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=15051
Printed Date: 11 May 2024 at 12:18am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Dll embeded FrameWnd wont load Toolbars
Posted By: johnmichael
Subject: Dll embeded FrameWnd wont load Toolbars
Date Posted: 27 August 2009 at 4:38am
Hello, similar to the menus I have the problem that trying to use th CXTPCommandBars functions for loading menus and toolbars wont work:

here is the code as I think it should work with codejock CXTPCommandBars

<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);
    if ( pMenuBar == NULL )
    {
        TRACE0("Failed to create menu bar\n");
    }
    else
    {
        pMenuBar->LoadMenu(pMenu);
        pMenuBar->SetFlags(xtpFlagStretched|xtpFlagNoMovable);
        pMenuBar->EnableCustomization(FALSE);
        pMenuBar->SetShowGripper(FALSE);
    }

    CXTPToolBar *pStdToolBar = pCommandBars->Add( _T("Component ToolBar"),xtpBarTop );
    pStdToolBar->LoadToolBar(IDR_COMPONENT_TOOLBAR); //This fails to load I think because its not using the correct module to load the resource from

    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>


here is the code I had to develop to load the menu and toolbars manually. However with the toolbar there is no easy way to convert it to a CXTPToolbar from what I can tell so it is not skinned and looks like a standard windows 9x toolbar:

<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);
    if ( pMenuBar == NULL )
    {
        TRACE0("Failed to create menu bar\n");
    }
    else
    {
        pMenuBar->LoadMenu(pMenu);
        pMenuBar->SetFlags(xtpFlagStretched|xtpFlagNoMovable);
        pMenuBar->EnableCustomization(FALSE);
        pMenuBar->SetShowGripper(FALSE);
    }


    // the following code creates a toolbar adds the command ids to it and then loads its relevant bitmap
    uint m_ids[ID_COMPONENT_TOOLBAR_END-ID_COMPONENT_TOOLBAR_OPEN];

    if ( !m_toolbar.CreateEx(this) )
    {
        TRACE0("Failed to create tool bar\n");
    }
    else
    {
        for(int id = 0; id < ID_COMPONENT_TOOLBAR_END-ID_COMPONENT_TOOLBAR_OPEN; id++ )
        {
            m_ids[id] = ID_COMPONENT_TOOLBAR_OPEN+id;
        }
        if ( m_toolbar.SetButtons(m_ids,ID_COMPONENT_TOOLBAR_END-ID_COMPONENT_TOOLBAR_OPEN) )
        {
            if ( !m_toolbar.SetBitmap(LoadBitmap(GetHInstance(),MAKEINTRESOURCE(IDR_COMPONENT_TOOLBAR))) )
            {
                TRACE0("Failed to create bitmap from tool 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);
   
    return TRUE;
}
</code>

Again I think this is a bug with the CXTPCommandBars failing to load the resources from the correct Module. Because specifying the module and resource to load manually succeeds. Is there away to convert my manual loading of the resource into a CXTPToolBar so that it gets skinned correctly as with the Menubar?

regards




Replies:
Posted By: Oleg
Date Posted: 27 August 2009 at 7:20am
Hello,
 
With standard Menu and toolbar you manually pass instance to your dll - GetHInstance()   
so how CommandBars should find them ???  
Just set your dll as default resource insance - AfxSetResourceHandle(GetHInstance());


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: johnmichael
Date Posted: 27 August 2009 at 9:21am
yes this works better for menus and toolbars and does not affect the rest of the application


Posted By: fjosesen
Date Posted: 29 September 2009 at 7:11am

Hi,
    I have a similar problem. I need to load two toolbars from different dynamic loaded dlls. Both toolbars have the same id. I call to AfxSetResourceHandle before I call the  LoadLibrary for each toolbar. It seems to work but I see that both toolbars are drawn identically (with the same bitmap). How can I solve this problem?

    Thanks in advance,

FJSen



-------------
Products: Suite Pro (ActiveX) v18.0.1
          Toolkit Pro (MFC) v18.0.1
Platform: Windows 10 (64bit)
Language: VC++ 2013 (MFC)



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