大体代码如下:
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)// Attributes
public:
SplitterWnd wndSplitter;
..........
};
void CMainFrame::Onsend() 
{
// TODO: Add your command handler code here
//MessageBox("hello");
SplitterWnd &sw=wndSplitter;
sw.ChangeView(0,1,RUNTIME_CLASS(CRecsms));
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
if (!wndSplitter.CreateStatic(this, 1, 2)) return false;
................
}
void SplitterWnd::ChangeView(int row, int col,CRuntimeClass* pViewClass)
{
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CView))); CView* pView = STATIC_DOWNCAST(CView, GetPane(row, col));
CFrameWnd* pFrame = pView->GetParentFrame();
ASSERT(pFrame); // set up create context to preserve doc/frame etc.
CCreateContext cc;
memset(&cc, 0, sizeof(CCreateContext));
cc.m_pNewViewClass = pViewClass;
cc.m_pCurrentDoc = pView->GetDocument();
cc.m_pNewDocTemplate = cc.m_pCurrentDoc ?
cc.m_pCurrentDoc->GetDocTemplate() : NULL;
cc.m_pCurrentFrame = pFrame; DeleteView(row, col);  // delete old view VERIFY(CreateView(row, col,  // create new one
pViewClass,
CSize(0,0),  // will fix in RecalcLayout
错误发生处: &cc));
// delete &cc;
RecalcLayout();  // recompute layout  // initialize the view
CWnd* pWnd = GetPane(row, col);
if (pWnd)
pWnd->SendMessage(WM_INITIALUPDATE);
}
我把窗口分割成左右两个,通过void CMainFrame::Onsend() 切换右边视图窗口,其中SplitterWnd::ChangeView(int row, int col,CRuntimeClass* pViewClass)是从另外的工程复制过来的,并且在那里运行良好。为什么在我这里运行到“错误发生处:”就出现
Unhandled exception in 文件名.exe(MFC42D.DLL):0x0000005 Access Violation?有什么办法可以解决?谢谢先!!