fork(1) download
  1. #include <afxwin.h>
  2. #include "resource.h"
  3. #include <afxtempl.h> //定義樣板類別的標頭檔
  4.  
  5. class MyDoc : public CDocument //Document的資料儲存
  6. {
  7. public:
  8. CArray<CPoint, CPoint &> pArray; //容納滑鼠軌跡的Array容器
  9.  
  10. void AddPoint(CPoint p) //將軌跡點加到容器內
  11. {
  12. pArray.Add(p);
  13. }
  14.  
  15. CPoint GetPoint(int i) //將軌跡點從容器中取出
  16. {
  17. return pArray[i];
  18. }
  19.  
  20. int GetSiez() //取得容器的大小
  21. {
  22. return pArray.GetSize();
  23. }
  24.  
  25. DECLARE_DYNCREATE(MyDoc) //宣告 run-time類別
  26. DECLARE_MESSAGE_MAP() //宣告訊息映射表
  27. };
  28.  
  29. IMPLEMENT_DYNCREATE(MyDoc,CDocument) //宣告MyDoc為run-time類別
  30. BEGIN_MESSAGE_MAP(MyDoc,CDocument) //建立訊息映射表
  31. END_MESSAGE_MAP()
  32.  
  33. class MyView : public CView //將儲存的資料顯示
  34. {
  35. public:
  36. void OnDraw(CDC * aDC) //複寫OnDraw(必須複寫的虛擬函數)
  37. {
  38. MyDoc *doc = (MyDoc *)GetDocument(); //取得目前Document物件的指標
  39. int num = doc->GetSiez(); //取得目前儲存的軌跡點點數
  40. int i;
  41.  
  42. for (i = 0; i < num; ++i) //將MyDOc中儲存的軌跡點重繪到視窗上
  43. {
  44. CPoint point = doc->GetPoint(i); //取出doc物件中儲存的第i個滑鼠軌跡點
  45. aDC->SetPixel(point, RGB(255, 0, 0)); //將滑鼠軌跡點繪於畫布上
  46. }
  47. }
  48.  
  49. afx_msg void OnButtonDown(UINT , CPoint point)
  50. {
  51. SetCapture();
  52. } //取得滑鼠訊息的接收權
  53.  
  54. afx_msg void OnMouseMove(UINT , CPoint point)
  55. {
  56. if (this == GetCapture()) //GetCapture()函數檢查滑鼠游標是否在這個應用程式的視窗上
  57. {
  58. CClientDC aDC(this); //建立畫布
  59. aDC.SetPixel(point, RGB(255, 0, 0)); //將點畫在畫布上
  60. MyDoc *doc = (MyDoc *)GetDocument(); //取得目前Doc物件的指標
  61. doc->AddPoint(point); //將軌跡點加入Doc物件中
  62. }
  63. }
  64.  
  65. afx_msg void OnLButtonUp(UINT , CPoint point)
  66. {
  67. ReleaseCapture(); //解放滑鼠訊息的接收權
  68. }
  69.  
  70. DECLARE_DYNCREATE(MyView) //宣告run-time類別
  71. DECLARE_MESSAGE_MAP() //宣告訊息映射表
  72. };
  73.  
  74. IMPLEMENT_DYNCREATE(MyView,CView) //宣告MyView為run-time類別
  75. BEGIN_MESSAGE_MAP(MyView,CView)
  76. ON_WM_LBUTTONDOWN()
  77. ON_WM_MOUSEMOVE()
  78. ON_WM_LBUTTONUP()
  79. END_MESSAGE_MAP() //建立訊息映射表
  80.  
  81. class MyFrame : public CFrameWnd
  82. {
  83. DECLARE_DYNCREATE(MyFrame) //宣告 run-time類別
  84. DECLARE_MESSAGE_MAP() //宣告訊息映射表
  85. };
  86.  
  87. IMPLEMENT_DYNCREATE(MyFrame,CFrameWnd) //宣告MyFrame為run-time類別
  88. BEGIN_MESSAGE_MAP(MyFrame,CFrameWnd) //建立訊息映射表
  89. END_MESSAGE_MAP()
  90.  
  91. class MyApp : public CWinApp
  92. {
  93. public:
  94. BOOL InitInstance()
  95. {
  96. CDocument *doc; //宣告指向文件的指標
  97. CSingleDocTemplate* DocTemplate; //宣告指向單文件樣板物件的指標
  98. DocTemplate = new CSingleDocTemplate( //建立具有單文件樣板物件
  99. IDR_MENU1, //用於單文件框架之資源的識別子
  100. RUNTIME_CLASS(MyDoc), //單文字視窗的Document
  101. RUNTIME_CLASS(MyFrame),//單文字視窗的視窗框架
  102. RUNTIME_CLASS(MyView)//單文字視窗的View
  103. );
  104.  
  105. AddDocTemplate(DocTemplate); //將單文件樣板物件設定給MyApp
  106. doc = DocTemplate->CreateNewDocument(); //建立新的文件
  107.  
  108. m_pMainWnd = DocTemplate->CreateNewFrame(doc, NULL); //建立一個視窗框架
  109. DocTemplate->InitialUpdateFrame((CFrameWnd*)m_pMainWnd, doc); //起始化視窗框架物件,並連接View物件
  110. m_pMainWnd->ShowWindow(SW_SHOW); //顯示視窗
  111.  
  112. return true;
  113. }
  114. }a_app; //建立應用程式物件
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:20: fatal error: afxwin.h: No such file or directory
 #include <afxwin.h>
                    ^
compilation terminated.
stdout
Standard output is empty