Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Add an Icon to a CButton

Status
Not open for further replies.

sparafucile17

Programmer
Apr 5, 2002
40
US
Hello all,

I was wondering if anyone knew of a way to add an Icon/Bitmap to a Cbutton? I have already included the icon into my project as a resource: IDI_CHECKMARK. I need to find a way to load this into the Button control m_SaveBtn.

I know that I can use the member func: SetIcon() which takes a HICON parameter. The question is how do I get the resource IDI_CHECKMARK into the HICON format?

And if I can do this, will SetIcon() work. I saw an MSDN article (142226) that says this function will only work in Windows 95. Is this true?

Any other ideas are welcome.

Regards,
Jeff
 
Code:
mybtn->SetIcon(AfxGetApp()->LoadIcon( IDI_CHECKMARK));

-pete
 
Ok,

That does work, but only when the "Icon" option is checked in the Button control properties. If I leave it unchecked the button does not change. Also, when I am in Icon mode, the normal Button text: "Save" disappears and is replaced by the icon.

How do I keep the original button text AND have the icon present at the same time?

Thanks for your help so far!

Jeff
 
I'm sorry I "wasted" your time with that one line response. Everytime I submit a long difficult question no one responds to me. An I'm sorry I didn't know that you couldn't have text and a graphic at the same time, I just assume that adding an icon would do just that: Add, not replace.

If I sound a little peeved, that's because I am. I don't like being accused of wasting people's time in a forum that designed to help those who don't have the experience and knowledge of VC++. I didn't think the original post was a burden, and I hope no one else views it that way.

I do appreciate your link to CSXButton class. This is exactly what I needed. I thank you for your time (both wasted and useful).

Jeff
 
Jeff, I realize now that you did not know what would happen after placing the icon on the button and therefore could not get to your second post without the first, my bad.

However my request was posted in a very polite fashion and should not be responded to with any attitude on your part. You’re a little peeved?

>> If I sound a little peeved, that's because I am.

I have been helping people on this site freely with my own time for several years now. I have posted thousands of responses attempting to help 100s of people, of which you are only one. There are frequent situations where posters have not taken the time to post a clear concise question. I mistakenly identified yours as one of these. I frequently post tips attempting to help people get the most out of using these forums and streamline the process. I see nothing offensive or discourteous in my post that warrants your reply. In short… lose the attitude.

-pete
 
Sorry Pete,

Statement withdrawn: delete >> If I sound a little peeved, that's because I am.

<<>>

That's the problem with text messages, sometimes certain words convey feelings that are not intended by the writer. When you said &quot;ask the question you want answered in the first post to keep people from wasting their time&quot; regarding my first post, I interpreted that as belittling my question. And while no question is a stupid question, that's what I felt like after reading your response.

I understand that you misinterpreted it, and apologize for my abrasive and vehement reply. I have also seen inadequate descriptions for posts and can see where you were coming from.

One piece of advise: &quot;The Pen is mightier than the Sword&quot; or in our case &quot;The Keyboard is mightier than the Sword&quot; .... Beware the power of words.

Jeff

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top