Client rectangle coordinates on screen

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.


To translate a window's client rectangle to screen coordinates, call the MapWindowPoints function. It implements special handling to always return a valid RECT, even when used in scenarios that involve windows with right-to-left layout:

If hWndFrom or hWndTo (or both) are mirrored windows (that is, have WS_EX_LAYOUTRTL extended style) and precisely two points are passed in lpPoints, MapWindowPoints will interpret those two points as a RECT and possibly automatically swap the left and right fields of that rectangle to ensure that left is not greater than right.

Calling ClientToScreen on both points in contrast fails to account for RTL layouts, and can produce an invalid RECT. It fails to adhere to one of the rectangle coordinate invariants:

The coordinate value of a rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.

A reliable function to return a window's client rectangle in screen coordinates would look like this:

RECT client_rect_in_screen_space(HWND const hWnd) {
    RECT rc{ 0 };
    if (!::GetClientRect(hWnd, &rc)) {
        auto const err_val{ ::GetLastError() };
        throw std::system_error(err_val, std::system_category());
    }

    ::SetLastError(ERROR_SUCCESS);
    if(::MapWindowPoints(hWnd, nullptr, reinterpret_cast<POINT*>(&rc), 2) == 0) {
        auto const err_val{ ::GetLastError() };
        if (err_val != ERROR_SUCCESS) {
            throw std::system_error(err_val, std::system_category());
        }
    }

    return rc;
}

The question update asks for a different, unrelated issue. There is no API built into the system, that allows you to query a web browser's display area for its HTML content. The most promising solution would be to employ UI Automation. The question, however, is too broad to provide a more detailed answer here.