Click here to Skip to main content
Click here to Skip to main content

A Doc/View Dialog, supports Dynamic Split

By , 21 Aug 2003
 

Sample Image - A_Doc_View_Dialog_support.jpg

As you see, you can arbitrarily add DOC/View, and all the view can be resized.

Why I Write this class?

My company asked me to make a COM dialog supporting multi_Doc/View. Because this is a COM based dialog, I can't make it using this Single or Mulit_Doc Doc/View. I looked for a solution in The Code Project, Code Guru etc., but I couldn't find a suitable class and sample, so I did it myself.

What's this about?

This demo only implements the base function: you can add the Doc / view, resize the View by dragging the splitter. Here, using iterator, notice all the view changing size. This can be done better :-), and this method has some bug. For example, I can't proportionately scale the sub_split's view… I will fix it. :-)

What classes are part of this?

  • CSplitterControl

    This class is like the Split, but not derived form the CSplitterWnd.

  • CDisplayView

    View's base class, here all view resizing must derive form it.

How to using this class

  1. Add this files into your project

    SplitterControl.h 
    SplitterControl.cpp 
    /*all view should come from CDisplayView */
    DisplayView.h 
    DisplayView.cpp
  2. Add some code in your project

    /*File "MyDialog.h"*/ 
    #include <VECTOR>
    #include "SplitterControl.h" 
    #include "DisplayView.h" 
           using namespace std; 
    class CMyDlgDlg: public CDialog 
    { 
        /*…………*/ 
        void UpdateRect(CSplitterControl *pSplitter); 
        CDisplayView *AddRootView(UINT docNum, UINT viewNum,CRect 
                       rect,CSplitterControl *splitter); 
        void AddView(UINT docNum,UINT viewNum,UINT type, 
                     CSplitterControl *splitter, 
                     CView *pCurView); 
        /*…………*/ 
        /* Split vector*/ 
         CSplitterControl m_pSplit; 
         CCreateContext m_pContext; 
        /*………………*/ 
    };
  3. Into the CMyDlgDlg's dialog designer

    • Add a "Picture Box", ID = "IDC_STA_SPLIT".

      It will become the root Split's position;

    • Add a "Ststic", ID = "IDC_STA_VIEW".

      It will become the region of the all View draw.

  4. Copy the function implementation code from the demo project.

    void CMyDlgDlg::AddView(UINT docNum, UINT viewNum,UINT type, 
    CSplitterControl *splitter,CView *pCurView) 
    { 
      /*………… copy demp project code here */
    } 
    CDisplayView *CMyDlgDlg::AddRootView(UINT docNum, UINT viewNum, 
    CRect rect,CSplitterControl *splitter) 
    { 
      /*………… copy demp project code here */
    
    } 
    void CMyDlgDlg::UpdateRect(CSplitterControl *pSplitter) 
    { 
      /*………… copy demp project code here */
    
    } 
    BOOL CMyDlgDlg::OnInitDialog() 
    { 
      CDialog::OnInitDialog(); 
      /*……………… */
      /* TODO: Add extra initialization here  */
      /* flowwer code using init the root view. */
      CRect rc; 
      GetDlgItem(IDC_STA_SPLIT)->GetWindowRect(rc); 
      ScreenToClient(rc); 
      m_pSplit.Create(WS_CHILD | WS_VISIBLE,rc,this,IDC_STA_SPLIT); 
      m_pSplit.SetRange(300, 300, -1); 
      GetDlgItem(IDC_STA_VIEW)->GetWindowRect(rc); 
      ScreenToClient(rc); 
    /***************************************/ 
    /*In here add the root View and Document*/ 
      m_pSplit.AddRootView(0,1,rc); 
      m_pSplit.ShowWindow(SW_HIDE); 
    return TRUE;
    }
  5. In the SplitterControl.cpp, add the Dialog's head file

    #include "MyDlg.h"    /*The application class */ 
    #include "MyDlgDlg.h" /*the dialog class */

I am Chinese and finish my school life last month, my English is very poor, so this article has some language error :-). I am a devoted reader of CodeProject, thanks everybody for helping me. Thanks CodeProject, thanks C++.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

shudingbo
Systems Engineer huawei
China China
Member
I do I want to do,and you?

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalthis project edit stdafx.hmemberYunJung Kim23 Oct '07 - 7:24 
take care when you implement
Generalsome questionsmemberluolf7 May '07 - 23:32 
i have creates a project follow your steps,but there are some worng, i don't konw what's the relations about the files in the Source Files between the files in the DocAndViw , you have not metioned the files in the DocAndView floder, you can see these in FileView part in VC project, how they worked in the project or what's their use. thank you very much!
GeneralScrollingmemberonlykeshu21 Feb '06 - 23:19 
I write some text in the control and it's size exceeds the cotrol size......how i use scrolling in the contols(both horizontal and vertical scrolling)
 
thanks
 
keshu
QuestionAbout &quot;picture&quot; and &quot;static&quot;?memberbonmeepon7 Apr '05 - 6:22 
In the dialog, what for in creating both "picture" and "static"?
 
If I don't want the splitter but only the view in the dialog, what should I do?
 

 
bonmeepon means pupcorn
AnswerRe: About &amp;quot;picture&amp;quot; and &amp;quot;static&amp;quot;?membercolo0077 May '06 - 21:18 
"picture" may be the picture control and "static" may be the static text.
All are possible.I am not sure.
 
-- modified at 3:18 Monday 8th May, 2006
GeneralInteresting idea...memberRyan Binns21 Aug '03 - 20:32 
But you really need to stick to the standard formatting, for example:
  • Use the <h1>, <h2> etc. tags for titles.
  • Use the <pre> tag for blocks of code, and <code> for small pieces of code inserted in text.
You also need to include some sort of description about what you've done and why, how it works, and how to use it. Take a look at Marc Clifton's guide to writing articles for CP[^] to get more ideas.
 
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

GeneralRe: Interesting idea...memberlava_sdb22 Aug '03 - 17:18 
Thanks for you advise,i update it,Smile | :)
 
I love fish,like i love C++.

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 22 Aug 2003
Article Copyright 2003 by shudingbo
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid