windowswindows-8themesaero-glassvisual-styles

Visual styles in Windows 8


I have the following C++ code (native desktop app) that uses Microsoft's Visual Styles API to draw a close button.

RECT r = DetermineButtonRect();
HANDLE h = OpenThemeData(Handle, L"WINDOW");
DrawThemeBackground(h, hdc, WP_CLOSEBUTTON, CBS_NORMAL, &rect, NULL);
CloseThemeData(h);

This works fine in earlier versions of Windows, but in Windows 8, it insists on drawing in the Windows 7 style. This isn't horrible, but it's still frustrating to not have all of the parts of the application use the same visual style. Here's a screenshot of what this looks like:

close buttons

From top to bottom:

Is there any way to get the Visual Styles API to draw Windows 8 style (non-Glass) buttons? Or is there a different API I should be using?


Solution

  • Use WP_SMALLCLOSEBUTTON which appears to work on both Windows 7 and Windows 8 with the correct theme.