Solved

Bitmaps on buttons

Posted on 1998-12-29
2
195 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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 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

10 Experts available now in Live!

Get 1:1 Help Now