当前位置:网站首页>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 ); //编辑控件的大小和位置都改变以上方法也适用于各种窗口。
边栏推荐
- Manhattan distance and Manhattan rectangle - print back font matrix
- [web security] nodejs prototype chain pollution analysis
- Software test interview questions - Test Type
- win10无法操作(删除、剪切)文件
- Request forwarding and redirection
- [C language] qsort function
- Luogu p1460 [usaco2.1] healthy Holstein cows
- 技术分享 | 常见接口协议解析
- Win10 cannot operate (delete, cut) files
- G - Supermarket
猜你喜欢

全链路压测:构建三大模型

PAT(乙级)2022年夏季考试

The latest 2022 review of "graph classification research"

What are the test sites for tunnel engineering?

MySQL之基础知识

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

HCIA review

职场进阶指南:大厂人必看书籍推荐

【Postman】Monitors 监测API可定时周期运行

About PHP startup, mongodb cannot find the specified module
随机推荐
MPLS test report
PAT(乙级)2022年夏季考试
Clock in during winter vacation
VINS-Mono: A Robust and Versatile Monocular Visual-Inertial State Estimator
Understanding of processes and threads
JMeter做接口测试,如何提取登录Cookie
Idea new UI usage
properties文件
Company video accelerated playback
【Postman】Monitors 监测API可定时周期运行
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
The latest 2022 review of "graph classification research"
D - How Many Answers Are Wrong
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
Function of contenttype
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
Hypothesis testing learning notes
【Postman】动态变量(也称Mock函数)
单元测试的意义