CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    14

    Question MFC: CSplitterWnd, runtime class

    Hello,

    I have the following problem/question:

    Let's say I have a class CMyView derived from CView whose constructor can take parameters which influence the view's initial appearance (e.g. an RGB value to set the background color).

    Now I want to use CSplitterWnd and create TWO views with CMyView as the runtime class. The two views are supposed to be initialized with different parameters though and therefore have a different initial appearance.

    Since I can only pass the runtime class to CSplitterWnd::CreateView how is it possible to influence the construction of the view used with CSplitterWnd?

    Thanks in advance!

  2. #2
    Join Date
    Jan 2004
    Location
    Near Portland, OR
    Posts
    222

    Re: MFC: CSplitterWnd, runtime class

    Quote Originally Posted by maglite View Post
    Hello,

    I have the following problem/question:

    Let's say I have a class CMyView derived from CView whose constructor can take parameters which influence the view's initial appearance (e.g. an RGB value to set the background color).

    Now I want to use CSplitterWnd and create TWO views with CMyView as the runtime class. The two views are supposed to be initialized with different parameters though and therefore have a different initial appearance.

    Since I can only pass the runtime class to CSplitterWnd::CreateView how is it possible to influence the construction of the view used with CSplitterWnd?

    Thanks in advance!
    You will have a view for the program that will own the splitter:

    CSplitterWnd m_wndSplitter;

    In the OnCreate for your program's main view, you will initialize the splitter and set up two panes:

    m_wndSplitter.CreateStatic(this,1, 2); //Creates two side by side panes

    Then you create each pane and do an instance of CMyView in each:
    Code:
    pContext = (CCreateContext*)lpCreateStruct->lpCreateParams;
    lpCreateStruct->style |= WS_OVERLAPPED;
    m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CMyView), CSize(0,0), pContext);
    m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CMyView),  CSize(0,0), pContext);
    m_pView0=(CMyView *)m_wndSplitter.GetPane(0,0);
    m_pView1=(CMyView *)m_wndSplitter.GetPane(0,1);
    You now have two instances of CMyView that are independent of one another that are children of your program's main view.

    Bill

  3. #3
    Join Date
    Jun 2009
    Posts
    14

    Re: MFC: CSplitterWnd, runtime class

    I now see that my question doesn't make much sense in the way that i want to pass parameters to the constructor of the view, since the constructor is of course protected...

    Thank you for your answer, wdolson! This is exactly what i needed to know.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured