dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How to create a modernized image based button control using the WinAPI

  1. #1
    Join Date
    Dec 2017
    Posts
    6

    How to create a modernized image based button control using the WinAPI

    Hi Gurus,

    Firstly, please forgive me if something similar has been posted before, to be completely honest, this has been bugging me now for quiet some time...
    I have search high and low and I just can't seem to find any information on the subject, yes I have seen 'use the BS_FLAT button style' or 'go with an owner draw button' etc but have failed miserably.

    Here are examples of buttons taken from various apps.

    Name:  Button1.png
Views: 115
Size:  531 Bytes
    Name:  Button2.png
Views: 113
Size:  803 Bytes
    Name:  Button3.png
Views: 113
Size:  974 Bytes
    Name:  Button4.png
Views: 113
Size:  1.2 KB

    As you can see, there simply border-less buttons containing an image, but most importantly they have visual styles, highlighting on hover, shadows on button click on so on, individual buttons behaving exactly like a image set Toolbar button!

    I would hugely appreciate any information on how this is done using nothing more than the WinAPI, I could simply just be overlooking/missing something and if turns out to be something simple, then I do apologize in advance!

    Looking forward to your replies!

    -Dan

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,487

    Re: How to create a modernized image based button control using the WinAPI

    highlighting on hover, shadows on button click on so on
    I think these are owner-drawn buttons with a different 'picture' displayed for different states. So highlighting on hover isn't actually highlighting, but a different owner-drawn picture displayed when the mouse is over the button. Similarly when a button-click is detected, shadows is again a different owner-drawn picture being displayed. Each button might have several of these slightly different pictures associated with it and the one shown at any one-time depends upon the state of the button.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.9)

  3. #3
    Join Date
    Dec 2017
    Posts
    6

    Re: How to create a modernized image based button control using the WinAPI

    Hey 2kaud

    Thanks for your reply!
    Quote Originally Posted by 2kaud
    I think these are owner-drawn buttons with a different 'picture' displayed for different states.
    Your not wrong! Just had a quick bash at this, finally seeing some good results, like you mentioned though, you need several images to represent the different states.
    However, I am interested to know how Windows mimics this behavior when rendering Tool Bar buttons for example, you only supply a single image per button yet windows ends up rendering a flat/border-less button as well as the common visual effects of pushdown / hot etc, I'm presuming the answer is hidden somewhere in the Visual Styles API but cannot find any code examples out there demonstrating what I'm after

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,258

    Re: How to create a modernized image based button control using the WinAPI

    Quote Originally Posted by Danage View Post
    ...
    However, I am interested to know how Windows mimics this behavior when rendering Tool Bar buttons for example, you only supply a single image per button yet windows ends up rendering a flat/border-less button as well as the common visual effects of pushdown / hot etc, I'm presuming the answer is hidden somewhere in the Visual Styles API but cannot find any code examples out there demonstrating what I'm after
    Have a look at Painting and Drawing Functions in MSDN, such as DrawEdge, DrawFocusRect, DrawState, ...
    Victor Nijegorodov

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,808

    Re: How to create a modernized image based button control using the WinAPI


Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)