×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Problem in Loading Bitmap To A Button

Problem in Loading Bitmap To A Button

Problem in Loading Bitmap To A Button

(OP)
Hi
   I am trying to load a Icon to a bitmap to a BUTTON .
But it is not loading the Bitmap .
The code I am writing is in the OnInitDialog of the Dialog Class .
The Code is
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// get a handler to the button
HWND hOk;

/* The button is control IDOK*/
hOk = (HWND) GetDlgItem(IDOK);

/* The icon is IDI_UP in the resource file */
HICON hU = (HICON) ::LoadImage  (AfxGetResourceHandle   (),MAKEINTRESOURCE(IDI_UP),IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
::SendMessage( hOk, BM_SETIMAGE, IMAGE_ICON,(LPARAM)(DWORD) hU );

return TRUE;  
}
 What is the problem with the above code . Please find me
a solution at the earliest . I want the solution in this way
only.

RE: Problem in Loading Bitmap To A Button

Dear moono,

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.

Then your dialog class has a CBitmap member named _bmp like this:

class CAboutDlg : public CDialog
{
... stuff
  CBitmap _bmp;
... stuff
};

Then in your OnInitDialog you do this:

CButton* pBtn = (CButton*)GetDlgItem(IDOK);
ASSERT( pBtn);
_bmp.LoadBitmap(IDB_OK);
pBtn->SetBitmap(_bmp);


Good luck
-pete

RE: Problem in Loading Bitmap To A Button

(OP)
Thanks -pete
  I tried this . But i had to set the owner draw
property of the Button also . Why that property
needed to be set . Is settting the Bitmap property
is not enough ?
  I have another question also . In which cases
we will set the check the icon property ?
 Thanks again for your reply....
       Moonoo

RE: Problem in Loading Bitmap To A Button

(OP)
Hi Pete
  Sorry i forgot to ask you another thing . This
way we are loading the Bitmap to the Button at run
time(while initializing the dialg) . Is there some
way to lead the Bitmap or icon at design time also.
      Thanks . Please send a early reply...
                      Moonoo

RE: Problem in Loading Bitmap To A Button

Dear Moonoo,

>Is there some way to lead the Bitmap or icon at design time also

Not that I know of.

>But i had to set the owner draw property of the
>Button also . Why that property needed to be set

On my system (NT4, VC6) I did not have to set the owner draw property.

Hope this helps
-pete

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close