unit CommandLink;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Windows, Graphics, Messages;
type
TCommandLink =
class(TButton)
private
fNote: WideString;
fShield: Boolean;
fIcon: TIcon;
procedure SetNote(Value: WideString);
procedure SetShield(Value: Boolean);
procedure SetIcon(Value: TIcon);
procedure UpdateIcon(Sender: TObject);
protected
procedure CreateParams(
var Params: TCreateParams);
override;
public
constructor Create(AOwner: TComponent);
override;
published
property Note: WideString
read fNote
write SetNote;
property Shield: Boolean
read fShield
write SetShield
default false;
property Icon: TIcon
read fIcon
write SetIcon;
end;
procedure Register;
const
BS_COMMANDLINK = $0000000E;
BCM_SETNOTE = $00001609;
BCM_FIRST = $1600;
BCM_SETSHIELD = BCM_FIRST + $000C;
BM_SETIMAGE = $00F7;
implementation
constructor TCommandLink.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fIcon := TIcon.Create;
fIcon.OnChange := UpdateIcon;
end;
procedure TCommandLink.CreateParams(
var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style
or BS_COMMANDLINK;
end;
procedure TCommandLink.SetNote(Value: WideString);
begin
SendMessage(
Handle, BCM_SETNOTE, 0, lParam(Pointer(Value)));
fNote := Value;
end;
procedure TCommandLink.SetShield(Value: Boolean);
begin
SendMessage(
Handle, BCM_SETSHIELD, 0, lParam(Value));
fShield := Value;
end;
procedure TCommandLink.SetIcon(Value: TIcon);
begin
SendMessage(
Handle, BM_SETIMAGE, 1, lParam(fIcon.Handle));
fIcon.Assign(Value);
end;
procedure TCommandLink.UpdateIcon(Sender: TObject);
begin
SendMessage(
Handle, BM_SETIMAGE, 1, lParam(fIcon.Handle));
end;
procedure Register;
begin
RegisterComponents('
Vista', [TCommandLink]);
end;
end.