CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2002
    Posts
    298

    Load Icon to bitmap

    Hi!
    Can anyone tell me how to load an Icon on to a Bitmap.

    I have smiley Icon and I want it on a Button.
    For that I used BS_PUSHBUTTON and BS_OWNERDRAW and created a button.
    But how to get this smiley onto button.Can i load into a icon and set bitmap on button or any other way.

    Thanks in advance,
    Gupta.

  2. #2
    Join Date
    Jun 2001
    Location
    UK
    Posts
    128
    I'd use:

    HICON hMyIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));

    Then to display it on the button, use

    DrawIcon(hDC, x_position, y_position, hMyIcon);

    Hope this helps

    Ben

  3. #3
    Join Date
    Dec 2001
    Location
    Canada/Montreal
    Posts
    983
    With the following Article you can do that and a lot more:

    http://www.codeproject.com/buttonctrl/cbuttonst.asp

    Regards, Sonu Kapoor
    Sonu [MVP, MCAD.NET]
    Website: http://DotNetSlackers.com

  4. #4
    Join Date
    Jan 2002
    Posts
    298
    By subclassing the Button we can do lot of things.But without doing that is there any way to do.

    Thanks for spending your precious time.
    Waiting for reply.
    Gupta.

  5. #5
    Join Date
    Jun 2001
    Location
    UK
    Posts
    128
    The only way I know of is either subclassing...e.g. inheriting your own class and doing your own drawing.

    class CMyButton : public CButton
    {
    ... etc etc
    }

    or setting a new proc...using setwindowlong api..

  6. #6
    Join Date
    Jun 2001
    Location
    UK
    Posts
    128
    If you jsut want to change the image...there's a class called

    CBitmapButton

    with a member:

    BOOL LoadBitmaps(
    UINT nIDBitmapResource,
    UINT nIDBitmapResourceSel = 0,
    UINT nIDBitmapResourceFocus = 0,
    UINT nIDBitmapResourceDisabled = 0
    );


    the 4 different parameters to the LoadBitmap member are the standard bitmap view, up bitmap, down bitmap etc.

    Hope it helps

  7. #7
    Join Date
    Jul 2002
    Location
    Connecticut, U.S.
    Posts
    275
    Hi Gupta,

    I'm not sure exactly what you want, but if you want to get an icon on a button:

    1) create the button with style BS_ICON
    2) load the icon
    3) call CButton::SetIcon()

    Good luck,
    John Flegert

  8. #8
    Join Date
    Jan 2002
    Posts
    298
    this is what i wanted to do.

    thanks a lot.
    Gupta.

  9. #9
    Join Date
    Dec 2001
    Location
    singapore, China
    Posts
    32
    Originally posted by jflegert
    Hi Gupta,

    I'm not sure exactly what you want, but if you want to get an icon on a button:

    1) create the button with style BS_ICON
    2) load the icon
    3) call CButton::SetIcon()

    Good luck,
    John Flegert
    Hi,

    Can you please teach me how you load the icon and call CButton::SetIcon ? I realise that there are available icons in the Microsoft Visual Studio\Common\Graphics\Icons, how do I make use of them? I want to displace them on the buttons in my application.

    Thanks in advance
    I am not smart, I am just very very curious!

    ----Albert Einstein

  10. #10
    Join Date
    Jul 2002
    Location
    Connecticut, U.S.
    Posts
    275
    To load an icon, I use LoadIcon or LoadImage. I would suggest looking in MSDN.

    Good luck,
    John Flegert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured