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 Toolbars
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Dll embeded FrameWnd wont load Toolbars

 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 Toolbars
    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

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: 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
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: 27 August 2009 at 9:21am
yes this works better for menus and toolbars and does not affect the rest of the application
Back to Top
fjosesen View Drop Down
Groupie
Groupie
Avatar

Joined: 30 June 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote fjosesen Quote  Post ReplyReply Direct Link To This Post 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)
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.173 seconds.