| Deep BlueVBScriptWMIPHPC语言JavaScriptWindows API路由器Windows函数Python | SDK编程中的窗口居中MFC程序中调用CWnd::CenterWindow就可以实现窗口居中,但是纯SDK编程中没有CenterWindow这个函数,需要自定义一个。Google到一个比较好的实现。
自定义函数一:
自定义函数二: void CentreWindow(HWND hwnd) { RECT winrect, workrect; int workwidth, workheight, winwidth, winheight; SystemParametersInfo(SPI_GETWORKAREA, 0, &workrect, 0); workwidth = workrect.right - workrect.left; workheight = workrect.bottom - workrect.top; GetWindowRect(hwnd, &winrect); winwidth = winrect.right - winrect.left; winheight = winrect.bottom - winrect.top; winwidth = min(winwidth, workwidth); winheight = min(winheight, workheight); SetWindowPos(hwnd, HWND_TOP, workrect.left + (workwidth-winwidth) / 2, workrect.top + (workheight-winheight) / 2, winwidth, winheight, SWP_SHOWWINDOW); SetForegroundWindow(hwnd); } 参考链接:自定义的窗口居中函数–CentreWindow |