Solved

Catch mouse events

Posted on 1998-11-02
2
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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