You are here:

C++/HWND of where the mouse is clicked on ...

Advertisement


Question
 hello sir,
 I want to write a program which is capable of giving me the handle(HWND) of where the mouse is clicked on; for example when I click on the edit box of the RUN menu in windows(Start->run) it should give me the handle of the edit box.

thank you very very much.  

Answer
mohammad , Thank you for your question.

It is not usually necessary to give a process information about mouse clicks in windows owned by other processes. For this reason, Windows does not make this easy to do. Please think about whether this is really what you want to do. Usually you just need to detect mouse clicks in windows owned by your application.

If you still want to do this, first consider whether capturing the mouse is what you want. The mouse can only be captured while the user keeps the mouse button down.

If you still want to do this, use a Mouse hook. Windows hooks are described in the MSDN Library. You can search Microsoft's MSDN Library at http://search.microsoft.com/us/dev/default.asp. Note that your mouse hook code will be executed in the context of another process, therefore you must write the code to be process-independent. Otherwise, you can easily crash the system.

David Spector

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


David Spector

Expertise

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.

Experience

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.

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

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

©2016 About.com. All rights reserved.