当前位置:网站首页>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 .
边栏推荐
- 【C语言】字符串左旋
- ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
- 黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
- 对数据安全的思考(转载)
- G - Supermarket
- Isam2 and incrementalfixedlagsmooth instructions in gtsam
- On weak network test of special test
- Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
- F - true liars (category and search set +dp)
- Aike AI frontier promotion (2.13)
猜你喜欢
[postman] collections configuration running process
Application du Groupe Li dans gtsam
How to extract login cookies when JMeter performs interface testing
[wechat applet] build a development tool environment
[C language] string left rotation
Buuctf-[bjdctf2020]zjctf, but so (xiaoyute detailed explanation)
浅谈专项测试之弱网络测试
Nodejs realizes the third-party login of Weibo
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
[postman] collections - run the imported data file of the configuration
随机推荐
2022 software testing workflow to know
[postman] collections configuration running process
Simulation volume leetcode [general] 1314 Matrix area and
win10无法操作(删除、剪切)文件
【Postman】测试(Tests)脚本编写和断言详解
模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
E - 食物链
MFC 动态创建的对话框及改变控件的大小和位置
Qt:无法定位程序输入点XXXXX于动态链接库。
Selenium source code read through · 9 | desiredcapabilities class analysis
B - The Suspects
Interface test: what are the components of the URL in fiddler
曼哈顿距离和-打印菱形
Testing and debugging of multithreaded applications
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
测试周期被压缩?教你9个方法去应对
Hypothesis testing learning notes
Simulation volume leetcode [general] 1249 Remove invalid parentheses
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
Pat (Grade B) 2022 summer exam