none
CMFCToolbar 24x24 or 32x32 images RRS feed

  • Question

  • Hi All,

    If in the resource window for a tool bar I specify the items to be 24x24 or 32x32 in height, the image is resized correctly and the corresponding bitmap is resized also.

    However upon starting the application it *always* shows a 16x16 button (thus the top left of the image for that button).

    No matter what I do nothing seems to have an effect, I've tried playing with the following static methods:

    CMFCToolBar::SetSizes
    CMFCToolBar::SetMenuSizes

    But they have zero effect. The resource file is simply this:


    IDR_TEST_TOOLBAR         BITMAP                  "res\\toolbar1.bmp" 
     
    IDR_TEST_TOOLBAR TOOLBAR  32, 32 
    BEGIN 
        BUTTON      ID_TEST 
    END 



    And the loading code is this:

     
         
    if (!m_wndGetBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
            !m_wndGetBar.LoadToolBar(IDR_TEST_TOOLBAR)) 
        TRACE0("Failed to create toolbar\n"); 
        return -1;      // fail to create 


    Any ideas would be really welcome, since in none 2008 feature pack stuff you just change the values in the resource editor and hey-presto it works!

    Thanks
    Monday, November 3, 2008 5:34 PM

Answers

  • Hi All,

    I've managed after many hours to get this to work, I'd thought I'd share how to prevent anyone experiencing hair loss! :)

    Basically it all revolves around the LoadToolBar method.  http://msdn.microsoft.com/en-us/library/bb983090.aspx

    For the parameter "bLocked" you need to specify true... as to why I am not entirely sure as the documentation says:

    [in] bLocked

    A Boolean value that specifies whether the toolbar is locked or not. If this parameter is TRUE, the toolbar is locked. Otherwise, the toolbar is not locked.

    Which is truly enlightening! I presume if you happen to be loading some 16x16 icons somewhere else on another toolbar it is attempting to use a shared list of images which messes up the sizes (which is very poor implementation if you ask me). So maybe specifying "Locked" means the particular toolbar uses its own internal list of images and hey presto it all works!

    Side note, if you are going to specify a menu image resource, make sure you set the menu image sizes to be the same first:

    CMFCToolBar::SetMenuSizes(CSize (w+6, h+6), CSize (w, h));

    Which is odd since CMFCToolBar::SetSizes is set internally by the LoadToolBar() method, very inconsistent...

    ... Maybe its a ploy by Ms/BCGSoft to get people to buy the full GUI kit instead of the half assed (and undocumented) MFC 8 pack? :)

    Thanks.

    • Marked as answer by Mark Duffill Tuesday, November 4, 2008 9:37 AM
    • Marked as answer by Mark Duffill Tuesday, November 4, 2008 9:37 AM
    Tuesday, November 4, 2008 9:35 AM

All replies

  • Hi All,

    I've managed after many hours to get this to work, I'd thought I'd share how to prevent anyone experiencing hair loss! :)

    Basically it all revolves around the LoadToolBar method.  http://msdn.microsoft.com/en-us/library/bb983090.aspx

    For the parameter "bLocked" you need to specify true... as to why I am not entirely sure as the documentation says:

    [in] bLocked

    A Boolean value that specifies whether the toolbar is locked or not. If this parameter is TRUE, the toolbar is locked. Otherwise, the toolbar is not locked.

    Which is truly enlightening! I presume if you happen to be loading some 16x16 icons somewhere else on another toolbar it is attempting to use a shared list of images which messes up the sizes (which is very poor implementation if you ask me). So maybe specifying "Locked" means the particular toolbar uses its own internal list of images and hey presto it all works!

    Side note, if you are going to specify a menu image resource, make sure you set the menu image sizes to be the same first:

    CMFCToolBar::SetMenuSizes(CSize (w+6, h+6), CSize (w, h));

    Which is odd since CMFCToolBar::SetSizes is set internally by the LoadToolBar() method, very inconsistent...

    ... Maybe its a ploy by Ms/BCGSoft to get people to buy the full GUI kit instead of the half assed (and undocumented) MFC 8 pack? :)

    Thanks.

    • Marked as answer by Mark Duffill Tuesday, November 4, 2008 9:37 AM
    • Marked as answer by Mark Duffill Tuesday, November 4, 2008 9:37 AM
    Tuesday, November 4, 2008 9:35 AM
  • Mark:
    After 3 days of trying and almost giving up, I came across your note. This is wonderful as it saved my frustration. Just goes to show how much Microsoft are behind their documentation.
    Good work.

    By the Way, I have two tools bars, one of them actually has a Dialogbar. Due to the size of this, the standard toolbar suddenly shows up enlarged. Strangely even if I use different IDs to create the Toolbars, the last toolbar I create is the size that all toolbars will use. - Unless ofcourse lock the tool bar as expalined by you.

    Thanks.
    Thursday, December 10, 2009 6:17 AM