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!

display an icon on a button

Status
Not open for further replies.

sumedha

Programmer
Apr 12, 2000
15
LK
hi,<br>how do you display an icon on a button?<br>I have a Icon as &quot;andy.ico&quot;<br>I want to display this icon on a button.<br>can someone please send me the code snippet?<br>I'm using VC++ 6.<br>(I experimented with SetIcon, SetBitmap but couldn't get it to work.)<br>Sumedha
 
Hi Sumedha,<br>See what I did was, I put a button on a Dialog Box, then in the Resource View goto the properties of the button, there on the <b>STYLES</b> tab, select <font color=red>Icon</font>.<br>Then I added an Icon resource, if you have a <font color=red>.ICO</font>, copy it in the <b>res</b> directory of your project then just import that file in your project , it will get a name say for eg IDI_YOURICON etc after that <br>in OnInitDialog()of the Dialogs class i just added this code<br>CButton* pButton = (CButton*)GetDlgItem(IDC_BUTTON1);<br>HICON hIcon = LoadIcon(AfxGetInstanceHandle(),(LPCTSTR)IDI_YOURICON);<br>pButton-&gt;SetIcon(hIcon); <br><br>It worked fine for me,<br><br>Hope this works for you :)<br>Regards<br>Sun<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top