Solved

Capture All Windows messages

Posted on 1998-10-28
4
838 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 30 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to fill array with TArray.Create? 14 87
Dev Express grid collapse 2 44
Dev express lookupcombo 3 26
enhance the following code 3 29
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…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now