Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Catch mouse events

Posted on 1998-11-02
2
Medium Priority
?
229 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 100 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

971 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