Solved

Catch mouse events

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

773 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