首页 > 代码库 > XP风格

XP风格

unit Unit1;
//加上这句和下边的{$R WindowsXP.res} 相当于放了一个xp风格组件,激活了风格
{$WEAKPACKAGEUNIT ON} //弱引用,参见编译指令
interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Themes;
//引用 Themes 单元,此单元中提供一组服务,用来调用系统的 uxtheme.dll 风格库
//其中提供了各种空间风格的绘制函数,具体调用可参见 Thems 单元

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

TMyThemsControl = class(TPanel)
private
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
protected
procedure Paint; override;
end;

var
Form1: TForm1;
{$R WindowsXP.res}
implementation

{$R *.dfm}

{ TMyThemsControl }

procedure TMyThemsControl.Paint;
var
Details: TThemedElementDetails;
begin
inherited;
//获取一种风格
Details := ThemeServices.GetElementDetails(themes.tbPushButtonNormal);
ThemeServices.DrawElement(Canvas.Handle, Details, Self.ClientRect, nil);
end;


procedure TMyThemsControl.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
//判断服务是否开启
if ThemeServices.ThemesEnabled then
Message.Result := 1
else
DefaultHandler(Message);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
b: TMyThemsControl;
begin
b := TMyThemsControl.Create(self);
b.Parent := Self;
end;

end.

XP风格