24. marts 2005 - 20:47Der er
1 kommentar og 1 løsning
Detect mouseclick
Hvordan laver jeg et program, der kalder ShowMessage('hello world') når brugeren klikker, også selvom programmet ligger i System Tray?, minimeret, etc., dvs. UDEN for delphi-programmets Form?
type TForm1 = class(TForm) Button1: TButton; Button2: TButton;
ApplicationEvents1: TApplicationEvents; procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCreate(Sender: TObject); private { Private declarations } IfStarted : Boolean; public { Public declarations } end;
var Form1: TForm1; i : integer;
implementation
{$R *.dfm}
var MntrH: THandle;
function Mntr(t, wParam: Integer; var evnMsg: TEventMsg): Integer; stdcall; var Char1: PChar; s: string; begin Result := CallNextHookEx(MntrH, t, wParam, Longint(@evnMsg));
if t < 0 then exit; if t = HC_SYSMODALON then exit;
if t = HC_ACTION then begin if evnMsg.message = WM_LBUTTONDOWN then begin i := i+1; form1.caption := 'Antal klik: '+inttostr(i); end; end; end;
procedure TForm1.Button1Click(Sender: TObject); begin if IfStarted = true then begin Abort; Exit; end;
MntrH := SetWindowsHookEx(WH_JOURNALRECORD, @Mntr, hInstance, 0); if MntrH > 0 then IfStarted := True else Abort;
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); begin Handled := false; if (Msg.message = WM_CANCELJOURNAL) and IfStarted = true then MntrH := SetWindowsHookEx(WH_JOURNALRECORD, @Mntr, 0, 0); end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin if IfStarted = true then UnhookWindowsHookEx(MntrH); end;
procedure TForm1.FormCreate(Sender: TObject); begin i := 0; end;
end.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.