ok, at the moment i am creating a mouse journal (hook) because i need my application to know where is the mouse, if the mouse move, if the user pressed left, right or whatever mouse button, etc.
see the question after all the code
this is the code for the journaling:
function JournalProc(Code, wParam: Integer; var EventStrut: TEventMsg): Integer; stdcall;
var
s: string;
begin
{this is the JournalRecordProc}
Result := CallNextHookEx(JHook, Code, wParam, Longint(@EventStrut));
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
s := '';
if EventStrut.message = WM_LBUTTONUP then
begin
if not form2.CheckBox1.Checked then //no stiky double-click
begin
doubleclick:=false;
form1.SpeedButton1.Down:=t
rue;
end;
end;
if EventStrut.message = WM_LBUTTONDOWN then
begin
form1.TILed1.Flash;
form1.TILed1.Caption:='L';
end;
if EventStrut.message = WM_RBUTTONDOWN then
begin
form1.TILed1.Flash;
form1.TILed1.Caption:='R';
end;
if (EventStrut.message = WM_RBUTTONUP) then
begin
if not form2.CheckBox1.Checked then //no stiky righ-click
begin
leftclick:=true;
form1.SpeedButton1.Down:=t
rue;
end;
end;
if (EventStrut.message = WM_MOUSEWHEEL) then
begin
//s := 'Mouse Wheel at X pos ' +
// IntToStr(EventStrut.paramL
) + ' and Y pos ' + IntToStr(EventStrut.paramH
);
end;
if (EventStrut.message = WM_MOUSEMOVE) then
begin
form1.MouseMoveReceived;
posx:=EventStrut.paramL;
posy:=EventStrut.paramH;
end;
if s <> '' then
begin
Form1.Label3.Caption:=s; //debug
end;
end;
end;
and i am starting the journaling with:
JHook := SetWindowsHookEx(WH_JOURNA
LRECORD, @JournalProc, hInstance, 0);
and stopping it with:
UnhookWindowsHookEx(JHook)
;
also, since the windows cancels the journal when the user presses ctrl-esc or ctrl-alt-del i am restarting it with:
procedure TForm1.ApplicationEvents1M
essage(var
Msg: tagMSG;
var Handled: Boolean);
begin
Handled := False;
if (Msg.message = WM_CANCELJOURNAL) and FHookStarted then
JHook := SetWindowsHookEx(WH_JOURNA
LRECORD, @JournalProc, hInstance, 0);
end;
now, here's the problem. while the hook is on i experience the following:
the start menu and any of the sub-menues there will flicker, as if someone if repetedly moving the mouse of the items and reopening them. also alt-tab will show the task change little form but it will disappear almost intantly.
all this might be related to the journal, or maybe to the rest of my code, that simple clicks the mouse by code when the user moves and stops the mouse somewhere on the screen. in any case, what's better a mouse journal or a full dll hook on the mouse in this case?
the case beeing the ability to know where the mouse is at any given time, to know whether the mouse is moving or not, whether it;s a left click, right click, double click or the mouse is till down (the user is dragging the form, etc).
if a full dll is better, i know the journaling could be problematic - hence this entire question, does anyone has simple example for a mouse hook thru a dll?
thanks and sorry for the poor english.