CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Posts
    34

    Using 256 Color Bitmaps in Toolbar

    I try to create a toolbar using 256 color bitmaps. I checked the Kevin Bentley's tip in the Controls Related Source Code Sections. I have a little bit trouble to achieve this. Two questions:
    1. In my MainFrm.cpp, I have lines reads:

    if (!m_MyToolbar.Create(this) ||
    !m_MyToolbar.LoadToolBar(IDR_MYTOOLBAR))
    {
    TRACE0("Failed to create My ToolBar\n");
    return -1; // fail to create
    }



    I don't know where to put the suggested line.

    m_wndToolBar.GetToolBarCtrl().AddBitmap(iNumButtons,IDR_MAINFRAME);



    2. How do I create 256 color the Toolbar bitmap. Say, I have IDR_MYTOOLBAR in TOOLBAR resource ( 16 color), should I create a separate 256 color bitmap and import it to the Bitmap resource? How does this work?

    Thanks for you help in advance.


  2. #2
    Join Date
    May 1999
    Posts
    40

    Re: Using 256 Color Bitmaps in Toolbar

    To create the bitmap for the toolbar you'll need to use some image editing program other than the one that comes with Developer Studio since that one doesn't support 256 colors. We use Paint Shop Pro. First create a toolbar resource in Dev Studio with the resource ID you want. Put in all the buttons and separators that you want with placeholders for the images. In the properties dialog box for the resource you can set the name of the .bmp file containing the image. Edit this file in Paint Shop Pro or whatever program you want and save it as a 256 color bitmap. Replace the placeholder images with your 256 color images. Once you have saved it as a 256 color bitmap you will no longer be able to open it in Dev Studio.

    Then in your mainframe class do the following:


    if (!m_myToolbar.Create(this) ||
    !m_myToolbar.LoadToolBar(IDR_BAR_ID))
    {
    TRACE0("Failed to create toolbar\n");
    return -1; // fail to create
    }

    // load the bitmap and convert the grays to the users color scheme
    HBITMAP hBmp= (HBITMAP)::LoadImage(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_BAR_ID),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);
    m_myToolbar.SetBitmap(hBmp);




    Using the LR_LOADMAP3DCOLORS flag in your code will correctly change the background colors of the buttons when you are using different color schemes.

    Josh


  3. #3
    Join Date
    Apr 1999
    Posts
    34

    Re: Using 256 Color Bitmaps in Toolbar

    Thanks very much. That's exactly what I want.


  4. #4
    Join Date
    Sep 1999
    Location
    Santa Clara, California
    Posts
    145

    Re: Using 256 Color Bitmaps in Toolbar

    Thanks, Josh
    Just a small note so that anyone who experiences the same problem I was having can find it in the search:
    The problem I had was, while using a 256 color .BMP created with Paint Shop Pro as the image source for a toolbar, some of the palette colors would be automatically replaced with colors generated by the MFC framework. After several attempts at manipulating the color palette under Paint Shop Pro failed to correct the problem, I turned to here to seek an answer (after finding nothing on MSDN, I might point out) (as usual). The following code (based on Josh's post) has corrected the problem:


    hBmp= (HBITMAP)::LoadImage(AfxGetResourceHandle(),MAKEINTRESOURCE(IDB_SCOLORS),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);
    if (!m_StripColors.CreateEx(this, bs_flat, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_ANY | CBRS_TOOLTIPS | CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_FLYBY) ||
    !m_StripColors.SetBitmap(hBmp) ||
    !m_StripColors.SetButtons(scolors, sizeof(scolors)/sizeof(UINT))) {
    TRACE0("Failed to create strip color bar\n");
    return -1;
    }





  5. #5
    Join Date
    Aug 2007
    Posts
    3

    Smile Re: Using 256 Color Bitmaps in Toolbar

    I also had a same problem, my toolbar was not visible after changing its color property to 8 bit. The solution had solved my problem. Thanks a lot.

  6. #6
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: Using 256 Color Bitmaps in Toolbar

    Probably a new record!

    NEARLY 13 YEARS OLD!!
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured