本文由 @lonelyrains 出品,转载请注明出处。
文章链接: http://blog.csdn.net/lonelyrains/article/details/10469933
void CenterWindowOnScreen(HWND hWnd) { RECT rect; int xLeft,yTop; GetWindowRect(hWnd,&rect); xLeft = (GetSystemMetrics(SM_CXFULLSCREEN)-(rect.right-rect.left))/2; yTop = (GetSystemMetrics(SM_CYFULLSCREEN)-(rect.bottom-rect.top))/2; // Move the window to the correct coordinates with SetWindowPos() //bResult = SetWindowPos(hWnd,HWND_TOP,xLeft,yTop,-1,-1,SWP_NOSIZE|SWP_NOZORDER/*|SWP_NOACTIVATE*/); SetWindowPos(hWnd, HWND_TOPMOST, xLeft,yTop,-1,-1, SWP_NOSIZE | SWP_NOZORDER); SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); }第二种方法
CenterWindow(GetDesktopWindow());