Question

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:

  • The standard Windows 8 close button, using Windows 8's minimalist non-Glass appearance.
  • The standard Windows 8 MDI close button (WP_MDICLOSEBUTTON, looking a bit out of place due to its more pronounced gradient, but that's Microsoft's decision.
  • The close button that I'm drawing myself, using a full-blown Aero Glass style (identical appearance to Windows 7) and looking rather out of place as a result.

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top