▲ 类向导->MFC类 创建两个子窗体。
1。创建两个子窗体。
2。属性设置:1)、“Style”选择“Child”;中文版“样式”选择“下层”。2)、“Border”为“None”;中文版“边框”选择“无”。
3。主窗体中实例子窗体对象:
声明:
private:
CSubForm1* m_CSubForm1;
CSubForm2* m_CSubForm2;
构造函数,析构函数:
CMFCApplication5SubFormSwitchDlg::CMFCApplication5SubFormSwitchDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_MFCAPPLICATION5SUBFORMSWITCH_DIALOG, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_CSubForm1 = new CSubForm1;
m_CSubForm2 = new CSubForm2;
}
CMFCApplication5SubFormSwitchDlg::~CMFCApplication5SubFormSwitchDlg()
{
delete m_CSubForm1;
delete m_CSubForm2;
}
4。初始化设定BOOL CMFCApplication5SubFormSwitchDlg::OnInitDialog()
函数中添加:
m_CSubForm1->Create(IDD_CSubForm1, this);
CRect re;
GetDlgItem(IDC_STATIC_ZOON)->GetWindowRect(&re);
ScreenToClient(re);
m_CSubForm1->MoveWindow(re);
m_CSubForm1->ShowWindow(SW_SHOW);
m_CSubForm2->Create(IDD_CSubForm2, this);
m_CSubForm2->MoveWindow(re);
m_CSubForm2->ShowWindow(SW_HIDE);
5。按钮切换
切换页面
按钮响应:
void CMFCApplication5SubFormSwitchDlg::OnBnClickedButtonswitch()
{
if (m_CSubForm1->IsWindowVisible()) {
m_CSubForm1->ShowWindow(SW_HIDE);
m_CSubForm2->ShowWindow(SW_SHOW);
}
else if (m_CSubForm2->IsWindowVisible()) {
m_CSubForm1->ShowWindow(SW_SHOW);
m_CSubForm2->ShowWindow(SW_HIDE);
}
}
▲ 点击 切换页面 按钮,相应区域会切换子页面显示
标签:控件,MFC,SW,CMFCApplication5SubFormSwitchDlg,窗体,CSubForm2,ShowWindow,CSubForm1
From: https://www.cnblogs.com/huvjie/p/17983980