Solved

Creating bitmap for a CToolBar

Posted on 1997-05-06
3
779 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
Comment Utility
calling SetBitmap and then deleteing the bitmap you just put in seems a bit silly
0
 

Author Comment

by:shri030197
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This video discusses moving either the default database or any database to a new volume.

772 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

14 Experts available now in Live!

Get 1:1 Help Now