can i make an image a button?

making my first GUI program in visual studios and I want to know can i put an image onto a button or make an image a button?

im making a program thats like a quiz. the program will ask a question and there will be a few choices (these will be buttons). The user has to click one of the buttons and the quiz will move on the next question.

i want the buttons to be pictures/bitmaps

thanks
Last edited on
It depends on what lib you're using. Is this WinAPI?
yes its WinAPI so is there a simple way to add an image to a button? I have the button made i just need to put the image in
Last edited on
I'm very rusty on that area of WinAPI. I'd have to research it, which I can't do at work =(. Maybe someone else can help.
ok thanks anyway
can anyone help with this?
and if anyone has some sample code it would really help
Once you've created your button -- with the right styles -- you can send it a BM_SETIMAGE message to set the image (loaded using LoadImage).

See MSDN entry for BM_SETIMAGE for the different styles (controlling if you get just the image or image and text, etc)

Also see this thread from last month: "Drawing a bitmap or icon in a button"
http://www.cplusplus.com/forum/windows/50741/
Last edited on
sorry im still a bit confused i've never used BM_SETIMAGE before

Heres what i have so far for the button

1
2
3
hwndButton5 = CreateWindow( L"button",L"Drum",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, cxBlock, cyBlock*20, 5*cxBlock, 2*cyBlock,
hWnd, (HMENU)IDC_BUTTON5, hInst,NULL);

the button displays fine but i want the button to be an image not a square button

so what would i do to this code to put the bitmap in?

heres the code i wrote for the bitmap if its any help
1
2
3
4
5
6
7
8
//bitmap image of drums
hdc = GetDC (hWnd);
memDC = CreateCompatibleDC(hdc);
memBM = CreateCompatibleBitmap(hdc, 48, 48);
m = LoadImage(hInst, (LPCWSTR)IDB_BITMAP1, IMAGE_BITMAP, 0, 0, LR_VGACOLOR);
SelectObject (memDC, m);
BitBlt(hdc, LOWORD(lParam), HIWORD(lParam), 400, 200, memDC, 2, 4, SRCCOPY);
ReleaseDC(hWnd, hdc);



thanks
Last edited on
Your original post asked how to put an image onto a button, which is the problem BM_SETIMAGE solves (an image on a rectangular button)

For a custom shaped button, you'll need to use an owner draw button. See button style BS_OWNERDRAW and the WM_DRAWITEM message.
Topic archived. No new replies allowed.