Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client rectangle coordinates on screen

How can I get coordinates of a window's client area relative to screen?

I thought about using GetClientRect and ClientToScreen. Also, in a browser window what is ClientRect? Only rectangle with HTML document shown in it, or it includes browser bars and pop-up menus, that can possibly shrink dimension for HTML doc?

I've tried this:

HWND hWnd;
RECT rc;
if (GetClientRect(hWnd, &rc)) // get client coords 
{
    MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc), 2); // converts rect rc points
    return rc.top;
}

But the sad thing is that browser's client rectangle includes all those pop-up browser menus and bars, therefore can't be used to detect accurate coordinates of browsers HTML document space. If anyone got suggestions how it can be done, will try it gladly.

like image 364
Max Yari Avatar asked Mar 31 '13 21:03

Max Yari


1 Answers

Yes, you can do this with the ClientToScreen function:

RECT rc;
GetClientRect(hWnd, &rc); // get client coords
ClientToScreen(hWnd, reinterpret_cast<POINT*>(&rc.left)); // convert top-left
ClientToScreen(hWnd, reinterpret_cast<POINT*>(&rc.right)); // convert bottom-right

What is the "client" rectangle in a browser depends on the browser implementation. You can use Spy++ to discover this for yourself.

like image 148
Jonathan Potter Avatar answered Nov 09 '22 05:11

Jonathan Potter