The EX23B Example—An SDI Application

This SDI "Hello, world!" example builds on the code you saw way back in Chapter 2. The application has only one window, an object of a class derived from CFrameWnd. All drawing occurs inside the frame window and all messages are handled there.

  1. Run AppWizard to produce \vcpp32\ex23b\ex23b. Select the Single Document option in the AppWizard Step 1 dialog and uncheck the Document/View Architecture Support? option, as shown here.

    Click to view at full size.

  2. Add code to paint in the dialog. Add the following boldface code to the CChildView::OnPaint function in the ChildView.cpp source code file:

    void CChildView::OnPaint() 
    {
        CPaintDC dc(this); // device context for painting
    
        dc.TextOut(0, 0, "Hello, world!");
    
        // Do not call CWnd::OnPaint() for painting messages
    }
    

  3. Compile and run. You now have a complete SDI application that has no dependencies on the document-view architecture.

AppWizard automatically takes out dependencies on the document-view architecture and generates an application for you with the following elements:

There are several interesting features in the SDI application that have no document-view support, including: