Solved

Bitmaps on buttons

Posted on 1998-12-29
2
206 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
[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
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

626 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