[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Capture All Windows messages

Posted on 1998-10-28
4
Medium Priority
?
963 Views
Last Modified: 2010-04-03
How can I catch all Windows messages?
For example , my active window is Microsoft Word
and when I click on it I want to catch this message
with my DELPHI program, which is not active in this moment.
0
Comment
Question by:jpenev1
  • 2
4 Comments
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344712
jpenev1

you can use the SetWindowsHook and SetWindowsHookEx to trap the messages, check the win32.hlp file....

Later
BoRiS
0
 
LVL 5

Accepted Solution

by:
ronit051397 earned 120 total points
ID: 1344713
You should use Hooking.
Download this example on hooking keyboard messages, and try to conclude from this on all messages:     ftp://delphiexchange.com/pub/offers/keyhook.zip

0
 
LVL 1

Expert Comment

by:AndersWP
ID: 1344714
You could do this with the SetWindowsHookEx API function. SetWindowsHookEx takes 4 parameters:
idHook: Should be set to WH_CALLWNDPROC
hkprc: Address of function to be called when a message is caught (callback function).
hMod: This should be set to the value of the hInstance variable of your Delphi Application
dwThreadID: ID of the thread you want to hook messages for. Setting this to 0 lets you hook ALL messages.
The function returns a hook handle that you will need when you remove the hook with the
UnhookWindowsHookEx function.

The callback function should be declared like this:

Function MyCallbackFunc(nCode: Integer; wParam, lParam: DWord): Integer;

Remember in your callback function to:
a: return 0 as the function result
b: Call CallNextHookEx to give other hooks a chance to look at the message.

I hope this will help you,
AndersWP
0
 
LVL 1

Expert Comment

by:AndersWP
ID: 1344715
I forgot to say that your callback function must be declared with the StdCall directive, and that it must be a global function (not an object method, not a local function declared within another function).

AndersWP
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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…
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.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 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