Understanding Menus

Chapter 24 - Application and Class Wizards

Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
  Copyright 1998 The McGraw-Hill Companies

The Graph Application
In this section, you will learn all of the steps necessary to create a basic application using the AppWizard and ClassWizard tools. This is a mechanical process, requiring that certain steps be completed in a specific order. The steps discussed here will take you through the development of code that will be used to create the first program, named Graph.
If your compiler is up and running, follow the steps along with us as we create this application.
The AppWizard
From the Microsoft Visual C++ menu bar, select the File menu and then the New item from the menu list. As shown in Figure 24-1, a dialog box will appear that will allow you to start a new project by selecting the MFC AppWizard (exe) option.
Figure 24-1: Use file | New to access the MFC AppWizard for a new project
Name the new project Graph, as shown in Figure 24-1. After you have named the project, you can start developing it using the AppWizard. Notice the project location shown in Figure 24-1. Now, simply click on OK to start the AppWizard.
The first step in generating a project with the AppWizard involves making a decision about whether the project will handle single, multiple, or dialog-based documents, as shown in Figure 24-2.
Figure 24-2: Step 1—Select a Single document interface
Single-document interfaces are the simplest, since multiple-document communications will not be required for this example. Make sure the Document/View architecture support option is checked. Accept the default for the resource language option. Click on the Next button to start Step 2, shown in Figure 24-3.
Figure 24-3: Step 2—Select None since no database support is needed
Step 2 is used only when you want to include database support. For this example, None is selected. Click on the Next button to start Step 3, shown in Figure 24-4.
Figure 24-4: Step 3—The project doesn’t require compound document support
Step 3 allows you to specify the type of OLE support: containers or servers. For this example, None is selected. You’ll learn more about this option in Chapter 25. Click on the Next button to start Step 4, shown in Figure 24-5.
Figure 24-5: Step 4—Allows special application features to be added
Step 4 gives you the opportunity to add special features to the project. For example, a toolbar or status bar could be added at this point. In our first example, however, no special features are needed. Click on the Next button to start Step 5, shown in Figure 24-6.
Figure 24-6: Step 5—Allows the MFC project type, inclusion of source comments, and the identification of the MFC library
Select the options shown in Figure 24-6 for Step 5. Now, click the Next button to start Step 6 as Figure 24-7.
Figure 24-7: Step 6—Allows a review of the classes to be generated by the AppWizard
Step 6 is the final step used to specify project features. Here, you will see a listing of the new classes that the AppWizard will automatically generate. The four classes that will be created for this application are CGraphApp, CMainFrame, CGraphDoc, and CGraphView.
If you select CGraphView in the list box, shown in Figure 24-7, the Base class list box will expand so that you can specify whether you want the CGraphView class to be derived from the CEditView, CFormView, CScrollView, or CView base class.
The CView class, derived from the CWnd class, is used to create the base for user-defined view classes. A view serves as a buffer between the document and the user, and is actually a child of a frame window. It produces an image of the document on the screen or on the printer and uses input from the keyboard or the mouse as an operation on the document.
Two of the classes mentioned above, CFormView and CEditView, are derived from the CView base class. CFormView describes a scrollable view that is based on a dialog template resource and includes dialog box controls. CEditView describes a text editor. CEditView is used in the second application developed in this chapter.
The Graph application will use CView as the base class. As a matter of fact, all of the default classes shown in the Base class list box are acceptable. Click on the Finish button and see a description summary of what the AppWizard will create for this project. Figure 24-8 shows the information for this project.
Figure 24-8: The AppWizard provides a summary of what will be createc for the profect
The information displayed in this dialog box is a summary of your choices, and this box offers you one last chance to make alterations before the template code is generated. If the options are correct, click the OK button to generate the code.
The various files—and there seems to be quite a few of them—will be generated and stored in the subdirectory specified at the beginning of the project.
After the code has been generated, you can add additional features to the project code by selecting ClassWizard using the View menu and selecting the ClassWizard… menu item, as shown in Figure 24-9.
Figure 24-9: The base code generated by the AppWizard can be customized by using the ClassWizard
Our Graph example will eventually draw some simple graphics to the client area. Therefore, the application must be able to process WM_PAINT messages. The message handler can be added with the ClassWizard.
The ClassWizard
The ClassWizard generates additional code for the application. This code can be used to support the processing of messages such as WM_PAINT, WM_MOUSEMOVE, and so forth. The ClassWizard, as mentioned in the previous section, is started from the View menu by selecting the ClassWizard menu item. Figure 24-10 shows the initial ClassWizard dialog box.
In this application, an OnPaint( ) member function will be added to our program code to process WM_PAINT messages. To add this support code, select CGraphView in the Class name text entry box. From the Object IDs list box, choose CGraphView, as shown in Figure 24-10.
Figure 24-10: The initial ClassWizard dialog box with the WM_Paint message handler added to the project
When CGraphView is selected, a list of messages will be shown in the Messages list box. When the WM_PAINT message is selected from the Messages list box, the OnPaint( ) member function will be shown in the Member functions list.
The GRAPHVIEW.CPP file will now contain this inserted code, as shown in Figure 24-11.
Figure 24-11: The OnPaint() member function has been added to the project
At this point, various graphics functions can be added to this member function to make this application unique. You’ll see how this is done before we conclude this example.
The next step is to compile and test the basic application.
Building the Application
When all of the message handlers have been added to the program’s code with the ClassWizard, the application can be compiled and linked. Select the Rebuild All menu item from the compiler’s Build menu, as shown in Figure 24-12.
Figure 24-12: Selecting Rebuild All to compile and link the project code
During the build operation, details of the operation are displayed to the screen. Figure 24-13 shows the steps performed in the compile and link process for this application.
Figure 24-13: During the build operation, the compile and link steps can be viewed
Notice in particular that four source code files—GRAPH.CPP, MAINFRM.CPP, GRAPHDOC.CPP, and GRAPHVIEW.CPP—will be compiled and then linked. In terms of sheer numbers, these four files are just the tip of the iceberg. When compilation is complete, examine the subdirectory in which these files are stored; you’ll see more than 30 files stored there. Automation has its price!
An executable file is also present in the appropriate subdirectory. Execute the program. Your screen should look something like Figure 24-14.
Figure 24-14: The window for the initial Graph project
The initial screen is empty because no graphics functions have been added at this point. Worse, none of the menu items work, with the exception of the About box from the Help menu. This is because the code for processing these messages must be added by you—it is not automatically generated. However, if you have gained a good understanding of the MFC library from previous chapters, developing this code will not be too difficult. The final example in this chapter will make use of all of these features.
Examining AppWizard Code
The AppWizard, with a little help from the ClassWizard, generated four important C++ files for the initial Graph application. These files were named GRAPH.CPP, MAINFRM.CPP, GRAPHDOC.CPP, and GRAPHVIEW.CPP. Each of these C++ files has an associated header file: GRAPH.H, MAINFRM.H, GRAPHDOC.H, and GRAPHVIEW.H. The header files contain the declarations of the specific classes in each C++ file. The purpose of each C++ file will be examined in the following sections.
The GRAPH.CPP File
The GRAPH.CPP file, shown here, serves as the main file for the application. It contains the CGraphApp class.
// Graph.cpp : Defines class behaviors for the application.
//

#include “stdafx.h”
#include “Graph.h”

#include “MainFrm.h”
#include “GraphDoc.h”
#include “GraphView.h”
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//////////////////////////////////////////////////////////////
// CGraphApp

BEGIN_MESSAGE_MAP(CGraphApp, CWinApp)
 //{{AFX_MSG_MAP(CGraphApp)
 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
   // NOTE - the ClassWizard will add and remove mapping
   // macros here.
   //    DO NOT EDIT what you see in these blocks of
   // generated code!
 //}}AFX_MSG_MAP
 // Standard file based document commands
 ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
 ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

//////////////////////////////////////////////////////////////
// CGraphApp construction

CGraphApp::CGraphApp()
{
 // TODO: add construction code here,
 // Place all significant initialization in InitInstance
}
//////////////////////////////////////////////////////////////
// The one and only CGraphApp object

CGraphApp theApp;

//////////////////////////////////////////////////////////////
// CGraphApp initialization

BOOL CGraphApp::InitInstance()
{
 // Standard initialization
 // If you are not using these features and wish to reduce
 // the size of your final executable, you should remove
 // from the following the specific initialization routines
 // you do not need.

 // Change the registry key under which our settings are
 // stored.  You should modify this string to be something
 // appropriate  such as the name of your company or
 // organization.
 SetRegistryKey(_T(“Local AppWizard-Generated Applications”));

 LoadStdProfileSettings();  // Load INI file options
                            // (including MRU)
 // Register the application’s document templates.  Document
 // templates  serve as the connection between documents,
 // frame windows and views.

 CSingleDocTemplate* pDocTemplate;
 pDocTemplate = new CSingleDocTemplate(
   IDR_MAINFRAME,
   RUNTIME_CLASS(CGraphDoc),
   RUNTIME_CLASS(CMainFrame),       // main SDI frame window
   RUNTIME_CLASS(CGraphView));
 AddDocTemplate(pDocTemplate);

 // Parse command line for shell commands, DDE, file open
 CCommandLineInfo cmdInfo;
 ParseCommandLine(cmdInfo);

 // Dispatch commands specified on the command line
 if (!ProcessShellCommand(cmdInfo))
   return FALSE;

 // The one and only window is initialized - show and update.
 m_pMainWnd->ShowWindow(SW_SHOW);
 m_pMainWnd->UpdateWindow();

 return TRUE;
}

//////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
 CAboutDlg();

// Dialog Data
 //{{AFX_DATA(CAboutDlg)
 enum { IDD = IDD_ABOUTBOX };
 //}}AFX_DATA
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CAboutDlg)
 protected:
 virtual void DoDataExchange(CDataExchange* pDX);    
 //}}AFX_VIRTUAL

// Implementation
protected:
 //{{AFX_MSG(CAboutDlg)
 // No message handlers
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
 //{{AFX_DATA_INIT(CAboutDlg)
 //}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CAboutDlg)
 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
 //{{AFX_MSG_MAP(CAboutDlg)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CGraphApp::OnAppAbout()
{
 CAboutDlg aboutDlg;
 aboutDlg.DoModal();
}

//////////////////////////////////////////////////////////////
// CGraphApp commands
The message map, near the top of the listing, belongs to the CGraphApp class. This message map specifically links the ID_APP_ABOUT, ID_FILE_NEW, and ID_FILE_OPEN messages with their member functions: OnAppAbout( ), CWinApp::OnFileNew( ), and CWinApp::OnFileOpen( ). Also notice in the listing that a constructor, an initial instance InitInstance( ), and a member function OnAppAbout( ) are implemented.
The About dialog box is derived from the CDialog class. If you examine the lower portion of the code you will notice a message map, a constructor, and a member function CDialog::DoDataExchange( ) for this derived dialog class.
There are no initial CGraphApp commands, as you can see from the end of ‘the listing.
The MAINFRM.CPP File
The MAINFRM.CPP file, shown below, contains the frame class CMainFrame. This class is derived from CFrameWnd and is used to control all single-document-interface (SDI) frame features.
// MainFrm.cpp : implementation of the CMainFrame class
//

#include “stdafx.h”
#include “Graph.h”

#include “MainFrm.h”
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
 //{{AFX_MSG_MAP(CMainFrame)
   // NOTE - the ClassWizard will add and remove mapping
   // macros here.
   //    DO NOT EDIT what you see in these blocks of
   // generated code !
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

//////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
 // TODO: add member initialization code here
 
}
CMainFrame::~CMainFrame()
{
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
 if( !CFrameWnd::PreCreateWindow(cs) )
   return FALSE;
 // TODO: Modify the Window class or styles here by modifying
 //  the CREATESTRUCT cs

 return TRUE;
}
//////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
 CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
 CFrameWnd::Dump(dc);
}

#endif //_DEBUG

//////////////////////////////////////////////////////////////
// CMainFrame message handlers
When you examine this listing, you’ll notice that the message map, constructor, and destructor initially contain no code. The member functions AssertValid( ) and Dump( ) use definitions contained in the parent class. Also note that CMainFrame initially contains no message handlers.
The GRAPHDOC.CPP File
The GRAPHDOC.CPP file, shown here, contains the CGraphDoc class, which is unique to your application. This file is used to hold document data and to load and save files.
// GraphDoc.cpp : implementation of the CGraphDoc class
//

#include “stdafx.h”
#include “Graph.h”

#include “GraphDoc.h”

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGraphDoc

IMPLEMENT_DYNCREATE(CGraphDoc, CDocument)

BEGIN_MESSAGE_MAP(CGraphDoc, CDocument)
 //{{AFX_MSG_MAP(CGraphDoc)
   // NOTE - the ClassWizard will add and remove mapping macros here.
   //    DO NOT EDIT what you see in these blocks of generated
         code!
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGraphDoc construction/destruction

CGraphDoc::CGraphDoc()
{
 // TODO: add one-time construction code here

}
CGraphDoc::~CGraphDoc()
{
}

BOOL CGraphDoc::OnNewDocument()
{
 if (!CDocument::OnNewDocument())
   return FALSE;

 // TODO: add reinitialization code here
 // (SDI documents will reuse this document)

 return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CGraphDoc serialization

void CGraphDoc::Serialize(CArchive& ar)
{
 if (ar.IsStoring())
 {
   // TODO: add storing code here
 }
 else
 {
   // TODO: add loading code here
 }
}

/////////////////////////////////////////////////////////////////////////////
// CGraphDoc diagnostics

#ifdef _DEBUG
void CGraphDoc::AssertValid() const
{
 CDocument::AssertValid();
}
void CGraphDoc::Dump(CDumpContext& dc) const
{
 CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGraphDoc commands
Examine this listing and you will again notice that the message map, constructor, and destructor contain no code. Four member functions can be used to provide vital document support. OnNewDocument( ) uses the definition provided by the parent class. Serialize( ) supports persistent objects. Our second programming example will use this member function to help with file I/O. The member functions AssertValid( ) and Dump( ) use definitions contained in the parent class. There are no initial CGraphDoc commands.
The GRAPHVIEW.CPP File
The GRAPHVIEW.CPP file, shown here, provides the view of the document. In this implementation, CGraphView is derived from the CView class. CGraphView objects are used to view CGraphDoc objects.
// GraphView.cpp : implementation of the CGraphView class
//

#include “stdafx.h”
#include “Graph.h”

#include “GraphDoc.h”
#include “GraphView.h”

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//////////////////////////////////////////////////////////////
// CGraphView

IMPLEMENT_DYNCREATE(CGraphView, CView)

BEGIN_MESSAGE_MAP(CGraphView, CView)
 //{{AFX_MSG_MAP(CGraphView)
 ON_WM_PAINT()
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

//////////////////////////////////////////////////////////////
// CGraphView construction/destruction

CGraphView::CGraphView()
{
 // TODO: add construction code here
}

CGraphView::~CGraphView()
{
}

BOOL CGraphView::PreCreateWindow(CREATESTRUCT& cs)
{
 // TODO: Modify the Window class / styles here by modifying
 //  the CREATESTRUCT cs

 return CView::PreCreateWindow(cs);
}

//////////////////////////////////////////////////////////////
// CGraphView drawing

void CGraphView::OnDraw(CDC* pDC)
{
 CGraphDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);

 // TODO: add draw code for native data here
}

//////////////////////////////////////////////////////////////
// CGraphView diagnostics
#ifdef _DEBUG
void CGraphView::AssertValid() const
{
 CView::AssertValid();
}

void CGraphView::Dump(CDumpContext& dc) const
{
 CView::Dump(dc);
}

CGraphDoc* CGraphView::GetDocument() // non-debug version
{
 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGraphDoc)));
 return (CGraphDoc*)m_pDocument;
}
#endif //_DEBUG

//////////////////////////////////////////////////////////////
// CGraphView message handlers

void CGraphView::OnPaint()
{
 CPaintDC dc(this); // device context for painting
 
 // TODO: Add your message handler code here
 
 // Do not call CView::OnPaint() for painting messages
}
Normally, the message map would be empty, but remember that we used the ClassWizard to add ON_WM_PAINT message-handling abilities. The constructor and destructor are empty.
The OnDraw( ) member function uses the pointer pDoc to point to the document. The member functions AssertValid( ) and Dump( ) use definitions contained in the parent class.
The message handler, OnPaint( ), is described at the end of this listing. Simple graphics commands, such as those shown in earlier chapters, can be inserted here.
Drawing in the Client Area
In the initial design phase of the Graph application, a single-document interface (SDI) application was created using the AppWizard and the ClassWizard. The view class was derived from the parent class, CView. Recall that the ClassWizard allowed us to add the WM_PAINT message handler to this code.
This is the perfect platform from which to draw simple graphics to the client area with very little additional work. To see how easy this can be, add the following code to the OnPaint( ) message handler shown in the previous listing:
// CGraphView message handlers

void CGraphView::OnPaint( )
{
 static DWORD dwColor[9]={RGB(0,0,0),         //black
                          RGB(255,0,0),       //red
                          RGB(0,255,0),       //green
                          RGB(0,0,255),       //blue
                          RGB(255,255,0),     //yellow
                          RGB(255,0,255),     //magenta
                          RGB(0,255,255),     //cyan
                          RGB(127,127,127),   //gray
                          RGB(255,255,255)};  //white

 POINT polylpts[4],polygpts[5];
 int xcoord;

 CBrush newbrush;
 CBrush* oldbrush;
 CPen newpen;
 CPen* oldpen;  
 
 CPaintDC dc(this); // device context for painting        

 // draws and fills a red ellipse
 newpen.CreatePen(PS_SOLID,1,dwColor[1]);
 oldpen=dc.SelectObject(&newpen);
 newbrush.CreateSolidBrush(dwColor[1]);
 oldbrush=dc.SelectObject(&newbrush);
 dc.Ellipse(275,300,200,250);
 dc.TextOut(220,265,"ellipse",7);
 dc.SelectObject(oldbrush);
 newbrush.DeleteObject( );
 dc.SelectObject(oldpen);
 newpen.DeleteObject( );
 // draws and fills a blue circle with ellipse function
 newpen.CreatePen(PS_SOLID,1,dwColor[3]);
 oldpen=dc.SelectObject(&newpen);
 newbrush.CreateSolidBrush(dwColor[3]);
 oldbrush=dc.SelectObject(&newbrush);
 dc.Ellipse(375,75,525,225);
 dc.TextOut(435,190,"circle",6);    
 dc.SelectObject(oldbrush);
 newbrush.DeleteObject( );
 dc.SelectObject(oldpen);
 newpen.DeleteObject( );

 // draws several green pixels
 for(xcoord=400;xcoord<450;xcoord+=5)
   dc.SetPixel(xcoord,350,0L);
 dc.TextOut(460,345,"<- pixels",9);

 // draws a wide black diagonal line
 newpen.CreatePen(PS_SOLID,6,dwColor[0]);
 oldpen=dc.SelectObject(&newpen);
 dc.MoveTo(20,20);
 dc.LineTo(100,100);
 dc.TextOut(60,20,"<- diagonal line",16);  
 dc.SelectObject(oldpen);
 newpen.DeleteObject( );

 // draws a blue arc
 newpen.CreatePen(PS_DASH,1,dwColor[3]);
 oldpen=dc.SelectObject(&newpen);
 dc.Arc(25,125,175,225,175,225,100,125);
 dc.TextOut(50,150,"small arc ->",12);   
 dc.SelectObject(oldpen);
 newpen.DeleteObject( );
 // draws a wide green chord
 newpen.CreatePen(PS_SOLID,8,dwColor[2]);
 oldpen=dc.SelectObject(&newpen);
 dc.Chord(125,125,275,225,275,225,200,125);
 dc.TextOut(280,150,"<- chord",8);
 dc.SelectObject(oldpen);
 newpen.DeleteObject( );

 // draws a black pie slice and fills with green
 newpen.CreatePen(PS_SOLID,1,dwColor[0]);
 oldpen=dc.SelectObject(&newpen);
 newbrush.CreateSolidBrush(dwColor[2]);
 oldbrush=dc.SelectObject(&newbrush);
 dc.Pie(200,0,300,100,200,50,250,100);
 dc.TextOut(260,80,"<- pie wedge",12);
 dc.SelectObject(oldbrush);
 newbrush.DeleteObject( );
 dc.SelectObject(oldpen);
 newpen.DeleteObject( );

 // draws a black rectangle and fills with gray
 newbrush.CreateSolidBrush(dwColor[7]);
 oldbrush=dc.SelectObject(&newbrush);
 dc.Rectangle(25,300,150,375);
 dc.TextOut(50,325,"rectangle",9);
 dc.SelectObject(oldbrush);
 newbrush.DeleteObject( );
 
 // draws a black rounded rectangle and fills with blue
 newbrush.CreateHatchBrush(HS_CROSS,dwColor[3]);
 oldbrush=dc.SelectObject(&newbrush);
 dc.RoundRect(350,250,400,290,20,20);
 dc.TextOut(410,270,"
 rectangle",20);
 dc.SelectObject(oldbrush);
 newbrush.DeleteObject( );

 // draws several wide magenta lines with polyline
 newpen.CreatePen(PS_SOLID,3,dwColor[5]);
 oldpen=dc.SelectObject(&newpen);
 polylpts[0].x=10;
 polylpts[0].y=30;
 polylpts[1].x=10;
 polylpts[1].y=100;
 polylpts[2].x=50;
 polylpts[2].y=100;
 polylpts[3].x=10;
 polylpts[3].y=30;
 dc.Polyline(polylpts,4);
 dc.TextOut(10,110,"polyline",8);  
 dc.SelectObject(oldpen);
 newpen.DeleteObject( );
 // draws a wide cyan polygon and
 // fills with diagonal yellow
 newpen.CreatePen(PS_SOLID,4,dwColor[6]);
 oldpen=dc.SelectObject(&newpen);
 newbrush.CreateHatchBrush(HS_FDIAGONAL,dwColor[4]);
 oldbrush=dc.SelectObject(&newbrush);
 polygpts[0].x=40;
 polygpts[0].y=200;
 polygpts[1].x=100;
 polygpts[1].y=270;
 polygpts[2].x=80;
 polygpts[2].y=290;
 polygpts[3].x=20;
 polygpts[3].y=220;
 polygpts[4].x=40;
 polygpts[4].y=200;
 dc.Polygon(polygpts,5);
 dc.TextOut(80,230,"<- polygon",10);
 dc.SelectObject(oldbrush);
 newbrush.DeleteObject( );
 dc.SelectObject(oldpen);
 newpen.DeleteObject( );
 
// Do not call CView::OnPaint( ) for painting messages
}
This should be familiar code since it employs simple GDI graphics functions. Compile and execute the revised version of this application. Your screen should be similar to the one shown in Figure 24-15.
Figure 24-15: Graphics shapes are drawn in the client area of  the Graph application
The AppWizard generated a template with a menu bar containing the File, Edit, and Help menus, along with the various graphics shapes. The default About box is viewed from the Help menu, as shown in Figure 24-16.
Figure 24-16: The default About box is viewed from the Help menu
Remember that the other menus and menu items are not functional. Why? Because no additional code was added to the template to handle those responses.
If you diligently went through the AppWizard’s template and removed code not used by this application, you would arrive at a static template very similar to the one we created and used in Chapter 23.
The next example will use an entirely new AppWizard template to generate a simple text editor. Enhancements will be made to the template code to add additional functionality to the application.

Books24x7.com, Inc 2000 –  


Visual C++ 6(c) The Complete Reference
Visual Studio 6: The Complete Reference
ISBN: B00007FYGA
EAN: N/A
Year: 1998
Pages: 207

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net