Objective Grid: Using a CGXTabWnd in a static splitter window

Problem


How can I use a CGXTabWnd in a static splitter window?
 


Cause



Action


Here are the steps necessary for doing this:

  1. Create a static splitter window class with ClassWizard, e.g. CScrltabsSplitMDIChildWnd
  2. Next, call CreateStatic( ) in OnCreateClient( ) and create the windows (see the following sample code)
  3. Finally, 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 to 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( );
public:
// Attributes
CSplitterWnd m_wndSplitter;
CGXTabWnd* m_pTabWnd1;
CGXTabWnd* m_pTabWnd2;

// Operations
BOOL OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext);
virtual void PostNcDestroy();

protected:
// Implementation
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)), pContext))
{

TRACE(Failed to create third pane );
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)), pContext))
{

TRACE(Failed to create third pane );
return FALSE;
}

m_pTabWnd2 = (CGXTabWnd*) m_wndSplitter.GetPane(1, 0);

// Creates the View1, View2 and View3 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();

}


 



Article ID: 40
Last updated: 22 Jun, 2018
Revision: 4
Stingray -> Objective Grid -> Objective Grid: Using a CGXTabWnd in a static splitter window
https://rwkbp.makekb.com/entry/40/