how to achieve button style in winapi

Diya Al deen 20 Reputation points
2024-01-27T23:40:42.12+00:00

In The Windows Api(or anytime when using MinGW-w64), when creating a button they have a classic style, i want to achieve a style that dynamically varies between windows versions, on windows 11 it has grey border, white background, rounded, and blue masked when hovered over, on windows 10/8.x it is like windows 11, but gre background and sharp corners and black border, on windows 7/vista it is like windows 11 one, but with visual effects aappplied, someone pleasetell me how to achieve this style of button, i see it everywhere in windows, one common answer is BS_OWNERDRAW and WM_DRAWITEM, but i dont think so, like i see it everywhere in windows, there must be a way without custom drawing

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,654 questions
{count} votes

2 answers

Sort by: Most helpful
  1. David Lowndes 2,555 Reputation points MVP
    2024-01-27T23:46:35.8233333+00:00

    Is your application configured to use visual styles? See here for how to enable them.

    2 people found this answer helpful.

  2. Tong Xu - MSFT 2,471 Reputation points Microsoft Vendor
    2024-01-30T03:05:59.1766667+00:00

    Indeed enabling visual styles makes difference.
    Just add the code on the top of the header, it will change something even through using custom controls or not.
    #pragma comment(linker,"\"/manifestdependency:type='win32' \ name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

    See the effect:

    (before): beforevisual

    (after): aftervisual


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.