We help IT Professionals succeed at work.

A brief understanding on how capturing windows messages work

afos21 asked
Medium Priority
Last Modified: 2013-11-20
My aim is to handle selected windows messages. I've been navigating through Internet and they are all very mixed up. I would be grateful if someone will link me a tutorial or help me understand how the procedure works since i'm completely lost.
Watch Question

You want to capture windows messages in your MFC application? You can handle messages to the current window you're conerned with. Look at the documentation for CWnd:


Most of the OnXXX() member functions are mapped message handlers. For instance:


will fire when the user left clicks in that window. Are you developing for MFC, or just plain win32? And what messages do you want to handle? If you give this information I can give specific examples for you.

Author of the Year 2009

... Or are you interested in capturing/monitoring window messages in *other applications* (other than the programs you write yourself).  The techniques are very different.


actually, my purpose is to write a mouse recorder application. I wasn't given any restrictions. I'm free to choose any programming language i want. They told me is much easier to do it with java but i choosed c++ because i'm more familiar with
Author of the Year 2009
You need to write what is called a Windows Hook.  In order to record mouse clicks and movement in an external APP, it must be a global hook  and it must reside in a DLL.

Here is a link to some source code that does waht you want

Here is one answer from another question at EE:
And here is an EE search to a bunch of related questions:

Here is the MSDN topic at Microsoft:

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.