Changeset 116 for trunk/Packages/Common/Theme.pas
- Timestamp:
- Dec 11, 2024, 10:47:08 AM (11 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Theme.pas
r115 r116 25 25 end; 26 26 27 TDwmSetWindowAttribute = function(hwnd: HWND; dwAttribute: DWORD; pvAttribute: Pointer; cbAttribute: DWORD): HRESULT; stdcall; 28 27 29 { TThemeManager } 28 30 … … 31 33 FTheme: TTheme; 32 34 FActualTheme: TTheme; 35 DwmapiLib: TLibHandle; 36 DwmSetWindowAttribute: TDwmSetWindowAttribute; 33 37 function Gray(C: TColor): Byte; 34 38 procedure SetTheme(AValue: TTheme); … … 52 56 ThemeNameLight = 'Light'; 53 57 ThemeNameDark = 'Dark'; 58 DwmapiLibName = 'dwmapi.dll'; 59 DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19; 60 DWMWA_USE_IMMERSIVE_DARK_MODE = 20; 54 61 55 62 procedure Register; … … 158 165 159 166 procedure TThemeManager.SetThemedTitleBar(AForm: TForm; Active: Bool); 160 type 161 TDwmSetWindowAttribute = function(hwnd: HWND; dwAttribute: DWORD; pvAttribute: Pointer; cbAttribute: DWORD): HRESULT; stdcall; 162 const 163 DwmapiLibName = 'dwmapi.dll'; 164 DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19; 165 DWMWA_USE_IMMERSIVE_DARK_MODE = 20; 166 var 167 DwmapiLib: TLibHandle; 168 DwmSetWindowAttribute: TDwmSetWindowAttribute; 167 var 169 168 Attr: DWord; 170 169 begin 170 if Assigned(DwmSetWindowAttribute) and IsWindows10OrGreater(17763) then begin 171 Attr := DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1; 172 if IsWindows10OrGreater(18985) then Attr := DWMWA_USE_IMMERSIVE_DARK_MODE; 173 174 DwmSetWindowAttribute(AForm.Handle, Attr, @Active, SizeOf(Active)); 175 end; 176 end; 177 178 procedure TThemeManager.SetTheme(AValue: TTheme); 179 begin 180 if FTheme = AValue then Exit; 181 FTheme := AValue; 182 FActualTheme := FTheme; 183 {$IFDEF WINDOWS} 184 if Assigned(FTheme) and (FTheme = Themes.FindByName(ThemeNameSystem)) and IsDarkTheme then 185 FActualTheme := Themes.FindByName(ThemeNameDark); 186 {$ENDIF} 187 end; 188 189 constructor TThemeManager.Create(AOwner: TComponent); 190 begin 191 inherited; 192 {$IFDEF WINDOWS} 171 193 DwmapiLib := LoadLibrary(DwmapiLibName); 172 194 if DwmapiLib <> 0 then DwmSetWindowAttribute := GetProcAddress(DwmapiLib, 'DwmSetWindowAttribute') 173 195 else DwmSetWindowAttribute := nil; 174 175 if Assigned(DwmSetWindowAttribute) and IsWindows10OrGreater(17763) then begin 176 Attr := DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1; 177 if IsWindows10OrGreater(18985) then Attr := DWMWA_USE_IMMERSIVE_DARK_MODE; 178 179 DwmSetWindowAttribute(AForm.Handle, Attr, @Active, SizeOf(Active)); 180 end; 181 if DwmapiLib <> 0 then FreeLibrary(DwmapiLib); 182 end; 183 184 procedure TThemeManager.SetTheme(AValue: TTheme); 185 begin 186 if FTheme = AValue then Exit; 187 FTheme := AValue; 188 FActualTheme := FTheme; 189 {$IFDEF WINDOWS} 190 if Assigned(FTheme) and (FTheme = Themes.FindByName(ThemeNameSystem)) and IsDarkTheme then 191 FActualTheme := Themes.FindByName(ThemeNameDark); 192 {$ENDIF} 193 end; 194 195 constructor TThemeManager.Create(AOwner: TComponent); 196 begin 197 inherited; 196 {$ENDIF} 197 198 198 Themes := TThemes.Create; 199 199 with Themes.AddNew(ThemeNameSystem) do begin … … 224 224 begin 225 225 FreeAndNil(Themes); 226 {$IFDEF WINDOWS} 227 if DwmapiLib <> 0 then FreeLibrary(DwmapiLib); 228 {$ENDIF} 226 229 inherited; 227 230 end;
Note:
See TracChangeset
for help on using the changeset viewer.