RECT rc, rc1, rctomove;
int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);
rc.left = 0;
rc.top = 0;
rc.right = width;
rc.bottom = height;
GetClientRect(窗口句柄, &rc1);
rctomove.left = (rc.right - rc.left) / 2 - (rc1.right - rc1.left) / 2;
rctomove.right = (rc.right - rc.left) / 2 + (rc1.right - rc1.left) / 2;
rctomove.top = (rc.bottom - rc.top) / 2 - (rc1.bottom - rc1.top) / 2;
rctomove.bottom = (rc.bottom - rc.top) / 2 + (rc1.bottom - rc1.top) / 2;
::SetWindowPos(窗口句柄, HWND_TOPMOST, rctomove.left, rctomove.top, rc1.right - rc1.left, rc1.bottom - rc1.top, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
本文介绍了一种在Windows平台上使应用程序窗口自动居中显示的方法。通过获取屏幕尺寸和窗口尺寸,计算窗口移动的位置,最终使用SetWindowPos函数完成窗口的居中设置。此方法适用于需要快速实现窗口居中功能的应用程序。
117

被折叠的 条评论
为什么被折叠?



