Delphi 完全时尚手册之 Visual Style 篇
---使非标准 Win32 控件或自画控件也具有 Windows XP 的界面风格
这里先说说两个概念:theme(主题)和 Visual Style 。Theme 最早出现在 Microsoft Plus! for Windows 95 中,是 Windows 中 Wallpaper、Cursors、Fonts、Sounds 、Icons 等的设置值集合。Visual Style 在 Windows XP 中才被引入,Visual Style 规定了 Contorls 的外观,另外还包括使用这些外观的一套 API 。使用 Visual Style 必须要 ComCtl32.dll 6,而 ComCtl32.dll 6 是不能被分发到以前版本的 Windows 中的,所以只能在 Windows XP 下使用 Visual Style。
procedure TVSPanel.Paint;
var
Details: TThemedElementDetails;
begin
inherited;
if ThemeServices.ThemesEnabled then
begin
Details := ThemeServices.GetElementDetails(tbPushButtonHot); {这里画个按钮处于 Hot 状态下的样子}
PerformEraseBackground(Self, Canvas.Handle); {擦除画按钮时的背景}
ThemeServices.DrawElement(Canvas.Handle, Details, ClientRect);
ThemeServices.DrawText(Canvas.Handle, Details, Caption, ClientRect,
DT_EXPANDTABS or DT_VCENTER or DT_CENTER or DT_SINGLELINE, 0);
end;
end;