Split Screen application and assigning different views

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahammad
    New Member
    • May 2007
    • 79

    Split Screen application and assigning different views

    I have a split screen application with two panes. I would like to assign different views to each pane. I created the application using th wizard, which created a class called CSplitMFCView, a subclass of CView.

    I added the following two lines in the OnCreateClient function of MainFrm.cpp

    Code:
    m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CSplitMFCView), CSize(1, 1), pContext);
    
    m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CView), CSize(10, 10), pContext);
    In order to differentiate between the two views, I modified the OnDraw function of CSplitMFCView so that it prints a red rectangle in the view. I added those lines:

    Code:
    pDC->SetBkColor(RGB(152,0,0));
    
    pDC->FillSolidRect(1, 1, 200, 200, RGB(255,0,0));
    What I thought would happen is that the first pane would have the red rectangle, and the second pane would be the default CView pane, which should be white. This was not the case, both panes have the red rectangle.

    How can I fix this?

    Thanks.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Originally posted by ahammad
    Code:
    m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CSplitMFCView), CSize(1, 1), pContext);
    
    m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CView), CSize(10, 10), pContext);
    I have to say this looks correct (assuming you created your splitter window 2 high and 1 wide).

    Have your tried building it for debug and stepping through this part of the code in the debugger, see if anything obvious is going wrong.

    Comment

    • ahammad
      New Member
      • May 2007
      • 79

      #3
      This is what I did to create the splitter:

      Code:
      (m_wndSplitter.Create(this, 2 , 1, CSize(10, 10), pContext))
      It seems correct to me. I'll try debugging.

      Edit:

      Code:
      m_wndSplitter.SplitRow(350);
      That's where I split horizontally.

      Also, in my main app's CPP, there is this in the initialization:

      Code:
      	CSingleDocTemplate* pDocTemplate;
      	pDocTemplate = new CSingleDocTemplate(
      		IDR_MAINFRAME,
      		RUNTIME_CLASS(CSplitMFCDoc),
      		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
      		RUNTIME_CLASS(CSplitMFCView));
      Could this have something to do with it? The CreateView method does take in a RUNTIM_CLASS variable.

      Comment

      • ahammad
        New Member
        • May 2007
        • 79

        #4
        I think I found out what's wrong. I had placed the CreateView function in OnCreateClient, but at that point, the SplitRow function hasn't been called, so it gave me errors.

        I tried putting the SplitRow function before that but it fails, and I get the two views on top of each other (I verified this by using different colored squares for every view).

        In OnCreateClient of MainFrm.cpp
        Code:
        m_wndSplitter.SplitRow(350);
        m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CSplitMFCView), CSize(100, 100), pContext);
        m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CMyView), CSize(100, 100), pContext);
        Any other ideas?

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Actually (having read the documentation on splitter windows more carefully) I think your problem is that you are calling m_wndSplitter.C reate when you actually need to be calling m_wndSplitter.C reateStatic.

          Create creates a dynamic splitter window, in a dynamic splitter window all panes use the same class (read this).

          CreateStatic - creates a static splitter window, in this case different cases can be different classes.

          below is the working code directly from one of my projects that uses a splitter window to display 2 different views.

          [code=cpp]
          BOOL CMainFrame::OnC reateClient(LPC REATESTRUCT /*lpcs*/,
          CCreateContext* pContext)
          {
          // create splitter window
          if (!m_wndSplitter .CreateStatic(t his, 1, 2))
          return FALSE;

          if (!m_wndSplitter .CreateView(0, 0, RUNTIME_CLASS(C LeftView), CSize(100, 100), pContext) ||
          !m_wndSplitter. CreateView(0, 1, RUNTIME_CLASS(C SBSView), CSize(100, 100), pContext))
          {
          m_wndSplitter.D estroyWindow();
          return FALSE;
          }

          m_wndSplitter.S etColumnInfo(0, 200, 20);

          return TRUE;
          }
          [/code]

          Comment

          • ahammad
            New Member
            • May 2007
            • 79

            #6
            Thanks a lot! This information is great and it helped me fix the issue I had. I'm saving it for future reference.

            Thanks again for your help.

            Comment

            Working...