static Splitterwnd hide and show --by wyj

转贴指明作者

#if !defined(AFX_MYSPLITER_H__A78B35E4_9855_43EE_9046_AF7B3A3AE2A9__INCLUDED_)
#define AFX_MYSPLITER_H__A78B35E4_9855_43EE_9046_AF7B3A3AE2A9__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MySpliter.h : header file

 #pragma warning( disable:4786 )
#include <list>
#include <map>
using namespace std;

class CMySpliter : public CSplitterWnd
{
// Construction
public:
 CMySpliter();

// Attributes
public:

// Operations
public:

// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CMySpliter)
 //}}AFX_VIRTUAL

// Implementation
public:
 virtual ~CMySpliter();
 virtual void HideRow(int row);
 void ShowRow( int row );
 // Generated message map functions
protected:
 //{{AFX_MSG(CMySpliter)
  // NOTE - the ClassWizard will add and remove member functions here.
 //}}AFX_MSG

 virtual void OnDrawSplitter( CDC* pDC, ESplitType nType, const CRect& rect );

 struct _HideSubUnit
 {
  CWnd* pWnd;
  int nCur;
  int nMin;
 };


 typedef list< _HideSubUnit > SUBLIST;

 struct _HideUnit
 {
  SUBLIST Sublist;
  int nCur;
  int nMin;
 };

 map< int, _HideUnit* > m_mapDelete;

 map< int, int > m_mapRowRow;

 DECLARE_MESSAGE_MAP()
};

 

// MySpliter.cpp : implementation file
//

#include "stdafx.h"
#include "fsdf.h"
#include "MySpliter.h"

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

/
// CMySpliter

CMySpliter::CMySpliter()
{
 /*
 m_cxSplitter = m_cySplitter = 2 + 1 + 1;
 m_cxBorderShare = m_cyBorderShare = 0;
 m_cxSplitterGap = m_cySplitterGap = 2 + 1 + 1;
 m_cxBorder = m_cyBorder = 1;
 m_uIDCount = 0;
 */
}

CMySpliter::~CMySpliter()
{
}


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

/
// CMySpliter message handlers

void CMySpliter::OnDrawSplitter( CDC* pDC, ESplitType nType, const CRect& rect )
{
 CSplitterWnd::OnDrawSplitter( pDC, nType, rect );
// if( pDC && splitBar == nType)
// pDC->FillSolidRect(rect, RGB(0, 0, 255));
}

void CMySpliter::HideRow(int rowVal)
{
 if( m_mapRowRow.empty() )
 {
  for( int i = 0; i < m_nRows; i++ )
   m_mapRowRow.insert( map< int, int >::value_type(i, i));
 }

 map< int, int >::iterator iter = m_mapRowRow.find(rowVal);
 if( iter == m_mapRowRow.end()  )
  return;


 map< int, int >::iterator iter1 = iter;
 for( ;iter != m_mapRowRow.end() ; iter++ )
 {
  iter->second--;
 }

 m_mapRowRow.erase( iter1 );

 int rowActive, colActive;
 if (GetActivePane(&rowActive, &colActive) != NULL && rowActive == rowVal)
 {
  if (++rowActive >= m_nRows)
   rowActive = 0;
  SetActivePane(rowActive, colActive);
 }

 CWnd* pScrollDel = m_bHasVScroll ?
  GetDlgItem(AFX_IDW_VSCROLL_FIRST+rowVal) : NULL;

 _HideUnit * pUnit = new _HideUnit;
 m_mapDelete.insert( map< int, _HideUnit* >::value_type( rowVal, pUnit ) );
 GetRowInfo( rowVal, pUnit->nCur, pUnit->nMin );

 for (int col = 0; col < m_nCols; col++)
 {
  _HideSubUnit sub;
  sub.pWnd = GetPane(rowVal, col);
  GetColumnInfo( col, sub.nCur, sub.nMin );
  pUnit->Sublist.push_back( sub );
  sub.pWnd->SetDlgCtrlID( 0 );
  sub.pWnd->ShowWindow( SW_HIDE );

  for (int row = rowVal+1; row < m_nRows; row++)
  {
   CWnd* pPane = GetPane(row, col);
   ASSERT(pPane != NULL);
   pPane->SetDlgCtrlID(IdFromRowCol(row-1, col));
   if (m_bHasVScroll && col == m_nCols-1)
   {
    CWnd* pScroll = GetDlgItem(AFX_IDW_VSCROLL_FIRST+row);
    if (pScroll != NULL)
     pScroll->SetDlgCtrlID(AFX_IDW_VSCROLL_FIRST+row-1);
   }
  }
 }
 m_nRows--;
 if (pScrollDel != NULL)
  pScrollDel->DestroyWindow();

 RecalcLayout();     // re-assign the space


}

void CMySpliter::ShowRow( int rowVal )
{
 map< int, _HideUnit* >::iterator iter = m_mapDelete.find( rowVal );
 if(  iter == m_mapDelete.end() )
  return;

 int nPos = 0;
 map< int, int>::iterator iter1 = m_mapRowRow.begin();
 for( ; iter1 != m_mapRowRow.end(); iter1++ )
 {
  if( iter1->first > rowVal )
  {
   iter1->second++;
  }
  else
  {
   nPos++;
  }
 }

 m_mapRowRow.insert( map< int, int>::value_type( rowVal, nPos ) );

 
 for (int col = 0; col < m_nCols; col++)
 {
  for (int row = nPos; row < m_nRows; row++)
  {
   CWnd* pPane = GetPane(row, col);
   ASSERT(pPane != NULL);
   pPane->SetDlgCtrlID(IdFromRowCol(row , col) + 16 );
   if (m_bHasVScroll && col == m_nCols-1)
   {
    CWnd* pScroll = GetDlgItem(AFX_IDW_VSCROLL_FIRST+row);
    if (pScroll != NULL)
     pScroll->SetDlgCtrlID(AFX_IDW_VSCROLL_FIRST+row + 1);
   }
  }
 }

 m_nRows++;
 SUBLIST::iterator listiter = iter->second->Sublist.begin();
 for ( col = 0; col < m_nCols; col++, listiter++)
 {
  listiter->pWnd->SetDlgCtrlID(IdFromRowCol(nPos, col) );
  listiter->pWnd->ShowWindow( SW_SHOW );
 }

 delete iter->second;
 m_mapDelete.erase( iter );
 

 if (m_bHasVScroll &&
  !CreateScrollBarCtrl(SBS_VERT, AFX_IDW_VSCROLL_FIRST + nPos))
 {
  TRACE0("Warning: SplitRow failed to create scroll bar./n");
 }

 
 RecalcLayout();
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值