woka

对话框中获得文档指针pDoc

For   a   single   document   interface   (SDI)   application,   add   the   following   code   to   your   SDI   document's   implementation   file   for   CMyDoc::GetDoc():    
   
        //   SDI   document   implementation   file  
        CMyDoc   *   CMyDoc::GetDoc()  
        {  
              CFrameWnd   *   pFrame   =   (CFrameWnd   *)(AfxGetApp()->m_pMainWnd);  
              return   (CMyDoc   *)   pFrame->GetActiveDocument();
 
        }  
   
   
  For   a   multiple   document   interface   (MDI)   application,   the   CMyDoc::GetDoc()   code   should   be   the   following:    
   
        CMyDoc   *   CMyDoc::GetDoc()  
        {  
              CMDIChildWnd   *   pChild   =  
                      ((CMDIFrameWnd*)(AfxGetApp()->m_pMainWnd))->MDIGetActive();  
   
              if   (   !pChild   )  
                      return   NULL;  
   
              CDocument   *   pDoc   =   pChild->GetActiveDocument();  
   
              if   (   !pDoc   )  
                    return   NULL;  
   
              //   Fail   if   doc   is   of   wrong   kind  
              if   (   !   pDoc->IsKindOf(   RUNTIME_CLASS(CMyDoc)   )   )  
                    return   NULL;  
   
              return   (CMyDoc   *)   pDoc;
 
        }  

posted on 2009-05-17 20:07 woka 阅读(777) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2009年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

导航

统计

常用链接

留言簿(2)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜