可以隐藏或显示某视图的CSplitterEx类

来源:互联网 发布:模拟驾车软件 编辑:程序博客网 时间:2024/05/21 09:46
可以隐藏或显示某视图的CSplitterEx类
前几天写程序,遇到一个问题。
类似的IE窗口的“历史”或“收藏夹”功能,当点击”历史“以后,会在左边出现一个视图,再点一下,这个视图就关闭(其实是隐藏).
费了半天劲,找到了一个代码,它只能隐藏列,我修改了一下,可以隐藏行了。
//CSplitterEx.h

#pragma once

// CSplitterEx 框架
class CSplitterEx : public CSplitterWnd
{
 DECLARE_DYNCREATE(CSplitterEx)
protected:
public:
 int m_nHidedCol;
 int m_nHidedRow;
 CSplitterEx();           // 动态创建所使用的受保护的构造函数
//呵,加个昵称:头太晕 http://spaces.msn.com/members/headfaint
 virtual ~CSplitterEx();
 void ShowColumn(bool bShow=false);
 void HideColumn(int colHide);
 void ShowRowumn(bool bShow=false);
 void HideRowumn(int rowHide);
protected:
 DECLARE_MESSAGE_MAP()
};

 
//CSplitterEx.cpp
 
// CSplitterEx.cpp : 实现文件
//
//呵,加个昵称:头太晕 http://spaces.msn.com/members/headfaint
#include "stdafx.h"
#include "CSplitterEx.h"

// splitterex
IMPLEMENT_DYNCREATE(CSplitterEx, CSplitterWnd)
CSplitterEx::CSplitterEx()
:m_nHidedCol(-1),m_nHidedRow(-1)
{
}
CSplitterEx::~CSplitterEx()
{
}

BEGIN_MESSAGE_MAP(CSplitterEx, CSplitterWnd)
END_MESSAGE_MAP()
void CSplitterEx::ShowColumn(bool bShow)

{
 //这个是显示所有列的.   加个昵称:头太晕 http://spaces.msn.com/members/headfaint
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 hided 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;
 if(bShow)RecalcLayout();
}
void CSplitterEx::HideColumn(int colHide)
{
 //这个是隐藏列的,   加个昵称:头太晕 http://spaces.msn.com/members/headfaint
 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();
}
void CSplitterEx::ShowRowumn(bool bShow)
{
 //这个是显示行的,   加个昵称:头太晕 http://spaces.msn.com/members/headfaint

 ASSERT_VALID(this);
 ASSERT(m_nRows < m_nMaxRows);
 ASSERT(m_nHidedRow != -1);
 int rowNew = m_nHidedRow;
 m_nHidedRow = -1;
 int cxNew = m_pRowInfo[m_nRows].nCurSize;
 m_nRows++;  // add a column
 ASSERT(m_nRows == m_nMaxRows);
 // fill the hided rowumn
 int row;
 for (int col = 0; col < m_nCols; col++)
 {
  CWnd* pPaneShow = GetDlgItem(
   AFX_IDW_PANE_FIRST + col * 16 + m_nRows);
  ASSERT(pPaneShow != NULL);
  pPaneShow->ShowWindow(SW_SHOWNA);
  for (row = m_nRows - 2; row >= rowNew; row--)
  {
   CWnd* pPane = GetPane(row, col);
   ASSERT(pPane != NULL);
   pPane->SetDlgCtrlID(IdFromRowCol(row+1, col));
  }
  pPaneShow->SetDlgCtrlID(IdFromRowCol(rowNew, col));
 }
 // new panes have been created -- recalculate layout
 for (row = rowNew + 1; row < m_nRows; row++)
  m_pRowInfo[row].nIdealSize = m_pRowInfo[row - 1].nCurSize;
 m_pRowInfo[rowNew].nIdealSize = cxNew;
 if(bShow) RecalcLayout();
}
void CSplitterEx::HideRowumn(int rowHide)
{
 //这个是隐藏行的,   加个昵称:头太晕 http://spaces.msn.com/members/headfaint

 ASSERT_VALID(this);
 ASSERT(m_nRows > 1);
 ASSERT(rowHide < m_nRows);
 ASSERT(m_nHidedRow == -1);
 m_nHidedRow = rowHide;
 // if the rowumn has an active window -- change it
 int rowActive, colActive;
 if (GetActivePane(&rowActive, &colActive) != NULL &&
  rowActive == rowHide)
 {
  if (++rowActive >= m_nRows)
   rowActive = 0;
  SetActivePane(rowActive, colActive);
 }
 // hide all rowumn panes
 for (int col = 0; col < m_nCols; col++)
 {
  CWnd* pPaneHide = GetPane(rowHide, col);
  ASSERT(pPaneHide != NULL);
  pPaneHide->ShowWindow(SW_HIDE);
  pPaneHide->SetDlgCtrlID(
   AFX_IDW_PANE_FIRST + col * 16 + m_nRows);
  for (int row = rowHide + 1; row < m_nRows; row++)
  {
   CWnd* pPane = GetPane(row, col);
   ASSERT(pPane != NULL);
   pPane->SetDlgCtrlID(IdFromRowCol(row-1, col));
  }
 }
 m_nRows--;
 m_pRowInfo[m_nRows].nCurSize = m_pRowInfo[rowHide].nCurSize;
 RecalcLayout();
}

// CSplitterEx 消息处理程序
原创粉丝点击