• C++如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图


    为了实现该功能我们需要对CSplitterWnd进行增强,具体实现如下:

    一、定义头文件
    //////////////////////////////////////////////////////////////////
    //
    // splitex.h
    class CSplitterWndEx : public CSplitterWnd
    {
    protected:
       int m_nHidedCol;    // hide column number, -1 if all columns
                           // are shown

    public:
       CSplitterWndEx();

       void ShowColumn();
       void HideColumn(int colHide);

    // ClassWizard generated virtual function overrides
       //{{AFX_VIRTUAL(CSplitterWndEx)
       //}}AFX_VIRTUAL

    // Generated message map functions
    protected:
       //{{AFX_MSG(CSplitterWndEx)
          // NOTE - the ClassWizard will add and remove member
          //        functions here.
          //}}AFX_MSG

        DECLARE_MESSAGE_MAP()
    };

    二、具体实现代码
    //////////////////////////////////////////////////////////////////
    //
    // splitex.cpp
    #include "stdafx.h"
    #include "splitex.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    //////////////////////////////////////////////////////////////////
    /
    // CSplitterWndEx

    CSplitterWndEx::CSplitterWndEx() :
        m_nHidedCol(-1)
    {
    }

    void CSplitterWndEx::ShowColumn()
    {
       ASSERT_VALID(this);
       ASSERT(m_nCols < m_nMaxCols);
       ASSERT(m_nHidedCol != -1);

       int colNew = m_nHidedCol;
       m_nHidedCol = -1;
       int cxNew = m_pColInfo[m_nCols].nCurSize;
       m_nCols++;    // add a column
       ASSERT(m_nCols == m_nMaxCols);

       // fill the hidden column
       int col;
       for (int row = 0; row < m_nRows; row++)
       {
          CWnd* pPaneShow = GetDlgItem(
             AFX_IDW_PANE_FIRST + row * 16 + m_nCols);
          ASSERT(pPaneShow != NULL);
          pPaneShow->ShowWindow(SW_SHOWNA);

          for (col = m_nCols - 2; col >= colNew; col--)
          {
             CWnd* pPane = GetPane(row, col);
             ASSERT(pPane != NULL);
             pPane->SetDlgCtrlID(IdFromRowCol(row, col + 1));
          }

          pPaneShow->SetDlgCtrlID(IdFromRowCol(row, colNew));
       }

       // new panes have been created -- recalculate layout
       for (col = colNew + 1; col < m_nCols; col++)
          m_pColInfo[col].nIdealSize = m_pColInfo[col - 1].nCurSize;
       m_pColInfo[colNew].nIdealSize = cxNew;
       RecalcLayout();
    }

    void CSplitterWndEx::HideColumn(int colHide)
    {
       ASSERT_VALID(this);
       ASSERT(m_nCols > 1);
       ASSERT(colHide < m_nCols);
       ASSERT(m_nHidedCol == -1);
       m_nHidedCol = colHide;

       // if the column has an active window -- change it
       int rowActive, colActive;
       if (GetActivePane(&rowActive, &colActive) != NULL &&
           colActive == colHide)
       {
          if (++colActive >= m_nCols)
             colActive = 0;
          SetActivePane(rowActive, colActive);
       }

       // hide all column panes
       for (int row = 0; row < m_nRows; row++)
       {
          CWnd* pPaneHide = GetPane(row, colHide);
          ASSERT(pPaneHide != NULL);
          pPaneHide->ShowWindow(SW_HIDE);
          pPaneHide->SetDlgCtrlID(
             AFX_IDW_PANE_FIRST + row * 16 + m_nCols);

          for (int col = colHide + 1; col < m_nCols; col++)
          {
             CWnd* pPane = GetPane(row, col);
             ASSERT(pPane != NULL);
             pPane->SetDlgCtrlID(IdFromRowCol(row, col - 1));
          }
       }
       m_nCols--;
       m_pColInfo[m_nCols].nCurSize = m_pColInfo[colHide].nCurSize;
        RecalcLayout();
    }

    BEGIN_MESSAGE_MAP(CSplitterWndEx, CSplitterWnd)
    //{{AFX_MSG_MAP(CSplitterWndEx)
       // NOTE - the ClassWizard will add and remove mapping macros here.
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

  • 相关阅读:
    大约PCA算法学习总结
    内部硬盘的硬件结构和工作原理进行了详细解释
    DWZ使用注意事项
    cocos2d-x 在XML分析和数据存储
    HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth完全详细的说明
    hdu 1114 Piggy-Bank
    getResources()方法
    人机博弈-吃跳棋游戏(三)代移动
    Oracle 11g client安装和配置。
    的微信公众号开发 图灵机器人接口允许调用自己的微通道成为一个智能机器人
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157181.html
Copyright © 2020-2023  润新知