Solved

Bitmaps on buttons

Posted on 1998-12-29
2
196 Views
Last Modified: 2013-12-03
I've just starting learning VC++ and I ran into a problem which I cannot find the solution to - setting the bitmap of a button.  

The first thing I did was create the button and name it ID_TESTBUTT.  I also clicked the Bitmap checkbox in the Sytles tab of the properties box. Next I added the variable m_testbutt to the ID_TESTBUTT id with CButton as the type, using the class wizard.  After that I created an icon and changed its id to TESTBUTT_ICON.  Lastly, I added this code to OnInitDialog() in the dialog's .cpp file:
      
m_testbutt.SubclassDlgItem(ID_TESTBUTT, this);
m_testbutt.SetBitmap(TESTBUTT_ICON);

and tried to compile, but I got this error:

error C2664: 'SetBitmap' : cannot convert parameter 1 from 'char *' to 'struct HBITMAP__ *'

What am I doing wrong?!  I would really appreciate any feedback!  Thanks even if you read this :)

-Chris
0
Comment
Question by:core123
2 Comments
 
LVL 6

Accepted Solution

by:
stsanz earned 50 total points
ID: 1181198
Your bitmap must be loaded first from resources to create a bitmap handle needed by SetBitmap.
Use :
m_testbutt.SetBitmap(HBITMAP(LoadBitmap(TESTBUTT_ICON))) ;


0
 

Author Comment

by:core123
ID: 1181199
Although I got errors executing the exact code above, it lead me to the correct method of loading the bmp for my project:

HINSTANCE appinstance = AfxGetInstanceHandle();
m_testbutt.SetBitmap(HBITMAP(LoadBitmap(appinstance, MAKEINTRESOURCE(TESTBUTT_ICON))));

Thanks alot, I appreciate it stsanz.  (I just thought I would post this just incase anyone found these and ran into trouble).

-Chris
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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

911 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

16 Experts available now in Live!

Get 1:1 Help Now