//MainFrm.h
protected:  
     CSplitterWnd  m_SplitterWnd;
//MainFrm.cpp
//创建拆分窗口
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: 在此添加专用代码和/或调用基类 if(!m_SplitterWnd.CreateStatic(this,1,2))
{
TRACE("创建分割窗口失败!");
return false;
}
if(!m_SplitterWnd.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,100),pContext)
|| !m_SplitterWnd.CreateView(0,1,RUNTIME_CLASS(CSplitterView),CSize(100,100),pContext))
{
TRACE("创建子视图失败!");
m_SplitterWnd.DestroyWindow();
return false;
}
//MessageBox("Hello");
return true;//CFrameWnd::OnCreateClient(lpcs, pContext);
}
//通过菜单隐藏左边的窗格
void CMainFrame::OnMenuHideleft()
{
// TODO: 在此添加命令处理程序代码
CWnd *pLeftWnd = m_SplitterWnd.GetPane(0,0);
CWnd *pRightWnd = m_SplitterWnd.GetPane(0,1);
m_SplitterWnd.SetActivePane( 0, 1 );
pLeftWnd->SetDlgCtrlID( AFX_IDW_PANE_FIRST + 1 );
pRightWnd->SetDlgCtrlID( AFX_IDW_PANE_FIRST ); 

pLeftWnd->ShowWindow( SW_HIDE );

pRightWnd->ShowWindow( SW_SHOW );
m_SplitterWnd.RecalcLayout();
}
可是无法隐藏,请高手指点!

解决方案 »

  1.   

    RecalcLayout之前加
    SetColumnInfo
      

  2.   

    GetActiveDocument()->m_bAutoDelete =false;
    m_SplitterWnd.DestroyWindow();
    GetActiveDocument()->m_bAutoDelete =true;然后创立一个右边视图可以看看
    http://community.csdn.net/Expert/topic/3104/3104698.xml?temp=.2957117
      

  3.   

    zoid():
    加了SetColumnInfo之后
    m_SplitterWnd.SetColumnInfo( 0, 0, 0 );
    m_SplitterWnd.SetColumnInfo( 1, 1000, 1000 );
    m_SplitterWnd.RecalcLayout();
    两个分割窗格的之间的分割条依然存在,并且最大化之后不能刷新。这个以前我就试过。kongyunzhongque(云雀):
    您的意思就是先销毁m_SplitterWnd然后创建一个新的右视图,但这个右视图是新的,原先视图中的内容就没有了,而且左视图中的东西也清掉了,不能再恢复了。是不是另有高招?
      

  4.   

    再m_SplitterWnd.SetDlgCtrlID(0);试试。
      

  5.   

    ////////////////////////////////////////////////////////////////////////////
    /
    // splitex.h
    // (c) 1997, Oleg G. Galkinclass CSplitterWndEx : public CSplitterWnd
    {
    protected:
         int m_nHidedCol;  // hided column number, -1 if all columns are shownpublic:
         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
    // (c) 1997, Oleg G. Galkin#include "stdafx.h"
    #include "splitex.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif////////////////////////////////////////////////////////////////////////////
    /
    // CSplitterWndExCSplitterWndEx::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 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;
         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()
    可参考一下这个例子,,,,,,
      

  6.   

    http://www.codeguru.com/Cpp/W-D/splitter/article.php/c1543
      

  7.   

    例子不错,但是还有点不明白,
    1.为什么要重新设置每个窗格的ID?
    2.再看这段代码:
    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));
              }
         }
    在第二个循环里面,当前要设置新ID的窗格为(row,col),它被设置新的ID后,它的ID就是窗格(row,col-1)的ID,一次类推下一个就是(row,col+1)了,它的新ID将是刚被设过的(row,col)的ID,那么以后的窗格ID将都是一样的。但事实上输出他们的ID却不是一样的。
      

  8.   

    ID不一样,
    实际上,这个循环覆盖被隐藏的COL的ID,colHide后面的COLS全部往回作了位移。