Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Bitmaps on buttons

Posted on 1998-12-29
2
Medium Priority
?
209 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

886 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