长江大侠 发表于 2016-6-3 19:58:09

窗口中心位置的计算.

本帖最后由 长江大侠 于 2016-6-3 20:09 编辑

1. 子窗口在父窗口的中心位置.

LONG WindowCenter_About_X      = WINDOW_ABOUT_WIDTH/ 2;   // 子窗口的 宽度 / 2, 求得 窗口中心点 位置      X.
LONG WindowCenter_About_Y      = WINDOW_ABOUT_HEIGHT / 2;   // 子窗口的 高度 / 2, 求得 窗口中心点 位置      Y.
LONG WindowCenter_Main_X      = WINDOW_MAIN_WIDTH   / 2;    // 父窗口的 宽度 / 2, 求得 窗口中心点 位置      X.
LONG WindowCenter_Main_Y      = WINDOW_MAIN_HEIGHT/ 2;    // 父窗口的 高度 / 2, 求得 窗口中心点 位置      Y.
RECT rc;      GetWindowRect(XWnd_GetHWND(m_hMainWindow), &rc);
LONG CenterPointX      =      rc.left + (WindowCenter_Main_X - WindowCenter_About_X);// 计算结果 窗口在屏幕的中心点位置.
LONG CenterPointY      =      rc.top+ (WindowCenter_Main_Y - WindowCenter_About_Y);// 计算结果 窗口在屏幕的中心点位置.

int x = CenterPointX;
int y = CenterPointY;
SetWindowPos(XWnd_GetHWND(m_hAboutWindow), 0, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
XWnd_ShowWindow(m_hAboutWindow, SW_RESTORE);      
SetForegroundWindow(XWnd_GetHWND(m_hAboutWindow));

2. 父窗口在屏幕的中心位置.
LONG WindowCenterX=AppSizeWidth/ 2;      // 窗口句柄的 宽度X / 2, 求得 窗口中心点 位置      X
LONG WindowCenterY=AppSizeHeight / 2;      // 窗口句柄的 高度Y / 2, 求得 窗口中心点 位置      Y
LONG CenterPointX=ScreenCenterX - WindowCenterX;// 计算结果 窗口在屏幕的中心点位置
LONG CenterPointY=ScreenCenterY - WindowCenterY;// 计算结果 窗口在屏幕的中心点位置
int x = CenterPointX;
int y = CenterPointY;
SetWindowPos(XWnd_GetHWND(m_hAboutWindow), 0, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
XWnd_ShowWindow(m_hAboutWindow, SW_RESTORE);      
SetForegroundWindow(XWnd_GetHWND(m_hAboutWindow));

3. MFC.

直接使用API:   CWnd::CenterWindow










dasemimi 发表于 2016-6-3 20:27:21

支持楼主发原创帖子

来世倾城恋 发表于 2016-6-9 20:14:08

支持下哈哈!!!!!!!!!
页: [1]
查看完整版本: 窗口中心位置的计算.