?
Solved

Creating bitmap for a CToolBar

Posted on 1997-05-06
3
Medium Priority
?
808 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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

743 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