设置窗口居中的两种方法

来源:互联网 发布:软件安全漏洞检测技术 编辑:程序博客网 时间:2024/05/21 17:20

本文由 @lonelyrains 出品,转载请注明出处。 
文章链接: http://blog.csdn.net/lonelyrains/article/details/10469933


第一种方法
void CenterWindowOnScreen(HWND hWnd){RECTrect;intxLeft,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());
原创粉丝点击