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.