Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a process window size without borders

Tags:

c#

winapi

Using the WinApi GetWindowRect() it returns the complete window size, but I would like to get the size without the borders and the title bar, something like the red square:

enter image description here

There is any functions to do that?

Thanks

like image 467
Kyore Avatar asked Sep 16 '25 05:09

Kyore


2 Answers

The Windows API function you are looking for is GetClientRect. If you subsequently need to convert these coordinates into screen relative coordinates, call ClientToScreen.

like image 80
David Heffernan Avatar answered Sep 19 '25 11:09

David Heffernan


This works:

RECT getInnerWindowScreenRectangle(HWND window) {
    RECT client;
    RECT output;
    // client coordinates are (0, 0) in the top left corner
    // of the window inside the border.
    GetClientRect(window, &client);
    POINT point;
    point.x = 0;
    point.y = 0;
    // screen coordinates are virtual screen coordinates with (0, 0)
    // in the top left corner of the primary display.
    ClientToScreen(window, &point);
    output.left = point.x;
    output.top = point.y;
    output.right = point.x + client.right;
    output.bottom = point.y + client.bottom;
    return output;
}
like image 21
Anthony V Avatar answered Sep 19 '25 11:09

Anthony V