我的文档视图结构程序中有一对话框,现我要在对话框中访问文档资源,怎么办,我是这样做的但不能运行:
.h文件中
CMainDoc* GetDocument();



#ifndef _DEBUG  // debug version in LeftpaneFrame.cpp
inline CMainDoc* CSearchDlg::GetDocument()
   { return (CMainDoc*)m_pDocument; }
#endif
////////////////////////////////////////////////////////
。CPP文件中
#ifdef _DEBUG
CMainDoc* CSearchDlg::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMainDoc)));
return (CMainDoc*)m_pDocument;
}#endif //_DEBUG
///////////////////////////////////////////////////////////
我访问文档资源在对话框 的INITDIALOG中,
如:
BOOL CSearchDlg::OnInitDialog() 
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
    m_pList = GetDocument()->GetList();
  。。

运行时通不过,我看了一下代码好像是在这里就不能通过: ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMainDoc)));怎么办呢?文档定义保证没有问题,因为我在视图中访问没有任何问题。谢谢各位很急!

解决方案 »

  1.   

    CMDIChildWnd * pMDIActive =((CMDIFrameWnd*) AfxGetApp()->GetMainWnd())->MDIGetActive();
    CSdi2Doc * pDoc =(CSdi2Doc *) pMDIActive->GetActiveDocument();
    #include "sdi2Doc.h"
      

  2.   

    那个CMDIChildWnd在什么地方定义,我单文档中好像没这个东西。再详细一点,非常感谢。
      

  3.   

    我用这个变通了一下,不知可否:
        CFrameWnd * pActive =((CFrameWnd*) AfxGetApp()->GetMainWnd())->GetActiveFrame();
    m_pDocument = (CMainDoc*)pActive->GetActiveDocument();
        m_pList = m_pDocument->GetList();
      

  4.   

    class CChildFrame : public CMDIChildWnd
    第二个应该变通