WalkLtDemoView.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //Download by http://www.NewXing.com
  2. // WalkLtDemoView.cpp : implementation of the CWalkLtDemoView class
  3. //
  4. #include "stdafx.h"
  5. #include "WalkLtDemo.h"
  6. #include "WalkLtDemoDoc.h"
  7. #include "WalkLtDemoView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CWalkLtDemoView
  15. IMPLEMENT_DYNCREATE(CWalkLtDemoView, CView)
  16. BEGIN_MESSAGE_MAP(CWalkLtDemoView, CView)
  17. //{{AFX_MSG_MAP(CWalkLtDemoView)
  18. ON_COMMAND(ID_GDIPLUS_DEMO, OnGdiplusDemo)
  19. ON_COMMAND(ID_GDIPLUS_CODE, OnGdiplusCode)
  20. ON_UPDATE_COMMAND_UI(ID_GDIPLUS_CODE, OnUpdateGdiplusCode)
  21. //}}AFX_MSG_MAP
  22. // Standard printing commands
  23. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  25. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CWalkLtDemoView construction/destruction
  29. CWalkLtDemoView::CWalkLtDemoView()
  30. {
  31. // TODO: add construction code here
  32. }
  33. CWalkLtDemoView::~CWalkLtDemoView()
  34. {
  35. }
  36. BOOL CWalkLtDemoView::PreCreateWindow(CREATESTRUCT& cs)
  37. {
  38. // TODO: Modify the Window class or styles here by modifying
  39. // the CREATESTRUCT cs
  40. return CView::PreCreateWindow(cs);
  41. }
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CWalkLtDemoView drawing
  44. typedef GdiPlusColor Color;
  45. int g_index1=0;
  46. int g_index2=0;
  47. BOOL g_OnDraw=0;
  48. void CWalkLtDemoView::OnDraw(CDC* pDC)
  49. {
  50. CWalkLtDemoDoc* pDoc = GetDocument();
  51. ASSERT_VALID(pDoc);
  52. // TODO: add draw code for native data here
  53. if (g_OnDraw)
  54. return;
  55. g_OnDraw=1;
  56. //绘制一个红色椭圆
  57. Graphics gc(pDC->m_hDC);
  58. Pen pen(Color::Red, 2);
  59. gc.DrawArc(&pen, 10, 10, 300, 200, 0, 360);
  60. //支持 WalkLtDemo设计实例.cpp 中的函数调用
  61. //----------- 调用 DoGdiplusDemo ---------
  62. extern void DoGdiplusDemo(Graphics &gc, CView *pView, int index1, int index2);
  63. if (g_index1>0 && g_index2>0)
  64. DoGdiplusDemo(gc, this, g_index1, g_index2);
  65. g_OnDraw=0;
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CWalkLtDemoView printing
  69. BOOL CWalkLtDemoView::OnPreparePrinting(CPrintInfo* pInfo)
  70. {
  71. // default preparation
  72. return DoPreparePrinting(pInfo);
  73. }
  74. void CWalkLtDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  75. {
  76. // TODO: add extra initialization before printing
  77. }
  78. void CWalkLtDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  79. {
  80. // TODO: add cleanup after printing
  81. }
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CWalkLtDemoView diagnostics
  84. #ifdef _DEBUG
  85. void CWalkLtDemoView::AssertValid() const
  86. {
  87. CView::AssertValid();
  88. }
  89. void CWalkLtDemoView::Dump(CDumpContext& dc) const
  90. {
  91. CView::Dump(dc);
  92. }
  93. CWalkLtDemoDoc* CWalkLtDemoView::GetDocument() // non-debug version is inline
  94. {
  95. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWalkLtDemoDoc)));
  96. return (CWalkLtDemoDoc*)m_pDocument;
  97. }
  98. #endif //_DEBUG
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CWalkLtDemoView message handlers
  101. #include "GdiplusDemoDlg.h"
  102. void CWalkLtDemoView::OnGdiplusDemo()
  103. {
  104. CGdiplusDemoDlg dlg;
  105. if (IDOK==dlg.DoModal())
  106. {
  107. g_index1=dlg.m_index1;
  108. g_index2=dlg.m_index2;
  109. Invalidate();
  110. }
  111. }
  112. #include "MyCodeDlg.h"
  113. void CWalkLtDemoView::OnGdiplusCode()
  114. {
  115. //获取函数的源代码
  116. CString GetGdiplusFunsCode(int index1, int index2);
  117. CMyCodeDlg dlg;
  118. dlg.m_str = GetGdiplusFunsCode(g_index1, g_index2);
  119. dlg.DoModal();
  120. }
  121. void CWalkLtDemoView::OnUpdateGdiplusCode(CCmdUI* pCmdUI)
  122. {
  123. pCmdUI->Enable(g_index1>0&&g_index2>0);
  124. }