Solved

Creating bitmap for a CToolBar

Posted on 1997-05-06
3
782 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 65
conditional code and condition difference 9 75
countEvens challenge 2 73
wordmultiple challenge 12 116
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

947 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now