오후 9:13 00-01-20 조경민 bro@shinbiro.com
분활뷰 만들기
------------------------------------------------------------
Doc/View 구조 없는 SDI에서 스플릿 윈도우 만들기

다음과 같이 메인 프레임에 스플릿 윈도우 변수를 마련한다.

class CMainFrame : public CFrameWnd
{
        
public:
        CMainFrame();
protected:
        DECLARE_DYNAMIC(CMainFrame)

        CSplitterWnd m_wndSplitter;

그리고 클래스 위자드를 불러서 OnCreateClient라는 함수를 오버라이드한다.
그후 자신이 올리려는 뷰를 RUNTIME_CLASS를 써서 올리면된다.
이때 문제는 CChildView라는 녀석은 (Non Doc/View에서) CWnd이기 때문에
동적 생성이 안되어 여기에 넣기도 뭐하고 하므로 코드를 삭제해야 한다.

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
        // TODO: Add your specialized code here and/or call the base class
        // create splitter window
        if (!m_wndSplitter.CreateStatic(this, 1, 2))
                return FALSE;
        
        if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftMainView), CSize(100, 100), pContext) ||
                !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CMainHtmlView), CSize(100, 100), pContext))
        {
                m_wndSplitter.DestroyWindow();
                AfxMessageBox("FALSE wndSpliter");
                return FALSE;
        }        

        return CFrameWnd::OnCreateClient(lpcs, pContext);
        //return TRUE;
}


CChildView 코드를 삭제하자.

CMainFrame.h에서 삭제
protected:  // control bar embedded members
        CStatusBar  m_wndStatusBar;
        CToolBar    m_wndToolBar;
        CReBar      m_wndReBar;
        CDialogBar      m_wndDlgBar;
        //CChildView    m_wndView;

CMainFrame.cpp에서  삭제를 해주면 된다.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
        if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
                return -1;
        // create a view to occupy the client area of the frame
        /*if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
                CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
        {
                TRACE0("Failed to create view window\n");
                return -1;
        }
        */


그리고 그외에 m_wndView 를 쓰는 곳의 코드를 삭제하면 된다.
void CMainFrame::OnSetFocus(CWnd* pOldWnd)
{
        // forward focus to the view window
//        m_wndView.SetFocus();
}

BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
        // let the view have first crack at the command
//        if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
//                return TRUE;

        // otherwise, do default handling
        return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

+ Recent posts