You are here:

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


 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.  

Did you try the MSDN library? If so did you try a query like “HWND near point”? I tried this using the local viewer application for the CD/DVD July 2004 edition and the forth item – as I dimly remembered - was the Win32 GDI API function WindowFromPoint.

If you do not have your own copy of the MSDN library then you can find it online at - however the search feature may be a bit different.

Get used to me – and probably others - referring you to the MSDN library – it is _the_ primary source of Microsoft development information and should be your first port of call for this sort of query. As it is freely available online – and you obviously can get online - I see no reason why you cannot make your own queries into this information resource. If you are using a MS development product then you may even have a copy supplied as the computer based help and documentation (since VC 6 I think). Take the time to learn how to find information in this source of information.

WindowFromPoint is a very simple function – you pass it a Win32 POINT structure instance and it returns the HWND of the window that contains that point.

You might also like to look at ChildWindowFromPoint, ChildWindowFromPointEx and RealChildWindowFromPoint.

Although the documentation does not specify I would guess that WindowFromPoint takes a POINT in screen coordinates and not client coordinates (ChildWindowFromPoint _does_ take a POINT in the client coordinates of the parent window specified by the additional parent HWND parameter). If you do not know the difference between screen and client coordinates then I suggest you read up on the difference in your favourite MS Windows programming text or read the relevant articles in the MSDN library.

You can extract the x and y coordinate value from a raw windows mouse message (i.e. a MSG struct) such as WM_LBUTTONDBLCLK by using the GET_X_LPARAM and GET_Y_LPARAM macros – passing the message lParam member to each.

Note that you can use the MAKEPOINTS macro to convert point data contained in the lParam member of a MSG to Win32 POINTS structs. This is _not_ the same as a POINT struct – a POINTS struct hold x and y values in message order as short integer values. POINT holds x and y values in x, y order as long integer values.  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2017 All rights reserved.