友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!阅读过程发现任何错误请告诉我们,谢谢!! 报告错误
一世书城 返回本书目录 我的书架 我的书签 TXT全本下载 进入书吧 加入书签

深入浅出MFC第2版(PDF格式)-第218章

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!



                   #0043          if (!CDocument::OnNewDocument()) 

                   #0044                  return FALSE; 

                   #0045          InitDocument(); 

                   #0046          return TRUE; 

                   #0047  } 

                   #0048 

                   #0049  ///////////////////////////////////////////////////////////////// 

                   #0050  // CScribbleDoc serialization 

                   #0051 

                   #0052  void CScribbleDoc::Serialize(CArchive& ar) 

                   #0053  { 

                   #0054          if (ar。IsStoring()) 

                   #0055          { 

                   #0056                  ar 》 m_sizeDoc; 

                   #0061          } 

                   #0062          m_strokeList。Serialize(ar); 

                   #0063  } 

                   #0064 

                   #0065  //////////////////////////////////////////////////////////////// 

                   #0066  // CScribbleDoc diagnostics 

                   #0067 

                   #0068  #ifdef _DEBUG 

                   #0069  void CScribbleDoc::AssertValid() const 

                   #0070  { 

                   #0071          CDocument::AssertValid(); 

                   #0072  } 

                   #0073 

                   #0074  void CScribbleDoc::Dump(CDumpContext& dc) const 

                   #0075  { 

                   #0076          CDocument::Dump(dc); 

                   #0077  } 

                   #0078  #endif //_DEBUG 



888 


…………………………………………………………Page 951……………………………………………………………

                                                   附錄B    Scribble Step5  完整原始碼 



#0079 

#0080  ///////////////////////////////////////////////////////////////// 

#0081  // CScribbleDoc mands 

#0082 

#0083  BOOL CScribbleDoc::OnOpenDocument(LPCTSTR lpszPathName) 

#0084  { 

#0085          if (!CDocument::OnOpenDocument(lpszPathName)) 

#0086                  return FALSE; 

#0087          InitDocument(); 

#0088          return TRUE; 

#0089  } 

#0090 

#0091  void CScribbleDoc::DeleteContents() 

#0092  { 

#0093          while (!m_strokeList。IsEmpty()) 

#0094          { 

#0095                  delete m_strokeList。RemoveHead(); 

#0096          } 

#0097          CDocument::DeleteContents(); 

#0098  } 

#0099 

#0100  void CScribbleDoc::InitDocument() 

#0101  { 

#0102          m_bThickPen = FALSE; 

#0103          m_nThinWidth = 2;   // default thin pen is 2 pixels wide 

#0104          m_nThickWidth = 5;  // default thick pen is 5 pixels wide 

#0105          ReplacePen();      // initialize pen according to current width 

#0106 

#0107          // default document size is 800 x 900 screen pixels 

#0108          m_sizeDoc = CSize(800;900); 

#0109  } 

#0110 

#0111  CStroke* CScribbleDoc::NewStroke() 

#0112  { 

#0113          CStroke* pStrokeItem = new CStroke(m_nPenWidth); 

#0114          m_strokeList。AddTail(pStrokeItem); 

#0115          SetModifiedFlag();  // Mark the document as having been modified; for 

#0116                                 // purposes of confirming File Close。 

#0117          return pStrokeItem; 

#0118  } 

#0119 

#0120 

#0121 

#0122 

#0123  ///////////////////////////////////////////////////////////////// 

#0124  // CStroke 



                                                                                      889 


…………………………………………………………Page 952……………………………………………………………

                   第五篇    附錄  



                   #0125 

                   #0126  IMPLEMENT_SERIAL(CStroke; CObject; 2) 

                   #0127  CStroke::CStroke() 

                   #0128  { 

                   #0129          // This empty constructor should be used by serialization only 

                   #0130  } 

                   #0131 

                   #0132  CStroke::CStroke(UINT nPenWidth) 

                   #0133  { 

                   #0134          m_nPenWidth = nPenWidth; 

                   #0135          m_rectBounding。SetRectEmpty(); 

                   #0136  } 

                   #0137 

                   #0138  void CStroke::Serialize(CArchive& ar) 

                   #0139  { 

                   #0140          if (ar。IsStoring()) 

                   #0141          { 

                   #0142                  ar  m_rectBounding; 

                   #0149                  WORD w; 

                   #0150                  ar 》》 w; 

                   #0151                  m_nPenWidth = w; 

                   #0152                  m_pointArray。Serialize(ar); 

                   #0153          } 

                   #0154  } 

                   #0155 

                   #0156  BOOL CStroke::DrawStroke(CDC* pDC) 

                   #0157  { 

                   #0158          CPen penStroke; 

                   #0159          if (!penStroke。CreatePen(PS_SOLID; m_nPenWidth; RGB(0;0;0))) 

                   #0160                  return FALSE; 

                   #0161          CPen* pOldPen = pDC…》SelectObject(&penStroke); 

                   #0162          pDC…》MoveTo(m_pointArray'0'); 

                   #0163          for (int i=1; i 《 m_pointArray。GetSize(); i++) 

                   #0164          { 

                   #0165                  pDC…》LineTo(m_pointArray'i'); 

                   #0166          } 

                   #0167 

                   #0168          pDC…》SelectObject(pOldPen); 

                   #0169          return TRUE; 

                   #0170  } 



890 


…………………………………………………………Page 953……………………………………………………………

                                                   附錄B    Scribble Step5  完整原始碼 



#0171  void CScribbleDoc::OnEditClearAll() 

#0172  { 

#0173          DeleteContents(); 

#0174          SetModifiedFlag();  // Mark the document as having been modified; for 

#0175                                 // purposes of confirming File Close。 

#0176          UpdateAllViews(NULL); 

#0177  } 

#0178 

#0179  void CScribbleDoc::OnPenThickOrThin() 

#0180  { 

#0181          // Toggle the state of the pen between thin or thick。 

#0182          m_bThickPen = !m_bThickPen; 

#0183 

#0184          // Change the current pen to reflect the new user…specified width。 

#0185          ReplacePen(); 

#0186  } 

#0187 

#0188  void CScribbleDoc::ReplacePen() 

#0189  { 

#0190          m_nPenWidth = m_bThickPen? m_nThickWidth : m_nThinWidth; 

#0191 

#0192          // Change the current pen to reflect the new user…specified width。 

#0193          m_penCur。DeleteObject(); 

#0194          m_penCur。CreatePen(PS_SOLID; m_nPenWidth; RGB(0;0;0)); // solid black 

#0195  } 

#0196 

#0197  void CScribbleDoc::OnUpdateEditClearAll(CCmdUI* pCmdUI) 

#0198  { 

#0199          // Enable the mand user interface object (menu item or tool bar 

#0200          // button) if the document is non…empty; i。e。; has at least one stroke。 

#0201          pCmdUI…》Enable(!m_strokeList。IsEmpty()); 

#0202  } 

#0203 

#0204  void CScribbleDoc::OnUpdatePenThickOrThin(CCmdUI* pCmdUI) 

#0205  { 

#0206          // Add check mark to Draw Thick Line menu item; if the current 

#0207          // pen width is 〃thick〃。 

#0208          pCmdUI…》SetCheck(m_bThickPen); 

#0209  } 

#0210 

#0211  void CScribbleDoc::OnPenWidths() 

#0212  { 

#0213          CPenWidthsDlg dlg; 

#0214          // Ini
返回目录 上一页 下一页 回到顶部 0 1
未阅读完?加入书签已便下次继续阅读!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!