[RESOLVED] Add Icon to a Button , keeping the Text
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: [RESOLVED] Add Icon to a Button , keeping the Text

  1. #1
    Join Date
    Jan 2006
    Location
    Italy
    Posts
    47

    [RESOLVED] Add Icon to a Button , keeping the Text

    Hi, I've lurked many hours to understand this... but I'm not so good to understand the code of the others..

    - I have a button in a dialog application.
    - To get some colours, I would like to place an ICON or a BITMAP (as you wish..) on the left of the button, keeping my previous Text (I made text changes to the button during execution... so text is dynamic).
    -The Icon/Bitmap must move up and down with the button , better with transparency background color.


    I use Visual C++ 6.0 upon Windows Me, so the problem could be this... because code I've tried fail in data exception or something...

    Can you post the Best, simple, and easy way to get the Icon/bitmap on the left of a CButton ?

    Thanks in advance.
    Lord Hol Napult
    ----------------------------------------------------
    Freeware Game : No One Shoots Forever
    Builder's Heaven (Cobol/Easytrieve): BH Homepage
    LHN Digital & Informatic Blog: NOSF BLOG

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    Re: Add Icon to a Button , keeping the Text

    Owner draw button would help you.
    Have a look at "button" sections on www.codeguru.com and www.codeproject.com
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2006
    Location
    Italy
    Posts
    47

    Re: Add Icon to a Button , keeping the Text

    yes, and I've tryed many ways... but failed.

    Essentially, I dont want to use a foreign class already prepared, I would like to understand what to put in OnInitDialog ....
    Lord Hol Napult
    ----------------------------------------------------
    Freeware Game : No One Shoots Forever
    Builder's Heaven (Cobol/Easytrieve): BH Homepage
    LHN Digital & Informatic Blog: NOSF BLOG

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    Re: Add Icon to a Button , keeping the Text

    Quote Originally Posted by LordHolNapult View Post
    yes, and I've tryed many ways... but failed.
    What did fail? Could you showhow you did it and where it "failed"?

    Quote Originally Posted by LordHolNapult
    Essentially, I dont want to use a foreign class already prepared, I would like to understand what to put in OnInitDialog ....
    If you "dont want to use a foreign class already prepared" then you will need to create your own class from the very begin...
    However, I recommend you to start with some of already designed class and extend it according your needs. One more example: A Better Bitmap Button Class
    Victor Nijegorodov

  5. #5
    Join Date
    Jan 2008
    Posts
    178

    Re: Add Icon to a Button , keeping the Text

    Quote Originally Posted by VictorN View Post
    Owner draw button would help you.
    No, you don't need owner-draw at all for this.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    Re: Add Icon to a Button , keeping the Text

    Quote Originally Posted by fred100 View Post
    No, you don't need owner-draw at all for this.
    Good answer!
    And would you so kind to explain how to implement the
    Quote Originally Posted by LordHolNapult View Post
    I would like to place an ICON or a BITMAP (as you wish..) on the left of the button, keeping my previous Text ...
    without owner drawing under:
    Quote Originally Posted by LordHolNapult View Post
    I use Visual C++ 6.0 upon Windows Me...
    Victor Nijegorodov

  7. #7
    Join Date
    Jan 2006
    Location
    Italy
    Posts
    47

    Re: Add Icon to a Button , keeping the Text

    Well, thank u for the code. I will study it later.
    At the moment I've found a class that does what I've needed... but it's not mine :|

    I was suppose not to create a class, but to modify my already defined dialog class to reach my purpose. Anyway, after seeing all the code you and I have found (3 examples tried and 10 i.e.pages readed), I must admit that the task thieves at least 200 lines of code, just to manage the position of the icon and a bit of resize...

    I must also admit that no one did as I would like to do, but everyone creates a class and applied a "dodataexchange" that binds between the buttonimage class and the button ID...

    Probably you are right (... and me I'm wrong . Class is required, just to add a simple icon to a button....

    I quote you. Thanks. But let me say a last thing... Microsoft! Hell fu@&%+**in B@st4%&&&ds!!!
    ciao
    Lord Hol Napult
    ----------------------------------------------------
    Freeware Game : No One Shoots Forever
    Builder's Heaven (Cobol/Easytrieve): BH Homepage
    LHN Digital & Informatic Blog: NOSF BLOG

  8. #8
    Join Date
    Jan 2008
    Posts
    178

    Re: Add Icon to a Button , keeping the Text

    Quote Originally Posted by VictorN View Post
    Good answer!
    And would you so kind to explain how to implement the
    without owner drawing under:
    Just read MSDN on Button control v6.
    5 lines of code...

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    Re: Add Icon to a Button , keeping the Text

    Quote Originally Posted by fred100 View Post
    Just read MSDN on Button control v6.
    5 lines of code...
    Could you provide a link to these "5 lines of code" or just post these lines?
    Victor Nijegorodov

  10. #10
    Join Date
    May 2005
    Posts
    13

    Re: [RESOLVED] Add Icon to a Button , keeping the Text

    Hi,

    I want to add an icon with transparent back color to a common radio button with push-like property, CButton class. Just this! I don't want complex derived classes to redraw a all control, I search in MSDN an many places more, but I don't know how to do it.

    Please, may you help me to find this 5 lines of code that do it?

    Thank you very much.

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center