Add Splitter Windows to Scribble

Adding splitter windows to Scribble requires two simple procedures:

  1. Add the member variable m_wndSplitter to class CChildFrame.

  2. Add the member function OnCreateClient to class CChildFrame.

After these procedures, you can build and run Scribble to test the splitter window functionality.

Suggested Reading in the Microsoft Foundation Class Reference

Optional Exercise   When you select the splitter window option from AppWizard, AppWizard also generates a menu item, which the user can use instead of directly selecting the split box. To duplicate this feature, create a Split item on Scribble’s Window menu, and assign it an ID of ID_WINDOW_SPLIT. There’s no need to create a handler for it—the framework handles it automatically.

To declare the CSplitterWnd member variable

  1. In ClassView, point to the CChildFrame class icon and click the right mouse button.

  2. From the pop-up menu, click Add Member Variable.

    The Add Member Variable dialog box appears.

  3. In the Variable Type edit box, type: CSplitterWnd.

  4. In the Variable Declaration edit box, type: m_wndSplitter.

  5. In the Access area, click Protected.

  6. Click OK.

    You can view the new variable in ClassView under the CChildFrame class.

To add the OnCreateClient member function

  1. Use WizardBar to open ChildFrm.cpp in the text editor.

  2. Click the arrow on the action button, located on the right end of WizardBar.

  3. On the menu, click Add Virtual Function.

    The New Virtual Override dialog box appears.

  4. From the New Virtual Functions list, select OnCreateClient.

  5. Click Add and Edit.

  6. Replace the //TODO comments with the following code:
    return m_wndSplitter.Create(this,
    2, 2,       // TODO: adjust the number of rows, columns
    CSize(10, 10),  // TODO: adjust the minimum pane size
    pContext);
    
  7. Save your work.

    You can view the new function in ClassView under the CChildFrame class.

In OnCreateClient, the frame window creates the window that will cover its client area by calling the Create function of its CSplitterWnd member variable. The following parameters passed to the Create function describe the panes that the splitter window will manage:

The Create function accepts two additional arguments:

Because Scribble doesn't pass any values for these, the default values are used.