本文共 1086 字,大约阅读时间需要 3 分钟。
利用MFC进行多文档程序开发的时候,灵活运行系统提供的获取指针方法快速定位到某一个窗体,我个人觉得蛮重要的。
1、GetParent(HWND hWnd);获取当前窗口是个子窗口,获取是父窗口的指针,如果是弹出的模态窗口(顶层窗口),获取的是没有WS_CHILD属性的间接父窗口。MSDN中的解释如下:If the window is a child window, the return value is a handle to the parent window. If the window is a top-level window, the return value is a handle to the owner window. If the window is a top-level unowned window or if the function fails, the return value is NULL2、获取应用程序的指针AfxGetApp();3、获取主框架的指针AfxGetMainWnd();((CMainFrame*)AfxGetApp())->m_pMainWnd;4、获取菜单的指针AfxGetMainWnd()->GetMenu();5、获取工具栏、状态栏的指针1)主窗口的相应变量m_wndStatusBarm_wndToolBarm_wndRibbonBar //ribbonBar工具栏2) 函数获取AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR);6、 文档,指图指针AfxGetMainWnd()->GetActiveFrame();AfxGetMainWnd()->GetActiveView(); //如果是多文档,首先获取子框架指针,AfxGetMainWnd()->GetActiveFrame()->GetActiveView();AfxGetMainWnd()->GetActiveDocument();7、获取子控件的指针GetDlgItem(AFX_IDW_PANE_FIRST) //多文档在主框架中获取的是主框架建立的一个伪视图(通过CreateWindow创建的),子框架中获取的才是真正的视图转载于:https://blog.51cto.com/tommy/2372242