如何使用GetThemeStream保存Windows主题部分? (DWMWINDOW除外) [英] How to save Windows theme part using GetThemeStream? (other than DWMWINDOW)

查看:99
本文介绍了如何使用GetThemeStream保存Windows主题部分? (DWMWINDOW除外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用



另请参阅:如何获取与Windows主题相关的图标?


I want to save the original PNG/BMP (32 bit with alpha) of the theme part with a specific state using GetThemeStream function.
It works well for DWMWINDOW parts as described here: GetThemeStream usage

But I'm unable to get other theme parts other than DWMWINDOW.
The OpenThemeData(0, 'BUTTON') is OK, but the call to GetThemeStream fails:

It always returns HResult -2147023728 ($80070490) : element not found.

function SaveTheme(const APathToSave: string): Boolean;
const
  ThemeRegPath = 'SOFTWARE\Microsoft\Windows\CurrentVersion\ThemeManager';
var
  hTh: HTHEME;
  hLib: HMODULE;
  DllName, Path: string;
  MS: TMemoryStream;
  BufSize: Cardinal;
  PBuf: Pointer;
  hr: HResult;
begin
  Result := False;
  { hTh := OpenThemeData(0, 'DWMWINDOW'); } // <- this works OK
  hTh := OpenThemeData(0, 'BUTTON');
  if hTh <> 0 then
  try
    // Get Library path
    SetLength(DllName, 1024);
    SHRegGetPath(HKEY_CURRENT_USER, PChar(ThemeRegPath), 'DllName', PChar(DllName), 0);
    // Open Library
    hLib := LoadLibraryEx(PChar(DllName), 0, LOAD_LIBRARY_AS_DATAFILE);
    if hLib > 0 then
    try
      hr := GetThemeStream(hTh, BP_PUSHBUTTON, PBS_NORMAL, TMT_DISKSTREAM, PBuf, BufSize, hLib);
      if hr = S_OK then begin
        MS := TMemoryStream.Create;
        try
          MS.WriteBuffer(PByteArray(PBuf)^[0], BufSize);
          MS.Position := 0;
          MS.SaveToFile(APathToSave);
          Result := True;
        finally
          MS.Free;
        end;
      end;
    finally
      FreeLibrary(hLib);
    end;
  finally
    CloseThemeData(hTh);
  end;
end;

Q: How can I save a BUTTON (BP_PUSHBUTTON) part with a state of PBS_NORMAL into a PNG using GetThemeStream?

The documentation is very poor and there are any examples on the web. I made a great effort to find some leads on how to use this functions, but I was unable to find anything useful.

解决方案

After a bit more digging, I think @RemyLebeau was right and there is nothing I can do with GetThemeStream. specially since the documentation is a joke.

The only thing that "works" is GetThemeBitmap. which is also a mystery in itself. it disregards the part State and the output bitmap contains all the available states.

See also: How to get an icon associated with Windows theme?

这篇关于如何使用GetThemeStream保存Windows主题部分? (DWMWINDOW除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆