zoukankan      html  css  js  c++  java
  • 在MFC中的CWinApp得到视图的指针,真难呀(适用于SDI和MDI)

    在MFC的SDI和MDI中,你要想从你的CXXXApp(当然是继承于CWinApp了)得到CXXXView(当然继承于CView了)视图指针可不是一件很容易的事情哟,还是很迂回的。下面将介绍如何得到,OK,让我们开始吧。
       如果我们要得到视图指针,首先我们要得到指向文档的指针,如何得到文档类的指针,首先我们又要得到文档模板的指针(即CDocTemplate),如何得到文档模板的指针,很简单,就是通过CWinApp类即可得到。
     具体过程如下:
     1)得到文档模板的位置
    2)根据模板的位置得到文档模板指针
     3)根据文档模板得到文档的位置
    4)根据文档的位置得到文档的指针
    5)根据文档得到视图的位置
    6)根据视图的位置得到视图的指针,这就是我们所要得到的。
    大家看了,是不是觉得很痛苦呀。
    请参见下图:

    OK,下面给出具体实现代码

     // Get the position of the first document template
     POSITION pos = GetFirstDocTemplatePosition();
     // Do we have a valid template position?
     if (pos)
     {
      // Get a pointer to the document template
      CDocTemplate* pDocTemp = GetNextDocTemplate(pos);
      // Do we have a valid pointer?
      if (pDocTemp)
      {
       // Get the position of the first document
       POSITION dPos = pDocTemp->GetFirstDocPosition();
       // Do we have a valid document position?
       if (dPos)
       {
        // Get a pointer to the document
        CTaskingDoc* pDocWnd =
         (CTaskingDoc*)pDocTemp->GetNextDoc(dPos);
        // Do we have a valid pointer?
        if (pDocWnd)
        {
         // Get the position of the view
         POSITION vPos = pDocWnd->GetFirstViewPosition();
         // Do we have a valid view position?
         if (vPos)
         {
          // Get a pointer to the view
          CTaskingView* pView = (CTaskingView*)pDocWnd->GetNextView(vPos);
    }
    }
    }

  • 相关阅读:
    瞬间从IT屌丝变大神——HTML规范
    瞬间从IT屌丝变大神——命名规则
    瞬间从IT屌丝变大神——分工安排
    写在开发前的话
    完全二叉树的权值
    无法更改电脑默认浏览器
    java语法错误,进行分析时已经到达文件结尾
    查找SHA1值
    关闭CPU 睿频方法
    Java idea 快捷键
  • 原文地址:https://www.cnblogs.com/confach/p/112352.html
Copyright © 2011-2022 走看看