CBCGPTabWnd 添加CDialog页面 完整代码
时间: 2023-08-07 21:03:41 浏览: 51
以下是 CBCGPTabWnd 添加 CDialog 页面的完整代码示例:
首先,在您的对话框类中添加以下代码:
```cpp
BOOL CMyDialog::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
{
if (!CBCGPDockingControlBar::Create(lpszTemplateName, pParentWnd, AFX_WS_DEFAULT_VIEW,
CBCGPTabbedControlBar::CBRS_BCGP_REGULAR_TABS, CRect(0, 0, 0, 0), AFX_IDW_PANE_FIRST))
{
return FALSE;
}
EnableDocking(CBRS_ALIGN_ANY);
return TRUE;
}
```
然后,您需要在您的 CBCGPTabWnd 派生类中添加以下代码:
```cpp
BOOL CMyTabWnd::AddTab(CRuntimeClass* pClass, LPCTSTR lpszTabLabel)
{
CDialog* pDlg = (CDialog*)pClass->CreateObject();
if (!pDlg)
{
return FALSE;
}
if (!pDlg->Create(pClass->m_lpszClassName, this))
{
delete pDlg;
return FALSE;
}
CBCGPTabInfo tabInfo(pDlg->GetSafeHwnd(), lpszTabLabel, 0, this, (DWORD_PTR)pDlg);
AddTab(tabInfo);
return TRUE;
}
```
现在,您可以在您的 CBCGPTabWnd 派生类中调用 AddTab 方法来添加 CDialog 页面。例如:
```cpp
AddTab(RUNTIME_CLASS(CMyDialog), _T("My Dialog"));
```
这将在您的 CBCGPTabWnd 控件中添加一个名为 "My Dialog" 的新选项卡,其中包含一个 CMyDialog 对话框。