很简单的一个例子, 设置form1上的Button1的颜色为红色:
....
type
TForm1=class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
BtnBrush: TBrush;
OldBtnWndProc: TWndMethod;
procedure BtnWndProc(var Message: TMessage);
end;
....
procedure TForm1.FormCreate(Sender: TObject);
begin
BtnBrush := TBrush.Create;
BtnBrush.Style := bsSolid;
BtnBrush.Color := clRed;
OldBtnWndProc := Button1.WindowProc;
Button1.WindowProc := BtnWndProc;
end;
procedure TForm1.BtnWndProc(var Message: TMessage);
begin
case Message.Msg of
WM_CTLCOLORBTN:
Message.Result := BtnBrush.Handle;
else
OldBtnWndProc(Message);
end;
end;