// MFCView.cpp : Defines the entry point for the application.
//#include "stdafx.h"
#include"resource.h"class CMyView:public CView{
DECLARE_MESSAGE_MAP()
public:
virtual void OnDraw(CDC *pDC);
afx_msg void OnPaint();
afx_msg void OnNew();
};
BEGIN_MESSAGE_MAP(CMyView,CView)
ON_COMMAND(ID_NEW,OnNew)
//ON_WM_PAINT()
END_MESSAGE_MAP()
void CMyView::OnNew(){
AfxMessageBox("新建被点击");
}
void CMyView::OnPaint(){
PAINTSTRUCT ps={0};
HDC hdc=::BeginPaint(this->m_hWnd,&ps);
::TextOut(hdc,200,200,"CMyView::OnPaint",strlen("CMyView::OnPaint"));
::EndPaint(this->m_hWnd,&ps);
}
void CMyView::OnDraw(CDC *pDC){
pDC->TextOut(100,100,"CMyView::OnDraw");
}
class CMyFrameWnd:public CFrameWnd{
DECLARE_MESSAGE_MAP()
public:
CSplitterWnd split1;
CSplitterWnd split2;
public:
virtual BOOL OnCreateClient(LPCREATESTRUCT lpCreateStruct,CCreateContext *CContext);
afx_msg void OnPaint();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
};
BEGIN_MESSAGE_MAP(CMyFrameWnd,CFrameWnd)
ON_WM_PAINT()
ON_WM_CREATE()
END_MESSAGE_MAP()
BOOL CMyFrameWnd::OnCreateClient(LPCREATESTRUCT lpCreateStruct,CCreateContext *CContext){
split1.CreateStatic(this,1,2);//这句代码出错
return CFrameWnd::OnCreateClient(lpCreateStruct,CContext);
}
int CMyFrameWnd::OnCreate(LPCREATESTRUCT lpCreateStruct){
CMyView *pView=new CMyView;
pView->Create(NULL,"",WS_CHILD|WS_VISIBLE|WS_BORDER,CRect(0,0,200,200),this,AFX_IDW_PANE_FIRST,NULL);
m_pViewActive=pView;
return CFrameWnd::OnCreate(lpCreateStruct);
}
void CMyFrameWnd::OnPaint(){
PAINTSTRUCT ps={0};
HDC hdc=::BeginPaint(m_hWnd,&ps);
::TextOut(hdc,200,200,"我是框架客户区",strlen("我是框架客户区"));
::EndPaint(m_hWnd,&ps);
}
class CMyWinApp:public CWinApp{
public:
virtual BOOL InitInstance();
};
CMyWinApp theApp;
BOOL CMyWinApp::InitInstance(){
CMyFrameWnd *pFrame=new CMyFrameWnd;
pFrame->Create(NULL,"MFCView",WS_OVERLAPPEDWINDOW,CFrameWnd::rectDefault,NULL,MAKEINTRESOURCE(IDR_MENU1));
m_pMainWnd=pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}代码已经写好的,调试起来运行错误Debug Assertion Failed!
Program:
..a\vc++6.0_win8\MyProjects\MFC\Day05\MFCView\Debug\MFCView.exe
File:winsplit.cpp
Line:364For information on how youre program can cause an assertion failure,see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
-------------------------------------------------------------------------------------------
Debug Assertion Failed!
Program:
..a\vc++6.0_win8\MyProjects\MFC\Day05\MFCView\Debug\MFCView.exe
File:winsplit.cpp
Line:1315For information on how youre program can cause an assertion failure,see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------------------------------------------------------------------------我在winsplit.cpp中查到错误的两处代码是:
CWnd* pView = GetDlgItem(IdFromRowCol(row, col));
ASSERT(pView != NULL);  // panes can be a CWnd, but are usually CViews
return pView;------------------------------------------------------------------------
ASSERT(pWnd != NULL);
ASSERT(pWnd->m_hWnd != NULL);
如果把CMyFrameWnd::OnCreateClient函数中的split1.CreateStatic(this,1,2);注释掉则程序没有报错,请问到底是哪里的问题呢,,为什么窗口切分始终用不了?

解决方案 »

  1.   


    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
    {
    // create splitter window
    if (!m_wndSplitter.CreateStatic(this, 1, 2)) return FALSE;
    //
    if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(100, 100), pContext) ||
    !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CMyExploreView), CSize(100, 100), pContext))
    {
    m_wndSplitter.DestroyWindow();
    return FALSE;
    }
    //
    return TRUE;
    }if (!m_wndSplitter.CreateStatic(this, 1, 2)) return FALSE; 后要
    !m_wndSplitter.CreateView
      

  2.   

    没有调用CSplitterWnd::CreateView()