Button control with bitmap
- Hi, when i create an xp style button and then set the image, the xp style look of button disappears.
//create a push button HWND hbutton1 = CreateControl(0, hParent, hInst, BS_PUSHBUTTON|BS_BITMAP|WS_CHILD|WS_VISIBLE , rc, id, "caption" , ("BUTTON" )); //set image SendMessage(hbutton1, BM_SETIMAGE, IMAGE_BITMAP, LPARAM(img)); //img is the handle to bitmap
any ideas?- Edited byDavid_21 Saturday, November 07, 2009 8:11 PM
Answers
- OK. I googled some more and found this CodeProject article.It seems to me that BS_BITMAP cannot be used with visual theme under XP.Under Vista works correctly.
- Marked As Answer byWesley YaoMSFT, ModeratorFriday, November 13, 2009 3:45 AM
All Replies
- I have created sample and it works for me:
HWND hButton = CreateWindow(L"BUTTON", L"OK", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 10, 10, 100, 50, hWnd, (HMENU)1000, (HINSTANCE)hInstance, NULL); HBITMAP hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP)); SendMessage(hButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)(HBITMAP)hBitmap); DeleteObject((HBITMAP)hBitmap);
- It doesn't work at all if i don't set the BS_BITMAP style as i saw in your code.
- To understand usage of BS_BITMAP look here (remarks section).On my Vista:when I add manifest dependency#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")bitmap displays correctly with my code posted above,when I remove it, bitmap doesn't appearI don't know why =) Maybe someone from the MVPs can help
- If i use DeleteObject() right after setting the image, the image just wouldn't appear.
- OK. I googled some more and found this CodeProject article.It seems to me that BS_BITMAP cannot be used with visual theme under XP.Under Vista works correctly.
- Marked As Answer byWesley YaoMSFT, ModeratorFriday, November 13, 2009 3:45 AM


