![]() |
LoadLibrary vs GetModuleHandle, eine Verständisfrage
Hallo, hier mal ein stück code mit einem Ergebnis was mich etwas verwirrt.
gegeben ist dieser Auszug aus meinem ![]() In dieser Variante, funktioniert (auch wenn falsch integriert) bei gesetzten ThemeDarkLight es halbwegs so wie ich es erhoffe.
Delphi-Quellcode:
himitsu schrieb ich soll auf LoadLibrary verzichten und direkt per GetModuleHandle zugreifen sowie den Schutzblock entfernen, gesagt getan:
type
TkzTheme = (ThemeNone, ThemeDarkLight, ThemeSystem, ThemeWallpaper); kzTheme = class(TObject) ... strict private FStyleTheme: TkzTheme; strict private procedure SetDwmMode(const AMode: ShortInt); ... end; AccentPolicy = packed record AccentState: Integer; AccentFlags: Integer; GradientColor: Integer; AnimationId: Integer; end; TWinCompAttrData = packed record attribute: THandle; pData: Pointer; dataSize: ULONG; end; var SetWindowCompositionAttribute: function(Wnd: HWND; const AttrData: TWinCompAttrData): BOOL; stdcall = nil; implementation procedure kzTheme.SetDwmMode(const AMode: ShortInt); const WCA_ACCENT_POLICY = 19; ACCENT_DISABLE = 0; ACCENT_ENABLE_GRADIENT = 1; ACCENT_ENABLE_TRANSPARENT = 2; ACCENT_ENABLE_BLURBEHIND = 3; GRADIENT_COLOR = $01000000; DrawLeftBorder = $20; DrawTopBorder = $40; DrawRightBorder = $80; DrawBottomBorder = $100; var dwm10: THandle; data: TWinCompAttrData; accent: AccentPolicy; begin if (not ((AMode = ACCENT_DISABLE) or (AMode = ACCENT_ENABLE_TRANSPARENT) or (AMode = ACCENT_ENABLE_BLURBEHIND))) then Exit; dwm10 := LoadLibrary(user32); try @SetWindowCompositionAttribute := GetProcAddress(dwm10, 'SetWindowCompositionAttribute'); if @SetWindowCompositionAttribute <> nil then begin accent.AccentState := AMode; accent.AccentFlags := DrawLeftBorder or DrawTopBorder or DrawRightBorder or DrawBottomBorder; if ((FStyleTheme = ThemeSystem) or (FStyleTheme = ThemeWallpaper)) then accent.GradientColor := FColorBackground; data.attribute := WCA_ACCENT_POLICY; data.dataSize := SizeOf(accent); data.pData := @accent; SetWindowCompositionAttribute(FForm.Handle, data); end; finally FreeLibrary(dwm10); end; end; initialization SetWindowCompositionAttribute := GetProcAddress(GetModuleHandle(user32), 'SetWindowCompositionAttribute'); end.
Delphi-Quellcode:
Doch nun funktioniert wenn ThemeDarkLight aktiv ist (Hintergrund ist schwarz) es nicht mehr.
procedure kzTheme.SetDwmMode(const AMode: ShortInt);
const WCA_ACCENT_POLICY = 19; ACCENT_DISABLE = 0; ACCENT_ENABLE_GRADIENT = 1; ACCENT_ENABLE_TRANSPARENT = 2; ACCENT_ENABLE_BLURBEHIND = 3; GRADIENT_COLOR = $01000000; DrawLeftBorder = $20; DrawTopBorder = $40; DrawRightBorder = $80; DrawBottomBorder = $100; var data: TWinCompAttrData; accent: AccentPolicy; begin if (not ((AMode = ACCENT_DISABLE) or (AMode = ACCENT_ENABLE_TRANSPARENT) or (AMode = ACCENT_ENABLE_BLURBEHIND))) then Exit; @SetWindowCompositionAttribute := GetProcAddress(GetModuleHandle(user32), 'SetWindowCompositionAttribute'); if @SetWindowCompositionAttribute <> nil then begin accent.AccentState := AMode; accent.AccentFlags := DrawLeftBorder or DrawTopBorder or DrawRightBorder or DrawBottomBorder; if ((FStyleTheme = ThemeSystem) or (FStyleTheme = ThemeWallpaper)) then accent.GradientColor := FColorBackground; data.attribute := WCA_ACCENT_POLICY; data.dataSize := SizeOf(accent); data.pData := @accent; SetWindowCompositionAttribute(FForm.Handle, data); end; end; Liegt es daran das mein code generell falsch ist oder gibt es doch unterschiede zwischen LoadLibrary und GetModuleHandle die mir momentan noch verborgen sind? LG |
AW: LoadLibrary vs GetModuleHandle, eine Verständisfrage
Hmmm..
Delphi-Quellcode:
was sagt hUser ?
var
hUser: HModule; begin hUser := GetModuleHandle('user32.dll'); @SetWindowCompositionAttribute := GetProcAddress(hUser, 'SetWindowCompositionAttribute'); end; GetModuleHandle(user32) <> GetModuleHandle('user32.dll'); |
AW: LoadLibrary vs GetModuleHandle, eine Verständisfrage
Danke Emil für Deine Vorschläge! :thumb:
Ich habe mir alle Varianten mal in einer Box darstellen lassen, alle lieferten die gleiche Nummer. Der Fehler, bzw das was irgendwie anders arbeitet ist hier verborgen:
Delphi-Quellcode:
so funktioniert es momentan, auch wenn nur dürftig (habe immer noch dein video im hinterstübchen^^)
...
@SetWindowCompositionAttribute := GetProcAddress(GetModuleHandle(user32), 'SetWindowCompositionAttribute'); // <- so ruf ich es nun auf ... if ((FStyleTheme = ThemeSystem) or (FStyleTheme = ThemeWallpaper)) then accent.GradientColor := FColorBackground else accent.GradientColor := FColorText; // das hier musste gesetzt werden damit der hintergrund wieder transparent wird... |
AW: LoadLibrary vs GetModuleHandle, eine Verständisfrage
Warum du dich weigerst einen String zu übergeben ist mir schleierhaft.
Siehe ![]()
Code:
Es sei denn du hast user32 als const definiert. (vielleicht in irgendeiner Unit in Delphi selbst)
HMODULE GetModuleHandleA(
LPCSTR lpModuleName ); Kann ich jetzt nicht sehen. Wie dem auch sei. :) |
AW: LoadLibrary vs GetModuleHandle, eine Verständisfrage
Zitat:
Habe es ja mit beide Variationen getestet, als
Delphi-Quellcode:
und auch als
user32
Delphi-Quellcode:
, gleiches Resultat erhalten.
'user32.dll'
Die
Delphi-Quellcode:
datei hat es als
uses Winapi.Windows
Delphi-Quellcode:
definiert
const
Delphi-Quellcode:
.
user32 = 'user32.dll';
|
AW: LoadLibrary vs GetModuleHandle, eine Verständisfrage
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:46 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz