Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to put an icon on a button

Posted on 1998-12-31
4
Medium Priority
?
412 Views
Last Modified: 2013-11-20
I want to put an icon on a button. the button was created using visual C++ and was done visually(i didn't right the code to create it i just dragged and dropped it). I used classwizard to attach a variable named m_button_close to it of type CButton. then i went in and manually wrote the following code:

      m_button_close.SetIcon(IDI_DIALOGBAR);

IDI_DIALOGBAR is an icon i added to the project. when i try to compile this progie it gives the following error:

error C2664: 'SetIcon' : cannot convert parameter 1 from 'const int' to 'struct HICON__ *'

whats up with that? what am i doing wrong?
0
Comment
Question by:backdraf
  • 2
4 Comments
 

Expert Comment

by:nari
ID: 1327083
Use LoadIcon funtion to convert const int to struct HICON_ then it works.
0
 

Author Comment

by:backdraf
ID: 1327084
Could you show me an example of this?
0
 

Author Comment

by:backdraf
ID: 1327085
Could you show me an example of this?
0
 
LVL 6

Accepted Solution

by:
thresher_shark earned 200 total points
ID: 1327086
This is what you want to do:

m_button_close.SetIcon (AfxGetApp ()->LoadIcon (IDI_DIALOGBAR);

Simply copy that code at the point you want the icon to load, and you are all set.  If you have further questions, please feel free to ask.  Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

810 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