Solved

Capture All Windows messages

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

26 Experts available now in Live!

Get 1:1 Help Now