Valhalla Legends Forums Archive | C/C++ Programming | Getting the cursor position in a child window

AuthorMessageTime
laurion
The mouse coordinates within a child window are different than those of the screen. GetCursorPos returns the cursor position on the screen, which unfortunately isn't what I need. Is it possible to grab the mouse coordinates as determined by the child/parent target window? For example, when I use Spy++ to track WM_LBUTTONDOWN/UP events, they are 400,300 in the child window, but when using GetCursorPos, hovering over the same point returns 400,375. The coordinates I'm attempting to grab are not within the actual program (I do have hWnds of the child/parent target windows, though).
September 23, 2007, 5:13 PM
Barabajagal
Can't you use SendMessage WM_MOUSEMOVE to detect where the mouse is on a given window handle?
September 23, 2007, 10:15 PM
Myndfyr
Have you considered using the MapWindowPoints function?

[code]
MapWindowPoints(hwndChild, NULL, &pt, 1);
[/code]

Alternatively you can also use ClientToScreen.
September 23, 2007, 11:26 PM
laurion
[quote author=MyndFyre[vL] link=topic=17042.msg173149#msg173149 date=1190589960]
Have you considered using the MapWindowPoints function?

[code]
MapWindowPoints(hwndChild, NULL, &pt, 1);
[/code]

Alternatively you can also use ClientToScreen.
[/quote]
Thanks a lot Mynd  :)
Although you had what I wanted to do backwards, it still worked fine :P. Rather than MapWindowPoints(hwnd, NULL, &pt, 1);, I just did MapWindowPoints(NULL, hwnd, &pt, 1);. Using ScreenToClient worked fine, too.
September 24, 2007, 12:08 AM

Search