Jeg har nu fundet en løsning via Windows API, der gør det jeg vil, på
http://www.delphi3000.com/articles/article_3647.aspDa artiklen ikke bare kan læses, men kræver at man registrerer sig (selv da kan man kun læse op til 50 gratis artikler), er her den kode jeg er nået frem til:
type
TForm1 = class(TForm)
sbtnStatus: TSpeedButton;
procedure sbtnStatusClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
protected
procedure WMCommand(var Msg: TWMCommand); message WM_COMMAND;
public
pmStatus: TPopUpMenu;
end;
const
WM_STATUSOFFLINE = WM_USER + 101;
WM_STATUSONLINE = WM_USER + 102;
implementation
{$R *.dfm}
procedure TForm1.WMCommand(var Msg: TWMCommand);
begin
case Msg.ItemID of
WM_STATUSOFFLINE:
sbtnStatus.Caption := 'Offline';
WM_STATUSONLINE:
sbtnStatus.Caption := 'Online';
end;
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
IndlaegRec: TIndlaegNoteRec;
begin
pmStatus := TPopUpMenu.Create(Self);
pmStatus.AutoPopup := FALSE;
pmStatus.AutoHotkeys := maManual;
AppendMenu(pmStatus.Handle, MF_STRING or MF_UNCHECKED, WM_STATUSOFFLINE, '&Offline');
AppendMenu(pmStatus.Handle, MF_STRING or MF_UNCHECKED, WM_STATUSONLINE, '&Online');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
pmStatus.Free;
end;
procedure TForm1.sbtnStatusClick(Sender: TObject);
var
Msg : LongBool;
PopupPos: TPoint;
begin
PopupPos := sbtnStatus.ClientToScreen(Point(sbtnStatus.Left, sbtnStatus.Top));
Msg := TrackPopupMenuEx(pmStatus.Handle, TPM_LEFTALIGN or TPM_LEFTBUTTON or TPM_BOTTOMALIGN or TPM_RETURNCMD, PopupPos.X, PopupPos.Y, Handle, nil);
if Msg then
SendMessage(Handle, WM_COMMAND, Integer(Msg), 0);
end;