Title: Windows XP Style and Color Scheme
Question: How can I retrieve the WinXP Color Scheme (Blue, Green, Silver) ?
Answer:
// Tested under D7, WinXP Pro SP1 English and French version.
// For Delphi 4, 5 and 6 users, you should go to this great site
http://www.delphi-gems.com/ThemeManager.php
// You could download ThemeManager components from Mike Lischke
uses ...
UxTheme;
type
TWinXPColorScheme = (csNone, csBlue, csOliveGreen, csSilver);
...
function GetXPStyleColorScheme: TWinXPColorScheme;
const
SZ_MAX_NAME_CHARS = 1024;
var
PThemeFileName, PThemeColor, PThemeSize: PWideChar;
begin
Result := csNone;
if IsThemeActive and IsAppThemed then begin
PThemeFileName := AllocMem( 2 * SZ_MAX_NAME_CHARS );
PThemeColor := AllocMem( 2 * SZ_MAX_NAME_CHARS );
PThemeSize := AllocMem( 2 * SZ_MAX_NAME_CHARS );
try
if not Failed(
GetCurrentThemeName( PThemeFileName, SZ_MAX_NAME_CHARS,
PThemeColor, SZ_MAX_NAME_CHARS,
PThemeSize, SZ_MAX_NAME_CHARS ) ) then begin
if PThemeColor = 'NormalColor' then
Result := csBlue
else
if PThemeColor = 'HomeStead' then
Result := csOliveGreen
else
if PThemeColor = 'Metallic' then
Result := csSilver;
end;
finally
FreeMem(PThemeSize);
FreeMem(PThemeColor);
FreeMem(PThemeFileName);
end;
end;
end;
// How to call this function
// ---------------------------
procedure TForm1.Button1Click(Sender: TObject);
begin
case GetXPStyleColorScheme of
csBlue : Button1.Caption := 'Blue';
csOliveGreen : Button1.Caption := 'Olive Green';
csSilver : Button1.Caption := 'Silver';
else
Button1.Caption := 'None';
end;
end;