11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3. Splitter Window<br />

)<br />

{<br />

}<br />

if<br />

(<br />

)<br />

{<br />

}<br />

if<br />

(<br />

)<br />

{<br />

}<br />

if<br />

(<br />

)<br />

{<br />

}<br />

!m_wndSpMain.CreateView<br />

(<br />

0, 0, RUNTIME_CLASS(CSpwView), CSize(100, 100), pContext<br />

)<br />

TRACE0("Failed to create first pane\n");<br />

return FALSE;<br />

!m_wndSpSub.CreateStatic<br />

(<br />

&m_wndSpMain, 2, 1,<br />

WS_CHILD | WS_VISIBLE, m_wndSpMain.IdFromRowCol(0, 1)<br />

)<br />

TRACE0("Failed to create nested splitter\n");<br />

return FALSE;<br />

!m_wndSpSub.CreateView<br />

(<br />

0, 0, RUNTIME_CLASS(CSpwFView), CSize(50, 50), pContext<br />

)<br />

TRACE0("Failed to create second pane\n");<br />

return FALSE;<br />

!m_wndSpSub.CreateView<br />

(<br />

1, 0, RUNTIME_CLASS(CSpwEView), CSize(50, 50), pContext<br />

)<br />

TRACE0("Failed to create third pane\n");<br />

return FALSE;<br />

}<br />

return TRUE;<br />

For an MDI application, everything is almost the same except that here CChildFrame replaces class<br />

CMainFrame. We can create an MDI application, declare m_wndSpMain and m_wndSpSub variables in class<br />

CChildFrame, and add code to CChildFrame::OnCreateClient(…) to create splitter windows. The code<br />

required here is exactly the same with implementing splitter window in an SDI application. Sample<br />

3.1\MDI\Spw demonstrates this.<br />

3.2 Dynamic Splitter Window<br />

Once we understand how to create static splitter window, it is easier for us to create dynamic splitter<br />

window because it takes fewer steps. For a dynamic splitter window, all panes are created to be the same<br />

type of view, so there is no need to call function CSplitterWnd::CreateView(…) for each individual pane.<br />

Also, instead of calling CSplitterWnd::CreateStatic(…), we need to call function CSplitterWnd::<br />

Create(…) to create dynamic splitter window within function CFrameWnd::OnCreateClient(…). The<br />

following is the format of function CSplitterWnd::Create(…):<br />

60

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!