按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
#0013 // CScribbleDoc
#0014
#0015 IMPLEMENT_DYNCREATE(CScribbleDoc; CDocument)
#0016
#0017 BEGIN_MESSAGE_MAP(CScribbleDoc; CDocument)
#0018 //{{AFX_MSG_MAP(CScribbleDoc)
#0019 // NOTE the ClassWizard will add and remove mapping macros here。
#0020 // DO NOT EDIT what you see in these blocks of generated code!
#0021 //}}AFX_MSG_MAP
#0022 END_MESSAGE_MAP()
#0023
#0024 /////////////////////////////////////////////////////////////////
477
…………………………………………………………Page 540……………………………………………………………
第篇 深入 MFC 程式設計
#0025 // CScribbleDoc construction/destruction
#0026
#0027 CScribbleDoc::CScribbleDoc()
#0028 {
#0029 // TODO: add one…time construction code here
#0030
#0031 }
#0032
#0033 CScribbleDoc::~CScribbleDoc()
#0034 {
#0035 }
#0036
#0037 BOOL CScribbleDoc::OnNewDocument()
#0038 {
#0039 if (!CDocument::OnNewDocument())
#0040 return FALSE;
#0041 InitDocument();
#0042 return TRUE;
#0043 }
#0044
#0045 /////////////////////////////////////////////////////////////////
#0046 // CScribbleDoc serialization
#0047
#0048 void CScribbleDoc::Serialize(CArchive& ar)
#0049 {
#0050 if (ar。IsStoring())
#0051 {
#0052 }
#0053 else
#0054 {
#0055 }
#0056 m_strokeList。Serialize(ar);
#0057 }
#0058
#0059 /////////////////////////////////////////////////////////////////
#0060 // CScribbleDoc diagnostics
#0061
#0062 #ifdef _DEBUG
#0063 void CScribbleDoc::AssertValid() const
#0064 {
#0065 CDocument::AssertValid();
#0066 }
#0067
#0068 void CScribbleDoc::Dump(CDumpContext& dc) const
#0069 {
#0070 CDocument::Dump(dc);
#0071 }
#0072 #endif //_DEBUG
478
…………………………………………………………Page 541……………………………………………………………
第8章 Document…View 深入探討
#0073
#0074 /////////////////////////////////////////////////////////////////
#0075 // CScribbleDoc mands
#0076
#0077 BOOL CScribbleDoc::OnOpenDocument(LPCTSTR lpszPathName)
#0078 {
#0079 if (!CDocument::OnOpenDocument(lpszPathName))
#0080 return FALSE;
#0081 InitDocument();
#0082 return TRUE;
#0083 }
#0084
#0085 void CScribbleDoc::DeleteContents()
#0086 {
#0087 while (!m_strokeList。IsEmpty())
#0088 {
#0089 delete m_strokeList。RemoveHead();
#0090 }
#0091 CDocument::DeleteContents();
#0092 }
#0093
#0094 void CScribbleDoc::InitDocument()
#0095 {
#0096 m_nPenWidth = 2; // default 2 pixel pen width
#0097 // solid; black pen
#0098 m_penCur。CreatePen(PS_SOLID; m_nPenWidth; RGB(0;0;0));
#0099 }
#0100
#0101 CStroke* CScribbleDoc::NewStroke()
#0102 {
#0103 CStroke* pStrokeItem = new CStroke(m_nPenWidth);
#0104 m_strokeList。AddTail(pStrokeItem);
#0105 SetModifiedFlag(); // Mark the document as having been modified; for
#0106 // purposes of confirming File Close。
#0107 return pStrokeItem;
#0108 }
#0109
#0110
#0111
#0112
#0113 ////////////////////////////////////////////////////////////////
#0114 // CStroke
#0115
#0116 IMPLEMENT_SERIAL(CStroke; CObject; 1)
#0117 CStroke::CStroke()
#0118 {
#0119 // This empty constructor should be used by serialization only
#0120 }
479
…………………………………………………………Page 542……………………………………………………………
第篇 深入 MFC 程式設計
#0121
#0122 CStroke::CStroke(UINT nPenWidth)
#0123 {
#0124 m_nPenWidth = nPenWidth;
#0125 }
#0126
#0127 void CStroke::Serialize(CArchive& ar)
#0128 {
#0129 if (ar。IsStoring())
#0130 {
#0131 ar 》 w;
#0138 m_nPenWidth = w;
#0139 m_pointArray。Serialize(ar);
#0140 }
#0141 }
#0142