Solved

How to put an icon on a button

Posted on 1998-12-31
4
397 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
Comment Utility
Use LoadIcon funtion to convert const int to struct HICON_ then it works.
0
 

Author Comment

by:backdraf
Comment Utility
Could you show me an example of this?
0
 

Author Comment

by:backdraf
Comment Utility
Could you show me an example of this?
0
 
LVL 6

Accepted Solution

by:
thresher_shark earned 50 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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