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:
Code:
int CenterWindow(HWND hwnd, int width, int height)
{
NONCLIENTMETRICS ncm;
rect scrrect;
int ret = 0;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
ret = ::SystemParametersInfo(SPI_GETWORKAREA, 0, &scrrect,
SPIF_UPDATEINIFILE);
if(!ret)
return 0;
point center(scrrect.bx() / 2, scrrect.by() / 2);
point tl(center.x() - width / 2, center.y() - height / 2);
::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0);
ret = ::MoveWindow(hwnd, tl.x() - ncm.iBorderWidth, tl.y() -
ncm.iCaptionHeight, width + ncm.iBorderWidth,
height + ncm.iBorderWidth, TRUE);
return ret;
}
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?