Thread: Ownerdraw buttons (again, I know)

  1. #1

    Ownerdraw buttons (again, I know)

    I'm having some trouble. No, that's an understatment, I have no clue what I'm doing.
    I haven't worked much with bitmap, but I want to make some ownerdraw buttons. When the user presses a button, the image should change for the time of the mousebutton down. But that's for later, I can't even get the image on the button

    As I understand it, you have to create the button and load the bitmap durng the WM_CREATE and draw it during the WM_DRAWITEM.

    her's my code:
    Code:
    //defntions:
    #define BUTTON1 40
    
    static HBITMAP hbitmap;
    static BITMAP bm;
    static HWND hbutton;
    
    
    case WM_CREATE:
    hbitmap=(HBITMAP) LoadImage(hinstance, "play.bmp", IMAGE_BITMAP,SM_CXICON,SM_CYICON,LR_LOADFROMFILE);
    GetObject(hbitmap, sizeof(bm), &bm);//don't know if I need this
    hbutton=CreateWindow( "button",NULL, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, 
    210, 350, 100,100, hwnd, (HMENU)BUTTON1, hinstance, 0 ); 
    
    case WM_DRAWITEM :
    SendMessage(hbutton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbitmap);
    Am I forgetting something? Or did I make some huge error here (or possebly more then one)


    Thanks

    --Maes
    Last edited by maes; 09-03-2003 at 03:55 PM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    I think you may be confusing 'bitmap' or 'image' buttons (ie those buttons that use BM_SETIMAGE) with owner-drawn controls (ie those with the BS_OWNERDRAW style that require you to draw everything in response to WM_DRAWITEM messages).

    There's an example of owner-drawn buttons here (msdn) that may be of some use. There's also an example in this thread of owner-drawn menus that may also be of some interest.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    So if I understand you correctly, if I use BS_BITMAP, I have to use the sendmessa function, and if I use the BS_OWNERDRAW, I have to use StretchBlit


    Now that I look at it, it seems logical

    And the msdn example did the trick, I got it to work

    Hip hip hora for Sir Fitlike

    Thanks Ken

    --Maes

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 04-09-2009, 02:31 AM
  2. Ownerdraw buttons (2)
    By maes in forum Windows Programming
    Replies: 7
    Last Post: 09-11-2003, 05:50 AM
  3. Radio Buttons in Visual C++ 6
    By Ripper1 in forum Windows Programming
    Replies: 22
    Last Post: 05-16-2003, 07:54 AM
  4. (Ken Fitlike) buttons
    By jdinger in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2002, 01:21 PM
  5. Grouping radio buttons
    By Bazz in forum Windows Programming
    Replies: 1
    Last Post: 08-28-2001, 07:15 AM