Solved

Catch mouse events

Posted on 1998-11-02
2
212 Views
Last Modified: 2010-04-03
I Hook a function that catch all mouse events in Windows.
This function give me lParam which points to MOUSEHOOKSTRUCT structure that contains X , Y mouse coordinates , etc.The problem occures when I make pointer to
this structure and I want to read the fields.It don't allow
me  to do it.I want to know is there any security methods
that denied me or the problem is mine.

0
Comment
Question by:jpenev1
2 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1345452
jpenev1,

here is code I've got from the web. I can't help you further if you don't give specific code. Maybe you can't, but then this example will help you further.

Can you elaborate more on how to use SetWindowsHookEx?  If possible,
>just enclosed a short piece of code.
      OK, take the following and compile it into a dll.
When you call the SetHook function in the dll it sets a global
mouse hook - any mouse messages go to this hook first. If it's a
mousedown on the desktop there's a beep; whether it was a
mousedown on the desktop or not the HookProc calls the next
hook. When you call the UnHookHook function it unhooks the hook.
      (I actually use the thing to pop up a menu when I
click on the desktop, if you're curious.)
      You wanted a keyboard hook - it took me a while to
figure out how the mouse hook should go a while ago (then
another little while cleaning it up some just now; the original
was my very first Delphi project, what you see here is much
nicer.) If you look at the code below together with the
documentation for SetWindowsHookEx and MouseProc you
should be able to get a global keyboard hook going, I think maybe.
      I just noticed that SetHook and UnHookHook are
functions that don't return anything in particular. So sue me.
(The idea is they'd return an error message or something.) The code:
library Hookdemo;uses  Beeper in 'BEEPER.PAS';exports       SetHook index 1,
       UnHookHook index 2,       HookProc index 3;begin   HookedAlready:=False;
end.{**************}unit Beeper;interfaceuses Wintypes,Winprocs,Messages;
function SetHook:Boolean;export;function UnHookHook:Boolean;export;
function HookProc(Code:integer; wParam: Word;       lParam: Longint): Longint;export;
var HookedAlready:Boolean;implementationvar   ourHook:HHook;   DeskTop:hwnd;
function SetHook:Boolean;begin if HookedAlready then exit;
DeskTop:=GetDeskTopWindow;
ourHook:=SetWindowsHookEx(WH_MOUSE,HookProc,HInstance,0);
{I have smart callbacks turned on or this wouldn't quite work}
HookedAlready:=True;end;function UnHookHook:Boolean;begin
UnHookWindowsHookEx(ourHook);HookedAlready:=False;end;
function HookProc(Code:integer; wParam: Word;             lParam: Longint): Longint;begin
   if (wParam=WM_LBUTTONDOWN) and       (PMouseHookStruct(lParam)^.hWnd=DeskTop)
     then MessageBeep(0);   result:=CallNextHookEx(ourHook,Code,wParam,lParam);
{If you want to eat a message instead you simply
leave out the CallNextHookEx part}end;end.
      And in fact for this particular application subclassing
the desktop window (SetWindowLong) would probably make
more sense than using SetWindowsHookEx. But if you want a
global hook you need a hook, not a subclass.
Author: David Ullrich


Zif.

0
 

Author Comment

by:jpenev1
ID: 1345453
your source didn't work, can you give me some working program on this E-mail:
fn41966@fs.fmi.uni-sofia.bg
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now