Solved

Creating bitmap for a CToolBar

Posted on 1997-05-06
3
788 Views
Last Modified: 2013-11-20
I need to dynamically change the buttons of a CToolBar. The way to do it is to use the CToolBar::SetBitmap(HBITMAP) function to set the bitmap and then use CToolBar::SetButtonInfo().

However i need to create the bitmap at runtime and i do this using the CBitmap class.

      CClientDC dc(this);
      CDC mdc;
      mdc.CreateCompatibleDC(&dc);
      CBitmap bmp;
      bmp.CreateCompatibleBitmap(&dc,200,15);
      CPen penStroke;
        if( !penStroke.CreatePen(PS_SOLID, 3, RGB(0,0xff,0)) )
                  return FALSE;
      CPen * oldPen = mdc.SelectObject( &penStroke );
      CBitmap * oldbmp = mdc.SelectObject(&bmp);
      mdc.MoveTo(000,0); mdc.LineTo(5000,10);
      mdc.SelectObject(oldPen);
      mdc.SelectObject(oldbmp);
      mdc.DeleteDC();

        m_toolBar.SetBitmap((HBITMAP)bmp);
        bmp.DeleteObject();


However this does not seem to work. Any answers?
0
Comment
Question by:shri030197
3 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1301372
calling SetBitmap and then deleteing the bitmap you just put in seems a bit silly
0
 

Author Comment

by:shri030197
ID: 1301373
Point taken. So i tried it after removing the bmp.DeleteObject() but that didnt work either
0
 
LVL 3

Accepted Solution

by:
Melange earned 100 total points
ID: 1301374
Make sure you call bmp.Detach() so that MFC doesn't delete the bitmap in the destructor.

m_toolBar.SetBitmap( bmp );
bmp.Detach();

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question