Width of window border
Trying to get the width of a window border to accurately make a window's client area centered on the screen. Stumbled upon SystemParametersInfo + SPI_GETNONCLIENTMETRICS / SPI_GETBORDER. In both cases, it returns to me that the border is only one pixel. Which I have a hard time believing. I use this code:
I call it with the width and height being the dimensions of the client area that I want. When the function is done, I call GetClientRect, and the bottom and right members of the RECT structure end up being 493 and 567. Is there another way I should be retrieving this sort of info? Is the computer LYING?
int CenterWindow(HWND hwnd, int width, int height)
int ret = 0;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
ret = ::SystemParametersInfo(SPI_GETWORKAREA, 0, &scrrect,
point center(scrrect.bx() / 2, scrrect.by() / 2);
point tl(center.x() - width / 2, center.y() - height / 2);
sizeof(NONCLIENTMETRICS), &ncm, 0);
ret = ::MoveWindow(hwnd, tl.x() - ncm.iBorderWidth, tl.y() -
ncm.iCaptionHeight, width + ncm.iBorderWidth,
height + ncm.iBorderWidth, TRUE);
Why not use the WS_CENTER style?
Or use the difference between GetWindowRect() and GetClientRect() to find the non client area?
ScreenToClient() may also help.
I am not sure about what you are asking but
Might help ???
Also, have a look at the AdjustWindowRect function.