Solved

Catch mouse events

Posted on 1998-11-02
2
215 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 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

12 Experts available now in Live!

Get 1:1 Help Now