Ask a questionAsk a question
 

AnswerButton control with bitmap

  • Saturday, November 07, 2009 6:25 PMDavid_21 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

All Replies

  • Saturday, November 07, 2009 7:44 PMNikita Leontiev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    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);
    
  • Saturday, November 07, 2009 8:10 PMDavid_21 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    It doesn't work at all if i don't set the BS_BITMAP style as i saw in your code.
  • Saturday, November 07, 2009 10:55 PMNikita Leontiev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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 appear

    I don't know why =) Maybe someone from the MVPs can help
  • Sunday, November 08, 2009 6:42 AMDavid_21 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    If i use DeleteObject() right after setting the image, the image just wouldn't appear.
  • Sunday, November 08, 2009 12:26 PMNikita Leontiev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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.