当前位置:网站首页>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 ); //编辑控件的大小和位置都改变以上方法也适用于各种窗口。
边栏推荐
- SQLMAP使用教程(三)实战技巧二
- Accélération de la lecture vidéo de l'entreprise
- Nodejs realizes the third-party login of Weibo
- 【eolink】PC客户端安装
- [C language] qsort function
- F - True Liars (种类并查集+DP)
- Configuring OSPF GR features for Huawei devices
- Seven imperceptible truths in software testing
- Eigen sparse matrix operation
- 【Postman】动态变量(也称Mock函数)
猜你喜欢
![[postman] the monitors monitoring API can run periodically](/img/9e/3f6150290b868fc1160b6b01d0857e.png)
[postman] the monitors monitoring API can run periodically

数据库-当前读与快照读

GTSAM中李群的運用

B - The Suspects

LeetCode 732. 我的日程安排表 III

The latest 2022 review of "graph classification research"

How to use the container reflection method encapsulated by thinkphp5.1 in business code

F - True Liars (种类并查集+DP)

G - Supermarket

E - 食物链
随机推荐
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
公司視頻加速播放
Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
IP day 16 VLAN MPLS configuration
Buuctf-[gxyctf2019] no dolls (xiaoyute detailed explanation)
多线程应用的测试与调试
Testing and debugging of multithreaded applications
自定义指定路由上的Gateway过滤器工厂
ESP32 ESP-IDF看门狗TWDT
PAT(乙级)2022年夏季考试
【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
Overview of three core areas of Mathematics: algebra
JWT-JSON WEB TOKEN
B - The Suspects
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
How to use the container reflection method encapsulated by thinkphp5.1 in business code
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
Function of activation function
Eigen稀疏矩阵操作
【C语言】字符串左旋