![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Fast Track Visual C++ 6.0 Programming
Weve used view hints to redraw only the changed line. In this way, were able to coordinate views in a smart way. Lets look at one last topic: using the documents modified flag. This is the flag you set when the user modifies the document so the program prompts the user if he or she exits without saving the document. Setting the Documents Modified FlagSetting the documents modified flag is easy: We use the documents SetModifiedFlag() function as shown in the following example: void CMDIView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CMDIDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(nChar != '\r'){ pDoc->text[pDoc->number_lines] += nChar; Invalidate(); } else{ pDoc->number_lines++; } pDoc->UpdateAllViews(this, (long) pDoc->number_lines, NULL); pDoc->SetModifiedFlag(); ⇐ CView::OnChar(nChar, nRepCnt, nFlags); }
If users quit without saving a modified document, the program prompts them to save the document (we add file handling to our program soon), as shown in Figure 2.4. That completes our first MDI program. Here, weve set up an MDI program, supported multiple documents and views, coordinated multiple views, used view hints, and made use of the documents modified flag. Our program is a success. MDIDoc.h and MDIDoc.cpp appear in Listing 2.1, and MDIView.h and MDIView.cpp appear in Listing 2.2. Listing 2.1 MDIDoc.h and MDIDoc.cpp // MDIDoc.h : interface of the CMDIDoc class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_MDIDOC_H__81CAFB2D_9C82_11D1_887F_D42B07C10710__INCLUDED_) #define AFX_MDIDOC_H__81CAFB2D_9C82_11D1_887F_D42B07C10710__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 const MAX_LINES = 1000; class CMDIDoc : public CDocument { protected: // create from serialization only CMDIDoc(); DECLARE_DYNCREATE(CMDIDoc) // Attributes public: int number_lines; CString text[MAX_LINES]; // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMDIDoc) public: virtual BOOL OnNewDocument(); virtual void Serialize(CArchive& ar); //}}AFX_VIRTUAL // Implementation public: virtual ~CMDIDoc(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: //{{AFX_MSG(CMDIDoc) // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_MDIDOC_H__81CAFB2D_9C82_11D1_887F_D42B07C10710__INCLUDED_) // MDIDoc.cpp : implementation of the CMDIDoc class // #include "stdafx.h" #include "MDI.h" #include "MDIDoc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMDIDoc IMPLEMENT_DYNCREATE(CMDIDoc, CDocument) BEGIN_MESSAGE_MAP(CMDIDoc, CDocument) //{{AFX_MSG_MAP(CMDIDoc) // 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() ///////////////////////////////////////////////////////////////////////////// // CMDIDoc construction/destruction CMDIDoc::CMDIDoc() { // TODO: add one-time construction code here number_lines = 0; } CMDIDoc::~CMDIDoc() { } BOOL CMDIDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: add reinitialization code here // (SDI documents will reuse this document) return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMDIDoc serialization void CMDIDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CMDIDoc diagnostics #ifdef _DEBUG void CMDIDoc::AssertValid() const { CDocument::AssertValid(); } void CMDIDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMDIDoc commands
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |