Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get coordinates of window client area

Tags:

c#

winapi

I can get the coordinates of a windows entire area, and the coordinates of the client area using the GetClientRect and GetWindowRect Win32 calls. My problem is that the GetClientRect always returns 0,0 for the top left. How do I figure out what the actual client region is relative to the window rect?

like image 745
Jeremy Avatar asked Jul 13 '10 23:07

Jeremy


3 Answers

You can use ClientToScreen to get the coordinates of the upper left (0,0) point in screen coordinates. The RECT returned by GetClientRect will be appropriate to get you the lower right corner (just add to the POINT set by ClientToScreen).

like image 116
Reed Copsey Avatar answered Nov 17 '22 00:11

Reed Copsey


Use ClientToScreen to convert the client coordinates to screen coordinates. The window rect (GetWindowRect) is already in screen coordinates, and includes the non-client area (borders, caption, etc)

like image 30
dthorpe Avatar answered Nov 16 '22 23:11

dthorpe


And if you are working with WinForms then you can use PointToScreen instead of ClientToScreen for solution proposed by Reed Copsey.

like image 3
Stan Avatar answered Nov 16 '22 23:11

Stan