You are here:

C++/absolute coordinate of mouse pointer ...


 hello sir,
 I want to write a program which tells me the (absolute) coordinate of where the mouse is clicked on(POINT data structure) or where the mouse is located. This coordinate can be outside the boundaries of my application's form.
 Microsoft visual studio 6 has a tool, called SPY++, which does a somehow similar task: it retrieves the handle of the window above which the mouse is moving.

 My probblem is that when the mouse is clicked somewhere I lose the focus in my application. What should I do to solve this problem(losing the focus OnClick)?

thank you very very much.  

mohammad, Thank you for your question.

Spy++ requires the user to drag an icon over windows to select them. It uses the 'SetCapture' function to do this. You can search Microsoft's MSDN Library for 'SetCapture' at While the mouse is 'captured', WM_MOUSEMOVE and other messages are sent to the application window specified in the call to 'SetCapture'.

David Spector


All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2017 All rights reserved.