Solved

Creating bitmap for a CToolBar

Posted on 1997-05-06
3
796 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

707 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