Сообщение от .Squid
Если нужно отцентрировать окно, то сначала получаешь его размеры (у тебя уже есть).
Затем получаешь размер декстопа:
int dx = GetSystemMetrics(SM_CXSCREEN);
int dy = GetSystemMetrics(SM_CYSCREEN);
Центрируешь:
int x = (dx - width) >> 1;
int y = (dy - height) >> 1;
SetWindowPos(rWnd, HWND_TOP, x, y, width, height, SWP_SHOWWINDOW);
|
Окно получается не совсем по центру, т.к. не учитывается размер рамки.
Я центрирую так:
/* (width, height - размеры окна) */
/* Get Desktop size */
tagRECT rect;
GetClientRect( GetDesktopWindow(), &rect );
/* Calc position and size of the new window */
rect.left = (rect.right - width) >> 1;
rect.right = rect.left + width;
rect.top = (rect.bottom - height) >> 1;
rect.bottom = rect.top + height;
/* Adjust window size */
AdjustWindowRect(&rect, GetWindowLong(_vpWindow, GWL_STYLE), false);
SetWindowPos(_vpWindow, 0, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0);
Клиентская область получается ровно по центру.