zoukankan      html  css  js  c++  java
  • VC编程技术点滴(八)如何在视图类中获取主窗口指针

    1、如何在视图类中获取主窗口指针

        主窗口的指针保存在CWinThread::m_pMainWnd中(应用程序类的Initlnstance函数有用到),可以调用 AfxGetMainWnd获取,也可以用视图类继承的函数GetParent()获取。另外,如果要获取当前视图类对象的指针(比如要在当前视图手动添 加控件)要使用this。

        2、如何在主框架类中获得视图类指针

        单文档(SDI):

        CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
        CYourDoc* pDoc = (CYourDoc*)pMainFrame->GetActiveDocument();
        CYourView* pView = (CYourView*)pMainFrame->GetActiveView();
        多文档(MDI):
        CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
        CChildFrame* pChildFrame = (CChildFrame*)pMainFrame->GetActiveFrame();
        CYourDoc* pDoc = (CYourDoc*)pChildFrame->GetActiveDocument();
        CYourView* pView = (CYourView*)pChildFrame->GetActiveView();

  • 相关阅读:
    Matlab中对二维数组排序
    ATL COM对象崩溃问题一例
    CSS样式介绍
    关于php
    BootStrap介绍
    关于base系列的加密解密
    php基础知识
    任务一
    php数组
    【CV学习1】opencvpython:第一,二章
  • 原文地址:https://www.cnblogs.com/luoshupeng/p/2146185.html
Copyright © 2011-2022 走看看