Click here to Skip to main content
15,891,431 members
Articles / Desktop Programming / MFC

CUsefulSplitterWnd (An Extension to CSplitterWnd)

Rate me:
Please Sign up or sign in to vote.
4.82/5 (26 votes)
24 Jan 2000CPOL 385.3K   8.1K   57   91
An extension to MFCs CSplitterWnd that provides splitter locking and dynamic view replacement

The CUsefulSplitterWnd class presents two extensions to CSplitterWnd.

  1. The first extension is the ability to lock the bar in position so that it can no longer be moved.
     // bar is locked using LockBar(TRUE) 
    m_wndSplitter.LockBar(TRUE);  
    
    // and is unlocked using LockBar(FALSE) 
    m_wndSplitter.LockBar(FALSE);
  2. The second extension allows the views in each pane to be changed dynamically using the ReplaceView() method.
     // to replace a view in a pane you use ReplaceView 
    m_wndSplitter.ReplaceView(0,1,RUNTIME_CLASS(CForm1),CSize(100,100));

    This would replace the view in row 0, column 1 with CForm1 and with a minimum size of 100x100.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Employed (other) Purplebricks
Australia Australia
All articles are supplied as-is, as a howto on a particular task that worked for me in the past. None of the articles are supposed to be out-of-the-box freeware controls and nor should they be treated as such. Caveat emptor.

Now living and working in Australia, trying to be involved in the local .NET and Agile communities when I can.

I spend a good chunk of my spare time building OpenCover and maintaining PartCover both of which are Code Coverage utilities for .NET.

Comments and Discussions

 
QuestionHow to make SetFocus? Pin
yummi15-Jan-03 8:29
yummi15-Jan-03 8:29 
AnswerRe: How to make SetFocus? Pin
Shaun Wilde17-Jan-03 8:14
Shaun Wilde17-Jan-03 8:14 
GeneralRe: How to make SetFocus? Pin
yummi17-Jan-03 9:06
yummi17-Jan-03 9:06 
GeneralMany Thanks Pin
FretBoardKnowledge13-Jan-03 13:02
FretBoardKnowledge13-Jan-03 13:02 
GeneralYet another Thanx Pin
Old Timer28-Nov-02 4:32
Old Timer28-Nov-02 4:32 
GeneralThanks! Pin
Hydra8-Aug-02 7:09
Hydra8-Aug-02 7:09 
GeneralRe: Thanks! Pin
Shaun Wilde8-Aug-02 10:29
Shaun Wilde8-Aug-02 10:29 
GeneralCall OnInitialUpdate() when u are using CFormView Pin
aldeba13-Jun-02 17:13
aldeba13-Jun-02 17:13 
Please remember to call OnInitialUpdate() in Replace view as pointed out by salinas in
http://www.codeproject.com/splitter/usefulsplitter.asp?df=100&forumid=260&select=91652#xx91652xx

C#
BOOL CUsefulSplitterWnd::ReplaceView(int row, int col,CRuntimeClass * pViewClass,SIZE size)
{
  CCreateContext context;
  BOOL bSetActive;
	       
   
  if ((GetPane(row,col)->IsKindOf(pViewClass))==TRUE)
       return FALSE;
   
   // Get pointer to CDocument object so that it can be used in the creation 
   // process of the new view
   CDocument * pDoc= ((CView *)GetPane(row,col))->GetDocument();
   CView * pActiveView=GetParentFrame()->GetActiveView();

   if (pActiveView==NULL || pActiveView==GetPane(row,col))
      bSetActive=TRUE;
   else
      bSetActive=FALSE;

    // set flag so that document will not be deleted when view is destroyed
   if (pDoc!=NULL) pDoc->m_bAutoDelete=FALSE;    
    // Delete existing view 
   ((CView *) GetPane(row,col))->DestroyWindow();
	
    // set flag back to default 
    if (pDoc!=NULL) pDoc->m_bAutoDelete=TRUE;
 
    // Create new view                      
   
   context.m_pNewViewClass=pViewClass;
   context.m_pCurrentDoc=pDoc;
   context.m_pNewDocTemplate=NULL;
   context.m_pLastView=NULL;
   context.m_pCurrentFrame=NULL;
      
   CreateView(row,col,pViewClass,size, &context);   
   
   CView * pNewView= (CView *)GetPane(row,col);   
   
   if (bSetActive==TRUE)
      GetParentFrame()->SetActiveView(pNewView);
   
   RecalcLayout(); 
   pNewView->OnInitialUpdate();

   GetPane(row,col)->SendMessage(WM_PAINT);
   
   return TRUE;
}


I hope u guys don make the same mistake as me. Spend almost a week and asking around and still couln'd find the problem. Finally solved it and noticed salinas post too.

The above code also takes care of things when u don't use a document/view architecture, just a small check on pDoc!=NULL

or u can use WM_INITIALUPDATE as suggested by salinas post
then you would need to include this
C#
#include <afxpriv.h>

and change
C#
pNewView->OnInitialUpdate();

to
C#
pNewView->SendMessage(WM_INITIALUPDATE);

GeneralRe: Call OnInitialUpdate() when u are using CFormView Pin
Shaun Wilde8-Aug-02 10:28
Shaun Wilde8-Aug-02 10:28 
GeneralReplaceView error !!! Pin
nvhoang13-Mar-02 2:12
nvhoang13-Mar-02 2:12 
GeneralRe: ReplaceView error !!! Pin
Shaun Wilde8-Aug-02 10:24
Shaun Wilde8-Aug-02 10:24 
Generalwhy not send WM_INITIALUPDATE to the new view Pin
salinas25-Dec-01 18:06
salinas25-Dec-01 18:06 
GeneralPreventing splitterbar movement past a postion Pin
TBiker10-Dec-01 11:23
TBiker10-Dec-01 11:23 
GeneralRe: Preventing splitterbar movement past a postion Pin
12-Feb-02 11:46
suss12-Feb-02 11:46 
GeneralThankx Pin
26-Nov-01 1:46
suss26-Nov-01 1:46 
QuestionHow can I use SCROLL BARS with your Class Pin
30-Jun-01 10:18
suss30-Jun-01 10:18 
GeneralCongratulation Pin
24-May-01 11:42
suss24-May-01 11:42 
GeneralSWSplit Pin
20-May-01 6:18
suss20-May-01 6:18 
GeneralRe: SWSplit Pin
SAWilde15-Jun-01 3:26
SAWilde15-Jun-01 3:26 
GeneralRe: SWSplit Pin
Jeason Zhao18-Jun-01 20:15
Jeason Zhao18-Jun-01 20:15 
GeneralRe: SWSplit Pin
SAWilde18-Jun-01 21:49
SAWilde18-Jun-01 21:49 
GeneralChanging bitmaps Pin
18-Apr-01 19:05
suss18-Apr-01 19:05 
GeneralRe: Changing bitmaps Pin
SAWilde15-Jun-01 3:26
SAWilde15-Jun-01 3:26 
General3 panes Pin
Dora11-Jul-00 5:12
Dora11-Jul-00 5:12 
GeneralRe: 3 panes Pin
Shaun Wilde11-Jul-00 9:05
Shaun Wilde11-Jul-00 9:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.