炫彩界面库论坛

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 5305|回复: 2

[开源教程] 窗口中心位置的计算.

[复制链接]

该用户从未签到

发表于 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










评分

参与人数 1炫彩币 +6 收起 理由
dasemimi + 6 解决了我的问题

查看全部评分

该用户从未签到

发表于 2016-6-3 20:27:21 | 显示全部楼层
支持楼主发原创帖子

该用户从未签到

发表于 2016-6-9 20:14:08 | 显示全部楼层
支持下哈哈!!!!!!!!!
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

QQ|Archiver|手机版|小黑屋|炫彩界面库 ( 鄂ICP备2023014763号-1 )

GMT+8, 2024-5-2 06:05 , Processed in 0.065045 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表