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. Transparent icons on a toolbar buttons

Transparent icons on a toolbar buttons

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 5 Posters 0 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.
  • D Offline
    D Offline
    Daredevil
    wrote on last edited by
    #1

    Hello I am using 256 color icons for my toolbar, however each of the icons has a white (or light grey) background which is ugly. How is it possible to make the icons transparent on any windows theme? Thanks in advance.

    G 1 Reply Last reply
    0
    • D Daredevil

      Hello I am using 256 color icons for my toolbar, however each of the icons has a white (or light grey) background which is ugly. How is it possible to make the icons transparent on any windows theme? Thanks in advance.

      G Offline
      G Offline
      GermanGeorge
      wrote on last edited by
      #2

      i did not try this out, but I would start this way: subclass the bar overwrite the WM_CTLCOLOR of the bar and set in the method { pDC->SetBkMode( TRANSPARENT ); return m_LeerBrush; } where m_LeerBrush=GetStockObject(HOLLOW_BRUSH) Then use a transparent color for the icon hope this helps

      E 1 Reply Last reply
      0
      • G GermanGeorge

        i did not try this out, but I would start this way: subclass the bar overwrite the WM_CTLCOLOR of the bar and set in the method { pDC->SetBkMode( TRANSPARENT ); return m_LeerBrush; } where m_LeerBrush=GetStockObject(HOLLOW_BRUSH) Then use a transparent color for the icon hope this helps

        E Offline
        E Offline
        Elmue
        wrote on last edited by
        #3

        Hello This will not work. The toolbar internally works with old primitive bitmaps. (it comes from the Windows 3.1 times) SetBkMode(TRANSPARENT) is useless for painting bitmaps. It is mainly for printing text. What you have to do is assign an Imagelist to the toolbar. The imagelist can maintain a primitive transparency using a mask. With i_ImageList.SetBkColor(..) you can define with which color the "transparent" pixels are filled. With i_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1) you can load transparent icons. With i_Toolbar->GetToolBarCtrl().SetImageList(&i_ImageList) you assign the image list And as LAST you can load the toolbar tooltips and Command IDs trom the resources i_Toolbar.LoadToolBar(IDR_TOOLBAR1); The images stored in the resources will be overridden with your imagelist. Please note: This is NOT real transparency with an Alpha channel! You can NOT draw XP icons or alpha channel bitmaps with various levels of transparency! And you can NOT draw on a multicolored backgound. Elmü

        L M 2 Replies Last reply
        0
        • E Elmue

          Hello This will not work. The toolbar internally works with old primitive bitmaps. (it comes from the Windows 3.1 times) SetBkMode(TRANSPARENT) is useless for painting bitmaps. It is mainly for printing text. What you have to do is assign an Imagelist to the toolbar. The imagelist can maintain a primitive transparency using a mask. With i_ImageList.SetBkColor(..) you can define with which color the "transparent" pixels are filled. With i_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1) you can load transparent icons. With i_Toolbar->GetToolBarCtrl().SetImageList(&i_ImageList) you assign the image list And as LAST you can load the toolbar tooltips and Command IDs trom the resources i_Toolbar.LoadToolBar(IDR_TOOLBAR1); The images stored in the resources will be overridden with your imagelist. Please note: This is NOT real transparency with an Alpha channel! You can NOT draw XP icons or alpha channel bitmaps with various levels of transparency! And you can NOT draw on a multicolored backgound. Elmü

          L Offline
          L Offline
          lakshmanguru
          wrote on last edited by
          #4

          Any suggestions? Still no luck.

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

          myBar.LoadToolBar(IDR\_TOOLBAR1);
          
          list1.Create(16, 16, ILC\_COLOR32 | ILC\_MASK, 2, 2);
              list1.SetBkColor(RGB(255,0,0));
          
          list1.Add(AfxGetApp()->LoadIcon(IDI\_ICON1));
          list1.Add(AfxGetApp()->LoadIcon(IDI\_ICON2));
          
              myBar.SendMessage(TB\_SETIMAGELIST, 0 , LPARAM (list1.m\_hImageList));
          
          myBar.EnableDocking(CBRS\_ALIGN\_ANY);
          EnableDocking(CBRS\_ALIGN\_ANY);
          DockControlBar(&myBar);
          
          1 Reply Last reply
          0
          • E Elmue

            Hello This will not work. The toolbar internally works with old primitive bitmaps. (it comes from the Windows 3.1 times) SetBkMode(TRANSPARENT) is useless for painting bitmaps. It is mainly for printing text. What you have to do is assign an Imagelist to the toolbar. The imagelist can maintain a primitive transparency using a mask. With i_ImageList.SetBkColor(..) you can define with which color the "transparent" pixels are filled. With i_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1) you can load transparent icons. With i_Toolbar->GetToolBarCtrl().SetImageList(&i_ImageList) you assign the image list And as LAST you can load the toolbar tooltips and Command IDs trom the resources i_Toolbar.LoadToolBar(IDR_TOOLBAR1); The images stored in the resources will be overridden with your imagelist. Please note: This is NOT real transparency with an Alpha channel! You can NOT draw XP icons or alpha channel bitmaps with various levels of transparency! And you can NOT draw on a multicolored backgound. Elmü

            M Offline
            M Offline
            Mahadev HK
            wrote on last edited by
            #5

            Hi, Try the below code. It will work for sure.

            if (!m\_wndToolBarMaha.CreateEx(this, TBSTYLE\_FLAT, WS\_CHILD | WS\_VISIBLE | CBRS\_TOP
                | CBRS\_GRIPPER | CBRS\_TOOLTIPS | CBRS\_FLYBY | CBRS\_SIZE\_DYNAMIC ) )
            {
                TRACE0("Failed to create toolbar\\n");
                return -1;      // fail to create
            }
            
            CWinApp\* pApp= AfxGetApp();
            m\_TBarImages.Create(32, 32, ILC\_COLOR, 4, 4);
            m\_TBarImages.SetBkColor( RGB( 192, 192, 192 ) );
            m\_TBarImages.Add(pApp->LoadIcon(IDI\_ICON1));
            m\_TBarImages.Add(pApp->LoadIcon(IDI\_ICON2));
            m\_TBarImages.Add(pApp->LoadIcon(IDI\_ICON3));
            m\_wndToolBarMaha.GetToolBarCtrl().SetImageList(&m\_TBarImages);
            
            m\_wndToolBarMaha.LoadToolBar(IDR\_MAINFRAME);
            
            // TODO: Delete these three lines if you don't want the toolbar to be dockable
            m\_wndToolBarMaha.EnableDocking(CBRS\_ALIGN\_ANY);
            EnableDocking(CBRS\_ALIGN\_ANY);
            DockControlBar(&m\_wndToolBarMaha);
            

            Mahadev

            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