当前位置:网站首页>MFC dynamically creates dialog boxes and changes the size and position of controls
MFC dynamically creates dialog boxes and changes the size and position of controls
2022-07-06 06:18:00 【Laobai 436196571】
1、 Dynamically create dialog
void CXXX_DEMODlg::OnBnClickedBtntest()
{
if(dlg_num==0)// Open only once
{
DLG_TEST *pDlg=new DLG_TEST;
pDlg->Create(IDD_DLG_TEST, this);// Always at the top
//pDlg->Create(IDD_DLG_TEST, GetDesktopWindow());
pDlg->ShowWindow(SW_SHOW);
dlg_num+=1;
}
}
2、 Delete pointer in WM_NCDESTROY in delete this
void DLG_TEST::OnBnClickedCancel()
{
// TODO: Add control notification handler code here
dlg_num-=1;
OnCancel();
}
void DLG_TEST::OnNcDestroy()
{
CDialog::OnNcDestroy();
// TODO: Add message handler code here
delete this;
}
Reference resources :
MFC Click button , Another dialog box pops up
CWnd Class MoveWindow() or SetWindowPos() You can change the size and position of the control .
void MoveWindow(int x,int y,int nWidth,int nHeight);
void MoveWindow(LPCRECT lpRect);
The first usage needs to give the new coordinates and width of the control 、 Height ;
The second usage gives the storage location CRect object ;
example :
CWnd *pWnd;pWnd = GetDlgItem( IDC_EDIT1 ); // Get control pointer ,IDC_EDIT1 For control ID Number
pWnd->MoveWindow( CRect(0,0,100,100) ); // Display a width in the upper left corner of the window 100、 high 100 Edit control for
SetWindowPos() Functions are more flexible , It is mostly used when only the position of the control is modified and the size remains unchanged, or when only the size is modified and the position remains unchanged :
BOOL SetWindowPos(const CWnd* pWndInsertAfter,int x,int y,int cx,int cy,UINT nFlags);
I can't use the first parameter , General set to NULL;
x、y Control location ;cx、cy Control width and height ;
nFlags Common values :
SWP_NOZORDER: Ignore the first parameter :
SWP_NOMOVE: Ignore x、y, Keep the position unchanged ;
SWP_NOSIZE: Ignore cx、cy, Keep the size unchanged ;
example :
CWnd *pWnd;pWnd = GetDlgItem( IDC_BUTTON1 ); // Get control pointer ,IDC_BUTTON1 For control ID Number
pWnd->SetWindowPos( NULL,50,80,0,0,SWP_NOZORDER | SWP_NOSIZE ); // Move the button to the window (50,80) It's about
pWnd = GetDlgItem( IDC_EDIT1 );
pWnd->SetWindowPos( NULL,0,0,100,80,SWP_NOZORDER | SWP_NOMOVE ); // Set the size of the edit control to (100,80), Position the same
pWnd = GetDlgItem( IDC_EDIT1 );
pWnd->SetWindowPos( NULL,0,0,100,80,SWP_NOZORDER ); // The size and position of the editing control are changed. The above method is also applicable to all kinds of windows .
边栏推荐
- JDBC Requset 对应内容及功能介绍
- 模拟卷Leetcode【普通】1218. 最长定差子序列
- LeetCode 729. 我的日程安排表 I
- Hypothesis testing learning notes
- 一文揭开,测试外包公司的真 相
- [API interface tool] Introduction to postman interface
- keil MDK中删除添加到watch1中的变量
- 模拟卷Leetcode【普通】1314. 矩阵区域和
- Simulation volume leetcode [general] 1061 Arrange the smallest equivalent strings in dictionary order
- 【Postman】测试(Tests)脚本编写和断言详解
猜你喜欢
随机推荐
Career advancement Guide: recommended books for people in big factories
Is the test cycle compressed? Teach you 9 ways to deal with it
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
模拟卷Leetcode【普通】1249. 移除无效的括号
【C语言】字符串左旋
Basic knowledge of error
Simulation volume leetcode [general] 1091 The shortest path in binary matrix
【eolink】PC客户端安装
LeetCode 739. 每日温度
全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
The latest 2022 review of "graph classification research"
模拟卷Leetcode【普通】1143. 最长公共子序列
联合索引的左匹配原则
[postman] dynamic variable (also known as mock function)
10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
Leaflet map
Win10 cannot operate (delete, cut) files
进程和线程的理解
[C language] qsort function