Oct 19, 2011 at 4:28pm UTC
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 Oct 20, 2011 at 12:32pm UTC
Oct 19, 2011 at 5:34pm UTC
It depends on what lib you're using. Is this WinAPI?
Oct 19, 2011 at 5:35pm UTC
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 Oct 19, 2011 at 6:16pm UTC
Oct 19, 2011 at 7:09pm UTC
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.
Oct 20, 2011 at 7:43pm UTC
can anyone help with this?
and if anyone has some sample code it would really help
Oct 21, 2011 at 4:53am UTC
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 Oct 21, 2011 at 4:57am UTC
Oct 24, 2011 at 10:28am UTC
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 Oct 24, 2011 at 12:45pm UTC
Oct 24, 2011 at 8:38pm UTC
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.