|窗口移动子窗口也跟着移动|

本文详细介绍了如何在C++应用中实现父窗口移动时,子窗口也随之移动的功能,通过初始化子对话框属性和在窗口移动事件中调整子窗口位置来确保子窗口始终保持在父窗口的相对位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

------------------------------------------------------------------------------------------
|父窗口移动子窗口也跟着移动|
------------------------------------------------------------------------------------------
//设置子对话框属性
Border    Dialog Frame
Style Popup
Title Bar
.h文件中。。。。
CInternalTipDlg *internaltip;


.CPP
 
void CCheckBillingRecordsCurrentInputDlg::OnBnClickedBtnInsidepointCi()
{
// 弹出内部提示对话框
if(internaltip  == NULL){//这句是防止非模式对话框弹出多个,但是一定要在构造函数中初始化(internaltip   == NULL;
internaltip = new CInternalTipDlg;
CRect rs;
GetDlgItem(IDC_BTN_INSIDEPOINT_CI)->GetWindowRect(rs);//ID是子窗口
internaltip->Create(IDD_DIALOG_INTERNALTIP_IT,this);
internaltip->ShowWindow(TRUE);
internaltip->SetWindowPos(&wndTopMost ,(rs.left-50 + rs.right)/2,rs.bottom ,0,0,SWP_NOSIZE);//设置移动位置,第一个参数说明显示最前
internaltip->UpdateWindow();//显示更新
}
}


//这个是WM_MOVE
void CCheckBillingRecordsCurrentInputDlg::OnMove(int x, int y)
{
CDialog::OnMove(x, y);
//你窗口移动时,子窗口跟着移动
::SetWindowPos(internaltip->GetSafeHwnd(),NULL,x + 600,y + 60,0,0,SWP_NOSIZE);


}
后语:一定要在CCheckBillingRecordsCurrentInputDlg类中初始化构造函数时初始化
internaltip = NULL;
形式如下
CReplacementOrderDlg::CReplacementOrderDlg(CWnd* pParent /*=NULL*/)
: CDialog(CReplacementOrderDlg::IDD, pParent)
{
internaltipone = NULL;
}
------------------------------------------------------------------------------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值