Solved

Capture All Windows messages

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

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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