Solved

How to put an icon on a button

Posted on 1998-12-31
4
399 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

21 Experts available now in Live!

Get 1:1 Help Now