Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

cbitmap - how to add bitmap image to buttons in MFC?

I am Trying to add an image to an existing button..I have done that to an extent, the problem is I can add an ownerdrawn Image but am not able to add the extact image that I want.. for the example see the below code

CButton* pBtn= (CButton*)GetDlgItem(ID_WIZBACK);

   pBtn->ModifyStyle( 0, BS_ICON );

   HICON hIcn= (HICON)LoadImage(
        AfxGetApp()->m_hInstance,
  MAKEINTRESOURCE(IDI_ICON3),
        IMAGE_ICON,
        0,0, // use actual size
        LR_DEFAULTCOLOR
    );

    pBtn->SetIcon( hIcn );

with the above code am converting the bitmap to an icon to add to my button...how can I add the exact Bitmap image directly to an existing button.Please help me frnds..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Steps for assigning bitmap to button in mfc :

  1. Create object of bitmap
  2. Load bitmap by using LoadBitmap()
  3. Get Handle of button using id and GetDlgItem() method
  4. Modify style so that we can assign bitmap to it
  5. use SetBitmap() on button's handle to assign bitmap

Code :

CBitmap bmp;

bmp.LoadBitmap( IDB_BITMAP4 );

CButton* pButton = (CButton* )GetDlgItem(IDC_BUTTON1);

pButton->ModifyStyle(0,BS_BITMAP);

pButton->SetBitmap(bmp);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...