How can I use a CGXTabWnd in a static splitter window.
Here are the steps necessary for doing this:
You should create a static splitter window class with ClassWizard, e.g. CScrltabsSplitMDIChildWnd
Next, you should call CreateStatic( ) in OnCreateClient( ) and create the windows (see the following sample code)
Finally, you should override PostNcDestroy() and delete the CGXTabWnd windows.
When you create the windows, you can create a tab window and embed the worksheets into it. The following example shows you how display a static splitter window with two panes. The panes are CGXTabWnd, each having several worksheets.
Example:
class CScrltabsSplitMDIChildWnd : public CMDIChildWnd
{
DECLARE_DYNCREATE(CScrltabsSplitMDIChildWnd)
protected:
// protected constructor used by dynamic creation
CScrltabsSplitMDIChildWnd( );
// Attributes
public:
CSplitterWnd m_wndSplitter;
CGXTabWnd* m_pTabWnd1;
CGXTabWnd* m_pTabWnd2;
// Operations
public:
BOOL OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext);
virtual void PostNcDestroy();
// Implementation
protected:
virtual ~CScrltabsSplitMDIChildWnd( );
// Generated message map functions
//{{AFX_MSG(CScrltabsSplitMDIChildWnd)
//}}AFX_MSG
DECLARE_MESSAGE_MAP( )
};
BOOL CScrltabsSplitMDIChildWnd::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
CScrltabsApp* pApp = (CScrltabsApp*) AfxGetApp( );
// specify the runtime class for the first sheet
// don't forget to register the document
// template in InitInstance!
pContext->m_pNewViewClass = RUNTIME_CLASS(CScrltabsFormView);
m_wndSplitter.CreateStatic(this, 2, 1);
// creates the tabwnd object
if (!m_wndSplitter.CreateView(0, 0,
RUNTIME_CLASS(CGXTabWnd), CSize(0, (lpcs->cy / 2)
), // SPLIT_BORDERS),
pContext))
{
TRACE("Failed to create third pane\n");
return FALSE;
}
m_pTabWnd1 = (CGXTabWnd*) m_wndSplitter.GetPane(0, 0);
// creates the View2 worksheet in the tab window
VERIFY(m_pTabWnd1->Create(this, "View 1", pContext));
m_pTabWnd1->CreateView(RUNTIME_CLASS(CScrltabsView),
"View 2", pContext);
// creates the tabwnd object
if (!m_wndSplitter.CreateView(1, 0,
RUNTIME_CLASS(CGXTabWnd), CSize(0, (lpcs->cy / 2)
), // SPLIT_BORDERS),
pContext))
{
TRACE("Failed to create third pane\n");
return FALSE;
}
m_pTabWnd2 = (CGXTabWnd*) m_wndSplitter.GetPane(1, 0);
// creates the View1, View2 and View 3 worksheets in
// the tab window
VERIFY(m_pTabWnd2->Create(this, "View 1", pContext));
m_pTabWnd2->CreateView(RUNTIME_CLASS(CScrltabsView),
"View 2", pContext);
m_pTabWnd2->CreateView(RUNTIME_CLASS(CScrltabsView),
"View 3", pContext);
return TRUE;
}
void CScrltabsSplitMDIChildWnd::PostNcDestroy()
{
// tab windows must be deleted here
delete m_pTabWnd1;
m_pTabWnd1 = NULL;
delete m_pTabWnd2;
m_pTabWnd2 = NULL;
CMDIChildWnd::PostNcDestroy();
}