当前位置:网站首页>MFC 动态创建的对话框及改变控件的大小和位置
MFC 动态创建的对话框及改变控件的大小和位置
2022-07-06 06:09:00 【老白436196571】
1、动态创建对话框
void CXXX_DEMODlg::OnBnClickedBtntest()
{
if(dlg_num==0)//只打开一次
{
DLG_TEST *pDlg=new DLG_TEST;
pDlg->Create(IDD_DLG_TEST, this);//一直置顶
//pDlg->Create(IDD_DLG_TEST, GetDesktopWindow());
pDlg->ShowWindow(SW_SHOW);
dlg_num+=1;
}
}
2、删除指针在WM_NCDESTROY里进行delete this
void DLG_TEST::OnBnClickedCancel()
{
// TODO: 在此添加控件通知处理程序代码
dlg_num-=1;
OnCancel();
}
void DLG_TEST::OnNcDestroy()
{
CDialog::OnNcDestroy();
// TODO: 在此处添加消息处理程序代码
delete this;
}
CWnd类的函数MoveWindow()或SetWindowPos()可以改变控件的大小和位置。
void MoveWindow(int x,int y,int nWidth,int nHeight);
void MoveWindow(LPCRECT lpRect);
第一种用法需给出控件新的坐标和宽度、高度;
第二种用法给出存放位置的CRect对象;
例:
CWnd *pWnd;pWnd = GetDlgItem( IDC_EDIT1 ); //获取控件指针,IDC_EDIT1为控件ID号
pWnd->MoveWindow( CRect(0,0,100,100) ); //在窗口左上角显示一个宽100、高100的编辑控件
SetWindowPos()函数使用更灵活,多用于只修改控件位置而大小不变或只修改大小而位置不变的情况:
BOOL SetWindowPos(const CWnd* pWndInsertAfter,int x,int y,int cx,int cy,UINT nFlags);
第一个参数我不会用,一般设为NULL;
x、y控件位置;cx、cy控件宽度和高度;
nFlags常用取值:
SWP_NOZORDER:忽略第一个参数:
SWP_NOMOVE:忽略x、y,维持位置不变;
SWP_NOSIZE:忽略cx、cy,维持大小不变;
例:
CWnd *pWnd;pWnd = GetDlgItem( IDC_BUTTON1 ); //获取控件指针,IDC_BUTTON1为控件ID号
pWnd->SetWindowPos( NULL,50,80,0,0,SWP_NOZORDER | SWP_NOSIZE ); //把按钮移到窗口的(50,80)处
pWnd = GetDlgItem( IDC_EDIT1 );
pWnd->SetWindowPos( NULL,0,0,100,80,SWP_NOZORDER | SWP_NOMOVE ); //把编辑控件的大小设为(100,80),位置不变
pWnd = GetDlgItem( IDC_EDIT1 );
pWnd->SetWindowPos( NULL,0,0,100,80,SWP_NOZORDER ); //编辑控件的大小和位置都改变以上方法也适用于各种窗口。
边栏推荐
- MySQL之数据类型
- Application du Groupe Li dans gtsam
- Digital triangle model acwing 1015 Picking flowers
- 【无App Push 通用测试方案
- 职场进阶指南:大厂人必看书籍推荐
- [leetcode] day96 - the first unique character & ransom letter & letter ectopic word
- The latest 2022 review of "graph classification research"
- 通过修改style设置打印页样式
- 《卓有成效的管理者》读书笔记
- Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
猜你喜欢
随机推荐
全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
Understanding of processes and threads
[untitled]
Fault, error, failure of functional safety
数据库隔离级别
Hypothesis testing learning notes
【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
Application of Lie group in gtsam
D - How Many Answers Are Wrong
Software test interview questions - Test Type
Web界面元素的测试
LeetCode 731. 我的日程安排表 II
Leaflet map
MPLS test report
Online and offline problems
Application du Groupe Li dans gtsam
(中)苹果有开源,但又怎样呢?
使用Nacos管理配置
Postman核心功能解析-参数化和测试报告