友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!
富士康小说网 返回本书目录 加入书签 我的书架 我的书签 TXT全本下载 『收藏到我的浏览器』

深入浅出MFC第2版(PDF格式)-第116部分

快捷操作: 按键盘上方向键 ← 或 → 可快速上下翻页 按键盘上的 Enter 键可回到本书目录页 按键盘上方向键 ↑ 可回到本页顶部! 如果本书没有阅读完,想下次继续接着阅读,可使用上方 "收藏到我的浏览器" 功能 和 "加入书签" 功能!



#0038          DECLARE_MESSAGE_MAP() 

#0039  }; 



CHILDFRM。CPP 



#0001  #include 〃stdafx。h〃 

#0002  #include 〃Scribble。h〃 

#0003 

#0004  #include 〃ChildFrm。h〃 

#0005 

#0006  #ifdef _DEBUG 

#0007  #define new DEBUG_NEW 

#0008  #undef THIS_FILE 

#0009  static char THIS_FILE'' = __FILE__; 

#0010  #endif 

#0011 

#0012  ///////////////////////////////////////////////////////////////// 

#0013  // CChildFrame 

#0014 

#0015  IMPLEMENT_DYNCREATE(CChildFrame; CMDIChildWnd) 

#0016 

#0017  BEGIN_MESSAGE_MAP(CChildFrame; CMDIChildWnd) 

#0018          //{{AFX_MSG_MAP(CChildFrame) 

#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  //////////////////////////////////////////////////////////////// 

#0025  // CChildFrame construction/destruction 

#0026 

#0027  CChildFrame::CChildFrame() 

#0028  { 

#0029          // TODO: add member initialization code here 

#0030 

#0031  } 

#0032 



                                                                                     883 


…………………………………………………………Page 946……………………………………………………………

                    第五篇    附錄  



                    #0033  CChildFrame::~CChildFrame() 

                    #0034  { 

                    #0035  } 

                    #0036 

                    #0037  BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) 

                    #0038  { 

                    #0039          // TODO: Modify the Window class or styles here by modifying 

                    #0040          //  the CREATESTRUCT cs 

                    #0041 

                    #0042          return CMDIChildWnd::PreCreateWindow(cs); 

                    #0043  } 

                    #0044 

                    #0045  ///////////////////////////////////////////////////////////////// 

                    #0046  // CChildFrame diagnostics 

                    #0047 

                    #0048  #ifdef _DEBUG 

                    #0049  void CChildFrame::AssertValid() const 

                    #0050  { 

                    #0051          CMDIChildWnd::AssertValid(); 

                    #0052  } 

                    #0053 

                    #0054  void CChildFrame::Dump(CDumpContext& dc) const 

                    #0055  { 

                    #0056          CMDIChildWnd::Dump(dc); 

                    #0057  } 

                    #0058 

                    #0059  #endif //_DEBUG 

                    #0060 

                    #0061  //////////////////////////////////////////////////////////////// 

                    #0062  // CChildFrame message handlers 

                    #0063 

                    #0064  BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT /* lpcs */; 

                                                                   CCreateContext* pContext) 

                    #0065  { 

                    #0066          return m_wndSplitter。Create(this; 

                    #0067                  2; 2;       // TODO: adjust the number of rows; columns 

                    #0068                  CSize(10; 10);  // TODO: adjust the minimum pane size 

                    #0069                  pContext); 

                    #0070  } 



                    SCRIBBLEDOC。H 



                    #0001  ///////////////////////////////////////////////////////////////// 

                    #0002  // class CStroke 

                    #0003  // 

                    #0004  // A stroke is a series of connected points in the scribble drawing。 



884 


…………………………………………………………Page 947……………………………………………………………

                                                    附錄B    Scribble Step5  完整原始碼 



#0005  // A scribble document may have multiple strokes。 

#0006 

#0007  class CStroke : public CObject 

#0008  { 

#0009  public: 

#0010          CStroke(UINT nPenWidth); 

#0011 

#0012  protected: 

#0013          CStroke(); 

#0014          DECLARE_SERIAL(CStroke) 

#0015 

#0016  // Attributes 

#0017  protected: 

#0018          UINT    m_nPenWidth;   // one pen width applies to entire stroke 

#0019  public: 

#0020          CArray  m_pointArray;   // series of connected points 

#0021          CRect   m_rectBounding;  // smallest rect that surrounds all 

#0022                                      // of the points in the stroke 

#0023                                      // measured in MM_LOENGLISH units 

#0024                                      // (0。01 inches; with Y…axis inverted) 

#0025  public: 

#0026          CRect& GetBoundingRect() { return m_rectBounding; } 

#0027 

#0028  // Operations 

#0029  public: 

#0030          BOOL DrawStroke(CDC* pDC); 

#0031          void FinishStroke(); 

#0032 

#0033  public: 

#0034          virtual void Serialize(CArchive& ar); 

#0035  }; 

#0036 

#0037  ///////////////////////////////////////////////////////////////// 

#0038 

#0039  class CScribbleDoc : public CDocument 

#0040  { 

#0041  protected: // create from serialization only 

#0042          CScribbleDoc(); 

#0043          DECLARE_DYNCREATE(CScribbleDoc) 

#0044 

#0045  // Attributes 

#0046  protected: 

#0047          // The document keeps track of the current pen width on 

#0048          // behalf of all views。 We'd like the user interface of 

#0049          // Scribble to be such that if the user chooses the Draw 

#0050          // Thick Line mand; it will apply to all views; not just 



                                                                                       885 


…………………………………………………………Page 948……………………………………………………………

                   第五篇    附錄  



                   #0051          // the view that currently has the focus。 

                   #0052 

                   #0053          UINT     m_nPenWidth;        // current user…selected pen width 

                   #0054          BOOL     m_bThickPen;        // TRUE if current pen is thick 

                   #0055          UINT     m_nThinWidth; 

                   #0056          UINT     m_nThickWidth; 

                   #0057          CPen     m_penCur;           // pen created according to 

                   #0058                                         // user…selected pen style (width) 

                   #0059  public: 

                   #0060          CTypedPtrList     m_strokeList; 

                   #0061          CPen*           GetCurrentPen() { return &m_penCur; } 

                   #0062 

                   #0063  protected: 

                   #0064          CSize           m_sizeDoc; 

                   #0065  public: 

                   #0066          CSize GetDocSize() { return m_sizeDoc; } 

                   #0067 

                   #0068  // Operations 

                   #0069  public: 

                   #0070          CStroke* NewStroke(); 

                   #0071 

                   #0072  // Overrides 

                   #0073          // ClassWizard generated virtual function overrides 

                   #0074          //{{AFX_VIRTUAL(CScribbleDoc) 

                   #0075          public: 

                   #0076          virtual BOOL OnNewDocument(); 

                   #0077          virtual void Serialize(CArchive& ar); 

                   #0078          virtual BOOL OnOpenDocument(LPCTSTR lpszPathName); 

                   #0079          virtual void DeleteContents(); 

                   #0080          //}}AFX_VIRTUAL 

                   #0081 

                   #0082  // Implementation 

                   #0083  protected: 

                   #0084          void ReplacePen(); 

                   #0085 

                   #0086  public: 

                   #0087          virtual ~CScribbleDoc(); 

                   #0088  #ifdef _DEBUG 

                   #0089          virtual void AssertValid() const; 

                   #0090          virtual void Dump(CDumpContext& dc) const; 

                   #0091  #endif 

                   #0092 

                   #0093  protected: 

                   #0094          void            InitDocument(); 

                   #0095 

                   #0096  // Generated message map functions 



886 


…………………………………………………………Page 949……………………………………………………………

                                                   附錄B    Scribble Step5  完整原始碼 



#0097  protected: 

#0098          //{{AFX_MSG(CScribbleDoc) 

#0099          afx_msg void OnEditClearAll(); 

#0100          afx_msg void OnPenThickOrThin(); 

#0101          afx_msg void OnUpdateEditClearAll(CCmdUI* pCmdUI); 

#0102          afx_msg void OnUpdatePenThickOrThin(CCmdUI* pCmdUI); 

#0103          afx_msg void OnPenWidths(); 

#0104          //}}AFX_MSG 

#0105          DECLARE_MESSAGE_MAP() 

#0106  }; 



SCRIBBLEDOC。CPP 



#0001  #include 〃stdafx。h〃 

#0002  #include 〃Scribble。h〃 

#0003 

#0004  #include 〃ScribDoc。h〃 

#0005  #include 〃PenDlg。h〃 

#0006 

#0007  #ifdef _DEBUG 

#0008  #define new DEBUG_NEW 

#0009  #undef THIS_FILE 

#0010  static char THIS_FILE'' = __FILE__; 

#0011  #endif 

#0012 

#0013  ///////////////////////////////////////////////////////////////// 

#0014  // CScribbleDoc 

#0015 

#0016  IMPLEMENT_DYNCREATE(CScribbleDoc; CDocument) 

#0017 

#0018  BEGIN_MESSAGE_MAP(CScribbleDoc; CDocument) 

#0019          //{{AFX_MSG_MAP(CScribbleDoc) 

#0020          ON_MAND(ID_EDIT_CLEAR_ALL; OnEditClearAll) 

#0021          ON_MAND(ID_PEN_THICK_OR_THIN; OnPenThickOrThin) 

#0022          ON_UPDATE_MAND_UI(ID_EDIT_CLEAR_ALL; OnUpdateEditClearAll) 

#0023          ON_UPDATE_MAND_UI(ID_PEN_THICK_OR_THIN; OnUpdatePenThickOrThin) 

#0024          ON_MAND(ID_PEN_WIDTHS; OnPenWidths) 

#0025          //}}AFX_MSG_MAP 

#0026  END_MESSAGE_MAP() 

#0027 

#0028  ///////////////////////////////////////////////////////////////// 

#0029  // CScribbleDoc construction/destruction 

#0030 

#0031  CScribbleDoc::CScribbleDoc() 

#0032  { 



                                                                                     887 


…………………………………………………………Page 950……………………………………………………………

                   第五篇    附錄  



                   #0033          // TODO: add one…time construction code here 

                   #0034 

                   #0035  } 

                   #0036 

                   #0037  CScribbleDoc::~CScribbleDoc() 

                   #0038  { 

                   #0039  } 

                   #0040 

                   #0041  BOOL CScribbleDoc::OnNewDocument() 

                   #0042  { 

                   #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 
返回目录 上一页 下一页 回到顶部 9 10
快捷操作: 按键盘上方向键 ← 或 → 可快速上下翻页 按键盘上的 Enter 键可回到本书目录页 按键盘上方向键 ↑ 可回到本页顶部!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!