const
WM_SETTINGCHANGE = $001A;
function SetWindowSubclass(hWnd: HWND; pfnSubclass, uIdSubclass, dwRefData: LongWord): BOOL; external 'SetWindowSubclass@comctl32.dll stdcall';
function RemoveWindowSubclass(hWnd: HWND; pfnSubclass, uIdSubclass: LongWord): BOOL; external 'RemoveWindowSubclass@comctl32.dll stdcall';
function DefSubclassProc(hWnd: HWND; uMsg: UINT; wParam, lParam: LongWord): LongWord; external 'DefSubclassProc@comctl32.dll stdcall';
var
GWndProc: LongWord;
GAppsUseLightTheme: Boolean;
procedure HandleLightTheme;
begin
GAppsUseLightTheme := True;
MsgBox('Light', mbInformation, MB_OK);
end;
procedure HandleDarkTheme;
begin
GAppsUseLightTheme := False;
MsgBox('Dark', mbInformation, MB_OK);
end;
function WndProc(hWnd: HWND; uMsg: UINT; wParam, lParam, uIdSubclass, dwRefData: LongWord): LongWord;
var
LAppsUseLightTheme: DWORD;
begin
case uMsg of
WM_SETTINGCHANGE:
begin
if (CompareText(CastIntegerToString(lParam), 'ImmersiveColorSet') = 0) and
RegQueryDWordValue(HKCU, 'Software\Microsoft\Windows\CurrentVersion\Themes\Personalize', 'AppsUseLightTheme', LAppsUseLightTheme) then
begin
if (LAppsUseLightTheme = 1) and not GAppsUseLightTheme then
HandleLightTheme
else if (LAppsUseLightTheme = 0) and GAppsUseLightTheme then
HandleDarkTheme;
end;
Result := DefSubclassProc(hWnd, uMsg, wParam, lParam);
end;
else
Result := DefSubclassProc(hWnd, uMsg, wParam, lParam);
end;
end;
function InitializeSetup: Boolean;
var
LAppsUseLightTheme: DWORD;
begin
Result := True;
if GetWindowsVersion > $0A004500 then
if RegQueryDWordValue(HKCU, 'Software\Microsoft\Windows\CurrentVersion\Themes\Personalize', 'AppsUseLightTheme', LAppsUseLightTheme) then
GAppsUseLightTheme := LAppsUseLightTheme = 1
else
GAppsUseLightTheme := False;
end;
procedure InitializeWizard;
begin
if GetWindowsVersion > $0A004500 then
begin
if GWndProc = 0 then
GWndProc := {#ifdef IS_ENHANCED}CallbackAddr('WndProc'){#else}CreateCallback(@WndProc){#endif};
SetWindowSubclass(WizardForm.Handle, GWndProc, 0, 0);
end;
end;
procedure DeinitializeSetup;
begin
if GetWindowsVersion > $0A004500 then
begin
if ExpandConstant('{wizardhwnd}') = '0' then Exit;
RemoveWindowSubclass(WizardForm.Handle, GWndProc, 0);
end;
end;