2

I started a new Windows Desktop C++ project in Visual Studio. The window creation looks like this:

HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

Immediately I check the size of the window and client rects, and get the difference between them:

RECT windowRect;
RECT clientRect;

GetWindowRect(hWnd, &windowRect);
GetClientRect(hWnd, &clientRect);

int xExtra = windowRect.right - windowRect.left - clientRect.right;

xExtra is 16 (26 if my process is per monitor DPI aware).

What is accounting for this difference? The client area appears to be the same width as the window!

(It seems like the border may account for a few pixels, but not 26!)

What am I overlooking?

enter image description here

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
TheNextman
  • 12,428
  • 2
  • 36
  • 75
  • 4
    The left & right borders are each 8 pixels. This is part of the non-client area, like the titlebar. In Windows 10 the borders on left/right/bottom are transparent, with some shadow effect. But if you move the mouse over you see the mouse changes for a resizable window (actually 7 of those 8 pixels are transparent with some shadow effect, plus 1 visible line) – Barmak Shemirani Jun 07 '18 at 19:16
  • It [gets 'em every time](https://stackoverflow.com/questions/50724768/createwindowex-invalid-x-position-once-created), eh @Barmak? – Paul Sanders Jun 08 '18 at 08:08
  • see also https://stackoverflow.com/a/34143777/4603670 – Barmak Shemirani Jun 11 '18 at 00:33

0 Answers0