MFC 获得各类指针、句柄的方法

 一般我们使用的框架是VC提供的Wizard生成的MFC App Wizard(exe)框架,无论是多文档还是单文档,都存在指针和句柄获取和操作问题。本文中将针对各类句柄的获得、指针的获得以及MFC中常见应用进行阐述并举例。

 

 

本节为VC中常用的文档类,视图类,框架类,应用程序类,自定义类中获取其它四个类的方法: 
GET App 
   AfxGetInstanceHandle() 
   AfxGetApp() 
GET Frame->View->Document 
    SDI   AfxGetMainWnd() -> GetActiveView() -> GetDocument() 
    MDI   AfxGetMainWnd() -> MDIGetActive() -> GetActiveView() -> GetDocument() 
GET Menu 
     CMenu *pMenu=AfxGetApp()->m_pMainWnd->GetMenu(); 
GET ToolBar,StatusBar 
      (CMainFrame *)GetParent()->m_wndToolBar; 
      (CMainFrame *)GetParent()->m_wndStatusBar; 
      CStatusBar * pStatusBa=(CStatusBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR); 
      CToolBar * pToolBar=(CtoolBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR); 
Get View from Document 
      GetFirstViewPosition 和 GetNextView 函数得到指针。 

<from : http://m.blog.csdn.net/blog/abcjennifer/7480019>

 

posted @ 2013-04-01 13:00  MMLoveMeMM  阅读(353)  评论(0)    收藏  举报