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!

Problem in Loading Bitmap To A Button 1

Status
Not open for further replies.

moonoo

Programmer
May 17, 2000
62
US
Hi<br>&nbsp;&nbsp;&nbsp;I am trying to load a Icon to a bitmap to a BUTTON .<br>But it is not loading the Bitmap .<br>The code I am writing is in the OnInitDialog of the Dialog Class .<br>The Code is <br>BOOL CAboutDlg::OnInitDialog() <br>{<br> CDialog::OnInitDialog();<br> <br> // get a handler to the button<br> HWND hOk;<br><br> /* The button is control IDOK*/<br> hOk = (HWND) GetDlgItem(IDOK);<br><br> /* The icon is IDI_UP in the resource file */<br> HICON hU = (HICON) ::LoadImage&nbsp;&nbsp;(AfxGetResourceHandle&nbsp;&nbsp;&nbsp;(),MAKEINTRESOURCE(IDI_UP),IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );<br> ::SendMessage( hOk, BM_SETIMAGE, IMAGE_ICON,(LPARAM)(DWORD) hU );<br><br> return TRUE;&nbsp;&nbsp;<br>}<br>&nbsp;What is the problem with the above code . Please find me<br>a solution at the earliest . I want the solution in this way<br>only.
 
Dear moono,<br><br>First you must have the BS_BITMAP style applied to the button. This can be done from the resource editor on the buttons property dialog.<br><br>Then your dialog class has a CBitmap member named _bmp like this:<br><br>class CAboutDlg : public CDialog<br>{<br>... stuff<br>&nbsp;&nbsp;CBitmap _bmp;<br>... stuff<br>};<br><br>Then in your OnInitDialog you do this:<br><br>CButton* pBtn = (CButton*)GetDlgItem(IDOK);<br>ASSERT( pBtn);<br>_bmp.LoadBitmap(IDB_OK);<br>pBtn-&gt;SetBitmap(_bmp);<br><br><br>Good luck<br>-pete
 
Thanks -pete<br>&nbsp;&nbsp;I tried this . But i had to set the owner draw<br>property of the Button also . Why that property<br>needed to be set . Is settting the Bitmap property<br>is not enough ?<br>&nbsp;&nbsp;I have another question also . In which cases<br>we will set the check the icon property ?<br>&nbsp;Thanks again for your reply....<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Moonoo
 
Hi Pete<br>&nbsp;&nbsp;Sorry i forgot to ask you another thing . This<br>way we are loading the Bitmap to the Button at run<br>time(while initializing the dialg) . Is there some<br>way to lead the Bitmap or icon at design time also.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thanks . Please send a early reply...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Moonoo
 
Dear Moonoo,<br><br>&gt;Is there some way to lead the Bitmap or icon at design time also<br><br>Not that I know of.<br><br>&gt;But i had to set the owner draw property of the <br>&gt;Button also . Why that property needed to be set <br><br>On my system (NT4, VC6) I did not have to set the owner draw property.<br><br>Hope this helps<br>-pete<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top