1

I'm having problems drawing Windows 10 themed Window Caption Buttons using the VisualStyleRenderer class.

My problem is that I can't figure out which Theme Class to use. I tried Window and CompositedWindow::Window, however, none of those actually contain Windows 10 themed buttons as I found out using this msstyle editor.

Which Theme Class contains Windows 10 themed Caption Buttons?

How it looks now:

Windows 7 themed button

How I want it to look:

Windows 10 themed caption buttons

How I'm drawing the buttons:

protected override void OnPaint(PaintEventArgs e)
{
    VisualStyleRenderer renderer = new VisualStyleRenderer("Window", 18 /*WP_CLOSEBUTTON*/, 1 /*CBS_NORMAL*/);
    var size = renderer.GetPartSize(e.Graphics, ThemeSizeType.True);
    renderer.DrawBackground(e.Graphics, new System.Drawing.Rectangle(10, 10, size.Width, size.Height));
}
thebear8
  • 194
  • 2
  • 11
  • You could have a look at the Chrome source and see how they do it. – Jonathan Potter Jun 01 '20 at 20:10
  • 1
    Those are probably rendered using the [Segoe MDL2](https://learn.microsoft.com/en-us/windows/uwp/design/style/segoe-ui-symbol-font) font. – IInspectable Jun 01 '20 at 21:06
  • @JonathanPotter I looked through chrome and firefox source, it looks like they both draw the caption buttons similarly by using DrawThemeBackground with `Window` theme, but I could have overlooked something. – thebear8 Jun 01 '20 at 21:43

1 Answers1

1

The problem is the Window class you are using. This is the legacy GDI Window that is composited without a composition engine.

The DWM Desktop Window Manager composites every window, as every window is just a DirectX surface. You need to use the DWMWindow class as opposed to the Window class from aero.msstyles.

enter image description here

Notice how there are multiple glyphs for each DPI: 96, 120, 144, etc.

Arush Agarampur
  • 1,340
  • 7
  • 20
  • Can I still draw the buttons using a VisualStyleRenderer or DrawThemeBackground? If so, what Part IDs and State IDs do I have to use? – thebear8 Jun 03 '20 at 13:44
  • @thebear8 It's a little more complicated. I don't have a C# sample handy, but you need to use `LoadLibraryEx`, `OpenThemeData`, and `GetThemeStream` to get a pointer to a PNG file in memory that contains all the modern aero glyphs. You can then use `GetThemeRect` to find the correct rectangle of the glyph you need. For more info, see the answer to this question: https://stackoverflow.com/questions/34222021/getthemestream-usage – Arush Agarampur Jun 04 '20 at 00:53
  • Thanks! That's exactly what I was looking for. – thebear8 Jun 04 '20 at 11:34