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

x
?
Solved

Systemwide Mousehook

Posted on 1997-10-12
1
Medium Priority
?
415 Views
Last Modified: 2010-04-03
Hi!

I tried to install a systemwide mousehook with
SetWindowsHookEx(WH_MOUSE, MouseHookCallBack, HInstance, 0)
inside a DLL. According to any articles I read about hooking this usually installs a systemwide mousehook, but it does not!

I use the DLL from my application, both coded with Delphi3. Inside the DLL all mouseevents are filtered and if there is the right one, a WM_USER message is posted to my application to inform it of the event.
But this only recognizes mouseevents on the application's form and not on the desktop or somewhere else.

What's wrong?
Is there any other way than using a DLL and hook procedures?

I tried to subclass the desktop window, but it does not work (as I read later). I think I declared everything as it should be (export and stdcall).

I saw several applications that are obviously able to receive systemwide events, but I did not manage.

Thanks in advance,
Harro
0
Comment
Question by:tier
1 Comment
 
LVL 1

Accepted Solution

by:
olmy earned 300 total points
ID: 1347326
Hi Tier

This keyboard hook is systemwide. It calls another program, but that part you can change.

library hookdll;
uses
  SysUtils,
  Classes,
  Windows,
  Messages;
var
  MyHook: HHOOK;

function MyHookProc(code: Integer; wparam: WPARAM; lparam: LPARAM): LRESULT stdcall;
var
  h: HWND;
begin
  Result := CallNextHookEx(MyHook, code, wparam, lparam);
  if (code = HC_ACTION) and ((lparam and $80000000) = 0) then begin
    // this is a keypress - tell caller
    h := FindWindow(nil, 'HookCaller');
    if h <> 0 then
      PostMessage(h, WM_APP, 0, 0);
  end;
end;

procedure Hook;
begin
  MyHook:= SetWindowsHookEx(WH_KEYBOARD, MyHookProc, hInstance, 0);
end;

procedure UnHook;
begin
  UnhookWindowsHookEx(MyHook);
end;

exports
  Hook, UnHook;

begin
end.


I Hope this helps :)

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

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…
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…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

885 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