Bitmap in buttons?

Started by
3 comments, last by En3my 22 years, 1 month ago
I am working on a level editor for a game that I''m making, and I am wondering how I can make buttons with a bitmap. I place the buttons in a modeless dialogbox, where the user can select different "tiles" by clicking on the buttons. I want the button to look pressed when selected. How can I do this in Visual C++ 6.0? All I need to know is how to make a button with an image in it? Thanks for your time and help!
Advertisement
Are you using MFC? Have a look at the CBitmapButton class or CButton::SetBitmap.
No, I am sorry... I was tired last night so I forgot to tell that I''m not using MFC... Can it be done with the Dialog Resource editor somehow? When I add buttons to my dialog, there is a check box saying BITMAP... How can I add the graphics to these buttons? Thanks!
You have to manually load the images in the WM_INITDIALOG message and associate them with the button as follows:

/* Load the button images */
hBmpRotateAntiClockwise = (HBITMAP)LoadImage( hInst,MAKEINTRESOURCE(IDB_ROTATE_ANTI_CLOCKWISE), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );

hBmpRotateClockwise = (HBITMAP)LoadImage( hInst, MAKEINTRESOURCE(IDB_ROTATE_CLOCKWISE), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );

/* Now attatch the bitmaps to the buttons */
SendDlgItemMessage( hDlg, IDC_ROTATE_LEFT_90, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)(HBITMAP)hBmpRotateAntiClockwise );

SendDlgItemMessage( hDlg, IDC_ROTATE_RIGHT_90, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)(HBITMAP)hBmpRotateClockwise );

Remeber that because you have to manually load the images and store them somewhere, you should release them when you close the dialog...
You have to manually load the images in the WM_INITDIALOG message and associate them with the button as follows:

/* Load the button images */
hBmpRotateAntiClockwise = (HBITMAP)LoadImage( hInst,MAKEINTRESOURCE(IDB_ROTATE_ANTI_CLOCKWISE), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );

hBmpRotateClockwise = (HBITMAP)LoadImage( hInst, MAKEINTRESOURCE(IDB_ROTATE_CLOCKWISE), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );

/* Now attatch the bitmaps to the buttons */
SendDlgItemMessage( hDlg, IDC_ROTATE_LEFT_90, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)(HBITMAP)hBmpRotateAntiClockwise );

SendDlgItemMessage( hDlg, IDC_ROTATE_RIGHT_90, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)(HBITMAP)hBmpRotateClockwise );

Remeber that because you have to manually load the images and store them somewhere, you should release them when you close the dialog...

This topic is closed to new replies.

Advertisement