解决这个问题的方法之一:手动解析活动*.msstyles文件。通常这是 aero.msstyles。不同窗口控件的位图存储在 STREAM 部分。对于 Windows 7 ResId = 971,Windows 8:Id = 1060,Windows 10:Id = 1194。但这是手动工作,并且此位图不同。
Update:
我发现,即使对于 Windows 的一个版本(针对 8 进行测试),我们也可以为该位图(png 图像)拥有不同的资源 id 值,现在我可以提供代码来获取任何 Windows 上的资源 id(针对 7 进行测试) ,8,10):
function EnumStreamProc(hModule: HMODULE; AType, AName: PChar; Params: LPARAM): BOOL; stdcall;
var
Id: NativeInt;
begin
PNativeInt(Params)^ := Integer(AName);
Result := False;
end;
function GetStyleResourceId(AModule: HMODULE): Integer;
begin
Result := 0;
EnumResourceNames(AMODULE, 'STREAM', @EnumStreamProc, LPARAM(@Result));
end;
var
hLib: HMODULE;
ResId: Integer;
RS: TResourceStream;
Png: TPngImage;
begin
hLib := LoadLibraryEx(PChar(GetWindowsPath + 'Resources\Themes\Aero\aero.msstyles'),
0, LOAD_LIBRARY_AS_DATAFILE);
ResId := GetStyleResourceId(hLib);
RS := TResourceStream.CreateFromID(hLib, ResId, 'STREAM');
Png := TPngImage.Create;
Png.LoadFromStream(RS);
...
end;
更新2:
使用官方api发现未破解的方法:
var
h: HTHEME;
Rect: TRect;
PBuf, PPBuf: Pointer;
BufSize: Cardinal;
Buf: array[0..1024*1024] of Byte;
h := OpenThemeData(Handle, 'DWMWINDOW');
if h <> 0 then
try
GetThemeRect(h, WP_MINCAPTION, MNCS_ACTIVE, TMT_ATLASRECT, Rect);
PBuf := @Buf[0];
PPBuf := @PBuf;
GetThemeStream(h, WP_MINCAPTION, MNCS_ACTIVE, TMT_ATLASRECT, PBuf, BufSize, hInstance);
finally
CloseThemeData(h);
end;
我可以获取最小化按钮的 Rect,但不明白如何使用 GetThemeStream?还有应该用PBuf还是PPBuf?