unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls, ComCtrls, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit3: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure ShowHwndAndClassName(CrPos: TPoint);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
hwnd: THandle;
Form1: TForm1;
JHook: THandle;
Track: Boolean;
hWndx: THandle;
implementation
{$R *.dfm}
procedure Tform1.ShowHwndAndClassName(CrPos: TPoint);
var
Text:
array[0..255]
of char;
begin
hWndx := WindowFromPoint(CrPos);
SendMessage(GetActiveWindow(), WM_GETTEXT, SizeOf(Text), integer(@Text));
Edit1.text := Text;
end;
function JournalProc(Code, wParam: Integer;
var EventStrut: TEVENTMSG): Integer;
stdcall;
var
Char1: PChar;
rPos: TPoint;
C:
array[0..127]
of Char;
S:
string;
begin
{this is the JournalRecordProc}
Result := CallNextHookEx(JHook, Code, wParam, Longint(@EventStrut));
{the CallNextHookEX is not really needed for journal hook since it it not
really in a hook chain, but it's standard for a Hook}
if Code < 0
then Exit;
{you should cancel operation if you get HC_SYSMODALON}
if Code = HC_SYSMODALON
then Exit;
if Code = HC_ACTION
then
begin
{the EventStrut record has the Information about the mouse or keyboard
event. You said you just wanted the mouse button events so I get the
mouse down and mouse up event messages}
if EventStrut.
message = WM_LBUTTONUP
then
begin
if boolean(GetCursorPos(rPos))
then
begin
Form1.ShowHwndAndClassName(rPos);
hwnd := FindWindowEx(0, 0,
nil, PChar(form1.edit1.text));
//if (hwnd <> 0) then SetWindowPos(hwnd, 0, 0, 0, strtoint(Form1.edit2.text), strtoint(Form1.edit3.text),
if (hwnd <> 0)
then SetWindowPos(hwnd, 0, 0, 0, strtoint(Form1.edit2.text), strtoint(Form1.edit3.text),
SWP_SHOWWINDOW);
Track := False;
UnhookWindowsHookEx(JHook);
JHook := 0;
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Track
then
begin
ShowMessage('
Mouse is already being Journaled, can not restart');
Exit;
end;
JHook := SetWindowsHookEx(WH_JOURNALRECORD, @JournalProc, hInstance, 0);
{SetWindowsHookEx starts the Hook}
if JHook > 0
then
begin
Track := True;
end else
ShowMessage('
No Journal Hook availible');
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
UnhookWindowsHookEx(JHook);
end;
end.