winapiwindows-themes

Windows 10 Close, Minimize and Maximize buttons


to paint themed button I use this code:

var
  h: HTHEME;
begin
  if UseThemes then begin
    SetWindowTheme(Handle, 'explorer', nil);
    h := OpenThemeData(Handle, 'WINDOW');
    if h <> 0 then
    try
      DrawThemeBackground(h, Canvas.Handle, WP_CLOSEBUTTON, GetAeroState, ClientRect, nil);
    finally
      CloseThemeData(h);
    end;
  end
  else
    DrawFrameControl(Canvas.Handle, ClientRect, DFC_CAPTION, DFCS_CAPTIONCLOSE or GetClassicState)
end;

This code works fine but painted button looks like from Windows 7 theme, even on Windows 8 or 10. This is possible to paint the Close button using Windows 10 or 8 theme?

enter image description here


Solution

  • Workable solution to get bitmaps from theme:

    var
      h: HTHEME;
      Rect: TRect;
      BufSize: Cardinal;    
    
    h := OpenThemeData(Handle, 'DWMWINDOW');
    if h <> 0 then
    try
      GetThemeRect(h, WP_MINCAPTION, MNCS_ACTIVE, TMT_ATLASRECT, Rect);
      ...
      GetThemeStream(...);
    finally
      CloseThemeData(h);
    end;
    

    And how to use GetThemeStream described here: GetThemeStream usage, many thanks to Andreas Verhoeven, author of the program Vista Style Builder