Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to setup toolbars (CMFCToolbar) for small and large icons with different DPI values ?

How to setup toolbars (CMFCToolbar) for small and large icons with different DPI values ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestionlearningworkspace
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    I can create toolbars to support small and large icons with code like this :

    {
    if (!m_StandardToolBar.CreateEx(this, TBSTYLE_FLAT, style| WS_VISIBLE , CRect(1,1 , 1, 1), ITB_STANDARD_TOOLBAR) )
    {
    TRACE0("Failed to create toolbar\n");
    return false; // fail to create
    }

    CMFCToolBarInfo info;
    
    info.m\_uiColdResID = ITB\_STANDARD\_TOOLBAR;
    info.m\_uiHotResID = ITB\_STANDARD\_TOOLBAR;
    info.m\_uiLargeColdResID = ITB\_STANDARD\_LARGE\_TOOLBAR;
    info.m\_uiLargeHotResID = ITB\_STANDARD\_LARGE\_TOOLBAR;
    
    m\_StandardToolBar.LoadToolBarEx( ITB\_STANDARD\_TOOLBAR, info , FALSE);
    m\_StandardToolBar.SetWindowText( CMbString::mbLoadString(IDS\_TOOLBAR\_STANDARD));
    

    }

    When changing the "DPI" (what was the "large font/small font) settings before) MFC (Win32) will automagically resize the toolbar bitmaps to fit the new settings. There are now 3 settings : 100% (smaller, default), 125% (medium) and 150% (Larger) If the default small toolbar button is 16x16, then the other sizes will be 20x20 and 24x24 If the default large toolbar button is 32x32, then the other sizez will be 40x40 and 48x48. Now if I have to do this "by the book" I would need to generate toolbars with buttons 16x16, 20x20, 24x24, 32x32, 40x40 and 48x48. so for each toolbar I create I will have something like : // pseudo code

    UINT smallToolbarID;
    if ( DPI == smaller )
    {
      smallToolbarID = 16x16;
      largeToolbarID = 32x32
    }
    else if ( DPI == medium )
    {
      smallToolbarID = 20x20;
      largeToolbarID = 40x40
    }
    else if ( DPI == larger)
    {
      smallToolbarID = 24x24;
      largeToolbarID = 48x48
    }
    
    if (!m\_StandardToolBar.CreateEx(this, TBSTYLE\_FLAT, style| WS\_VISIBLE , CRect(1,1 , 1, 1), ITB\_STANDARD\_TOOLBAR) )
    {
    	TRACE0("Failed to create toolbar\\n");
    	return false;      // fail to create
    }
    
    CMFCToolBarInfo info;
    
    info.m\_uiColdResID = smallToolbarID;
    info.m\_uiHotResID = smallToolbarID;
    info.m\_uiLargeColdResID = largeToolbarID;
    info.m\_uiLargeHotResID = largeToolbarID;
    
    m\_StandardToolBar.LoadToolBarEx( ITB\_STANDARD\_TOOLBAR, info , FALSE);
    m\_StandardToolBar.SetWindowText( CMbString::mbLoadString(IDS\_TOOLBAR\_STANDARD));
    

    Meaning that for each toolbar, I will have 6 different bitmaps to maintain? Am I thinking this straight or is there a catch somewhere ? Thanks. Max.

    I'd rather be phishing!

    A 1 Reply Last reply
    0
    • M Maximilien

      I can create toolbars to support small and large icons with code like this :

      {
      if (!m_StandardToolBar.CreateEx(this, TBSTYLE_FLAT, style| WS_VISIBLE , CRect(1,1 , 1, 1), ITB_STANDARD_TOOLBAR) )
      {
      TRACE0("Failed to create toolbar\n");
      return false; // fail to create
      }

      CMFCToolBarInfo info;
      
      info.m\_uiColdResID = ITB\_STANDARD\_TOOLBAR;
      info.m\_uiHotResID = ITB\_STANDARD\_TOOLBAR;
      info.m\_uiLargeColdResID = ITB\_STANDARD\_LARGE\_TOOLBAR;
      info.m\_uiLargeHotResID = ITB\_STANDARD\_LARGE\_TOOLBAR;
      
      m\_StandardToolBar.LoadToolBarEx( ITB\_STANDARD\_TOOLBAR, info , FALSE);
      m\_StandardToolBar.SetWindowText( CMbString::mbLoadString(IDS\_TOOLBAR\_STANDARD));
      

      }

      When changing the "DPI" (what was the "large font/small font) settings before) MFC (Win32) will automagically resize the toolbar bitmaps to fit the new settings. There are now 3 settings : 100% (smaller, default), 125% (medium) and 150% (Larger) If the default small toolbar button is 16x16, then the other sizes will be 20x20 and 24x24 If the default large toolbar button is 32x32, then the other sizez will be 40x40 and 48x48. Now if I have to do this "by the book" I would need to generate toolbars with buttons 16x16, 20x20, 24x24, 32x32, 40x40 and 48x48. so for each toolbar I create I will have something like : // pseudo code

      UINT smallToolbarID;
      if ( DPI == smaller )
      {
        smallToolbarID = 16x16;
        largeToolbarID = 32x32
      }
      else if ( DPI == medium )
      {
        smallToolbarID = 20x20;
        largeToolbarID = 40x40
      }
      else if ( DPI == larger)
      {
        smallToolbarID = 24x24;
        largeToolbarID = 48x48
      }
      
      if (!m\_StandardToolBar.CreateEx(this, TBSTYLE\_FLAT, style| WS\_VISIBLE , CRect(1,1 , 1, 1), ITB\_STANDARD\_TOOLBAR) )
      {
      	TRACE0("Failed to create toolbar\\n");
      	return false;      // fail to create
      }
      
      CMFCToolBarInfo info;
      
      info.m\_uiColdResID = smallToolbarID;
      info.m\_uiHotResID = smallToolbarID;
      info.m\_uiLargeColdResID = largeToolbarID;
      info.m\_uiLargeHotResID = largeToolbarID;
      
      m\_StandardToolBar.LoadToolBarEx( ITB\_STANDARD\_TOOLBAR, info , FALSE);
      m\_StandardToolBar.SetWindowText( CMbString::mbLoadString(IDS\_TOOLBAR\_STANDARD));
      

      Meaning that for each toolbar, I will have 6 different bitmaps to maintain? Am I thinking this straight or is there a catch somewhere ? Thanks. Max.

      I'd rather be phishing!

      A Offline
      A Offline
      Andrew Truckle
      wrote on last edited by
      #2

      Hi Did you go with this in the end? Andrew

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups