BMP on button?

This is a discussion on BMP on button? within the Windows Programming forums, part of the Platform Specific Boards category; I have a BMP loaded. It loads fine but I have 1 problem. I try this: SendMessage(GetDlgItem(hwnd, 1001), BM_SETIMAGE, (WPARAM)GfxCnt, ...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question BMP on button?

    I have a BMP loaded. It loads fine but I have 1 problem. I try this:


    SendMessage(GetDlgItem(hwnd, 1001), BM_SETIMAGE, (WPARAM)GfxCnt, (LPARAM)0);


    Nothing happens. How would I set an image on a button? If you can let me know this too it would be great:


    How would I detect a WM_LBUTTONDOWN on a bitmap?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    According to MSDN the WPARAM should either be IMAGE_BITMAP or IMAGE_ICON and the LPARAM is the handle to the image.

    If you want to fully customise the way buttons behave when click look into Owner-Draw buttons.

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Wink Oops...

    Sorry that was the wrong code, here's what I have:


    CreateWindow(
    "button",
    NULL,
    WS_CHILD | WS_VISIBLE | BS_OWNERDRAW | BS_BITMAP,
    210, 350,
    100, 20,
    hwnd,
    (HMENU)100,
    0,
    0
    );

    SendMessage(GetDlgItem(hwnd, 100), BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)netftp_cnt);

    It does not work for me!
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    What's netftp_cnt?

  5. #5
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb That is...

    The netftp_cnt is my HBITMAP for the BMP to go on the button.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  6. #6
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Another snippet from MSDN -

    Do not combine the BS_OWNERDRAW style with any other button styles.
    I removed the BS_OWNERDRAW style and did a quick test using an icon instead of a bitmap and your code worked fine.

    If you still want an Owner-Draw button, you'll have to paint your bitmap on receipt of a WM_DRAWITEM message and not using BM_SETIMAGE.

  7. #7
    Unregistered
    Guest
    If you use the BS_BITMAP style you don't need the BS_OWNERDRAW style.

    If you want an owner draw button then use BS_OWNERDRAW style in which case you will need to handle at the very least the WM_DRAWITEM msg in order to render the button's appearance in its various states. You might want to take a look at WM_MEASUREITEM too.

    As to your 2nd question: "...WM_LBUTTONDOWN on a bitmap?",
    assuming you mean the bmp that hopefully will appear on your button then there are a couple of possibilities.

    1. Get the coords from the WM_LBUTTONDOWN and use PtInRect fn to see if mouse click has 'hit' the button. It should be a short task from there to see if it hit the bitmap on the button.

    2. Subclass the button control and handle the subclassed button's WM_LBUTTONDOWN handler. You have to provide a wndproc for the subclassed button, use SetWindowLong to 'attach' it to the cntrl after it has been created and use CallWindowProc for default msg handling. Make sure you store the return value from SetWindowLong - (WNDPROC) - and use SetWindowLong with that stored value to reset to the sytem wndproc for the button control prior to its destruction.

    If you just mean a bitmap that's blitted onto an wnd then just ensure you store the bmp's dimensions/coords and use the PtInRect fn for hit-testing.

    Does this help?

  8. #8
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question Can I have...

    I tried it with an icon like this:


    netftp_cnt=LoadBitmap(hInst, "Ico1");

    GetObject(netftp_right, sizeof(bm), &bm);

    CreateWindow(
    "button",
    NULL,
    WS_CHILD | WS_VISIBLE | BS_BITMAP,
    210, 350,
    100, 20,
    hwnd,
    (HMENU)100,
    0,
    0
    );

    SendMessage(GetDlgItem(hwnd, 100), BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)netftp_cnt);


    That didn't work either. Can I see some code?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  9. #9
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    I didn't mean you should use an icon. I just used one to test your code -
    HICON test = LoadIcon(0, IDI_APPLICATION);

    HWND hbutton =CreateWindow(
    "button",
    NULL,
    WS_CHILD | WS_VISIBLE | BS_ICON,
    210, 350,
    100,100,
    hWnd,
    (HMENU)100,
    0,
    0
    );


    SendMessage(hbutton, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)test);

  10. #10
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question How do i...

    I got the icon. I will just use it with text. How do I load a custom Icon?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  11. #11
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question How do I...

    Ok. I am just going to use Icon and Text. How do I load a custom Icon on to a Button?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  12. #12
    Unregistered
    Guest
    seemsto be a lot of similtaneous posting going on here! Sorry for the above reapeat of 'Sorensen's' note - but it honestly wasn't there when I posted my original reply!

    Seems like you guys have it well sorted out anyway

  13. #13
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >How do I load a custom Icon?

    If it's from file then -

    HICON test =(HICON) LoadImage(GetModuleHandle(0), "icon1.ico",IMAGE_ICON,SM_CXICON,SM_CYICON,LR_LOAD FROMFILE);

    Otherwise if it's a resource then you can use LoadIcon() with the resource ID.

  14. #14
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Talking Thanks!

    Thanks for your help! I did that but changed it to BMP and it worked! Thanks!
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  15. #15
    Registered User
    Join Date
    Aug 2001
    Posts
    223
    Here is what I found in the MSD and it worked fine for me...

    you can do this for any of the button types checkbox, radio or pushbutton. The only problem is that the button image remains the same in all states..except when disabled...

    Code:
    
    m_bmp.LoadBitmap( IDB_MYBMP );
    
    HBITMAP hbmp = m_bmp.operator HBITMAP();
    
    //** Get pointer to the bitmap
    m_button.SetBitmap( hbmp );
    zMan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2008, 08:30 PM
  2. elliptical button
    By geek@02 in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2006, 01:15 AM
  3. Problem reading BMP
    By Mortissus in forum C Programming
    Replies: 4
    Last Post: 02-02-2006, 05:32 AM
  4. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  5. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 08:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21