Solved

Bitmaps on buttons

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Writing a parser for java language 4 91
C++ Language error 28 276
SNMP error No Such Object available on this agent at this OID 3 366
How do i run a c++ file? 15 51
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

685 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