Put a bitmap in a toolbars background

This is a discussion on Put a bitmap in a toolbars background within the Windows Programming forums, part of the Platform Specific Boards category; Does anyone know how to put a bitmap in a toolbar's background? Thanks...

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    307

    Put a bitmap in a toolbars background

    Does anyone know how to put a bitmap in a toolbar's background?
    Thanks
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  2. #2
    Registered User blueterry's Avatar
    Join Date
    Jun 2007
    Posts
    3

    here this should help

    Introduction
    The proposed class is based on Daniel Godson's: Generating inactive/disabled images for toolbar. I have fixed some errors in the original code. But there are still some shortcomings left:

    the function to load bitmap from the file and display it is not implemented
    the size of buttons on the toolbar is 24×24, I haven't give an interface to change it.
    Using the code
    Just 2 places you need to edit for your own use.

    First is,


    Code:
    <PRE id=pre0 style="MARGIN-TOP: 0px">int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
      if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
     
      if (!m_wndToolBar.CreateEx(this, 
        TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
        | CBRS_GRIPPER | CBRS_TOOLTIPS | 
        CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
        !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
      {
        TRACE0("Failed to create toolbar\n");
        return -1;      // fail to create
      }
     
      int *num,i,j=m_wndToolBar.GetToolBarCtrl().GetButtonCount();
      num=new int[j+1];
      memset(num,0,(j+1)*sizeof(int));
      num[0]=j;//button numbers,include the separators.
      for(i=0;i<j;i++)
      {
         if(ID_SEPARATOR == m_wndToolBar.GetItemID( i ))
            num[i+1]=1;
      }//get the button info.zero represent the 
      //separators.the info is used to calc 
      //the position of the buttons.
    
      m_wndToolBar.SetFullColorImage(IDR_MAINFRAME_24, 
        RGB(255, 0, 255),num); //the first Parameter 
        //specify the resource id of button bitmap , 
        //second is the backgroud color of  the toolbar.
        
      if (!m_wndStatusBar.Create(this) ||
        !m_wndStatusBar.SetIndicators(indicators,
        sizeof(indicators)/sizeof(UINT)))
      {
        TRACE0("Failed to create status bar\n");
        return -1;      // fail to create
      }
      
      // TODO: Delete these three lines if
      // you don't want the toolbar to
      //  be dockable
      m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
      EnableDocking(CBRS_ALIGN_ANY);
      DockControlBar(&m_wndToolBar);
      delete []num;
      return 0;
    }</PRE>
    Second is, change the background bitmap here, by resource ID. So you must add the bitmap to your workplace first.

    Code:
    void CMainFrame::OnChangebk() 
    {
      // TODO: Add your command handler code here
      if(whichbk)
        m_wndToolBar.UpdateBk(IDR_MAINFRAME_24, 
               RGB(255, 0, 255) , IDB_BITMAP1);
      else
        m_wndToolBar.UpdateBk(IDR_MAINFRAME_24 ,
           RGB(255, 0, 255) , IDB_BITMAP2);
      whichbk=!whichbk;
    }

    THAT SHOULD HELP OUT

  3. #3
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    307
    oh..thanks but..I hate MFC....
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitmap scroll issues
    By Gerread in forum Windows Programming
    Replies: 4
    Last Post: 05-14-2007, 05:18 AM
  2. Loading a bitmap (Without using glaux)
    By Shamino in forum Game Programming
    Replies: 7
    Last Post: 03-16-2006, 08:43 AM
  3. Bitmap as background
    By Arkanos in forum Windows Programming
    Replies: 3
    Last Post: 12-02-2005, 01:51 PM
  4. Bitmap extractor
    By Punnie in forum C++ Programming
    Replies: 2
    Last Post: 10-22-2005, 01:15 PM
  5. difficult bitmap question
    By Mecnels in forum Windows Programming
    Replies: 1
    Last Post: 03-13-2003, 06:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21