Autor Beitrag
bbfan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Fr 29.12.06 16:29 
Hi!

Momentan stelle ich über diese Funktion fest, ob der XP Sytle aktiviert ist oder nicht.
Leider sehr schlecht gelöst finde ich, da ich eine Exception abfange. Tritt eine Exception auf, so ist der Style inaktiv.
Gibt es was besseres als das?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
function getXPStyleActive():boolean;
var
  FileName, ColorScheme, SizeName: WideString;
  hThemeLib: THandle;
var
  GetCurrentThemeName: function (pszThemeFileName: LPWSTR; cchMaxNameChars: Integer;
    pszColorBuff: LPWSTR; cchMaxColorChars: Integer; pszSizeBuff: LPWSTR;
    cchMaxSizeChars: Integer): HRESULT; stdcall;
begin
  try
    result:=false;
    hThemeLib := LoadLibrary('uxtheme.dll');
    if hThemeLib > 0 then
      GetCurrentThemeName := GetProcAddress(hThemeLib, 'GetCurrentThemeName');
    if Assigned(GetCurrentThemeName) then
    begin
      SetLength(FileName, 255);
      SetLength(ColorScheme, 255);
      SetLength(SizeName, 255);
      try
       OleCheck(GetCurrentThemeName(PWideChar(FileName), 255, PWideChar(ColorScheme), 255, PWideChar(SizeName), 255));
       Result:=true;
      except
       Result:=false;
      end;
    end;
  finally
    FreeLibrary(hThemeLib);
  end;
end;
mpth
Hält's aus hier
Beiträge: 6

Win XP
Delphi 7 Prof, Turbo Delphi 2006 Prof.
BeitragVerfasst: Fr 29.12.06 16:39 
ausblenden Delphi-Quelltext
1:
Result := GetCurrentThemeName(PWideChar(FileName), 255, PWideChar(ColorScheme), 255, PWideChar(SizeName), 255) = S_OK;					


das vermeidet zumindest mal das abfangen einer exception...

aber hast du schon mal an IsThemeActive oder IsAppThemed gedacht?

_________________
hexen ist keine kunst, sondern harte arbeit...
bbfan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Fr 29.12.06 17:37 
Hab jetzt die hier. Die ist super:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
function _IsThemeActive: Boolean;
// Returns True if the user uses XP style
const
  themelib = 'uxtheme.dll';
type
  TIsThemeActive = function: BOOL; stdcall;
var
  IsThemeActive: TIsThemeActive;
  huxtheme: HINST;
begin
  Result := False;
  // Check if XP or later Version
  if (Win32Platform  = VER_PLATFORM_WIN32_NT) and
     (((Win32MajorVersion = 5) and (Win32MinorVersion >= 1)) or
      (Win32MajorVersion > 5)) then
  begin
    huxtheme := LoadLibrary(themelib);
    if huxtheme <> 0 then
    begin
      try
        IsThemeActive := GetProcAddress(huxtheme, 'IsThemeActive');
        Result := IsThemeActive;
      finally
       if huxtheme > 0 then
          FreeLibrary(huxtheme);
      end;
    end;
  end;
end;