demoView.cpp
上传用户:qdhmjx
上传日期:2022-07-11
资源大小:2226k
文件大小:4k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // demoView.cpp : implementation of the CDemoView class
  2. //
  3. #include "stdafx.h"
  4. #include "demo.h"
  5. #include "demoDoc.h"
  6. #include "demoView.h"
  7. #include "MainFrm.h"
  8. #include "math.h"
  9. #include "NPenDlg.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CDemoView
  17. IMPLEMENT_DYNCREATE(CDemoView, CView)
  18. BEGIN_MESSAGE_MAP(CDemoView, CView)
  19. //{{AFX_MSG_MAP(CDemoView)
  20. ON_COMMAND(ID_MEDIUM, OnMedium)
  21. ON_UPDATE_COMMAND_UI(ID_MEDIUM, OnUpdateMedium)
  22. ON_COMMAND(ID_SMALL, OnSmall)
  23. ON_UPDATE_COMMAND_UI(ID_SMALL, OnUpdateSmall)
  24. ON_WM_MOUSEMOVE()
  25. ON_UPDATE_COMMAND_UI(ID_INDICATOR_CTRL, OnUpdateKeyCtrl)
  26. ON_COMMAND(ID_BIG, OnBig)
  27. //}}AFX_MSG_MAP
  28. // Standard printing commands
  29. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  30. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  31. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CDemoView construction/destruction
  35. CDemoView::CDemoView()
  36. {
  37. flag=false;
  38. }
  39. CDemoView::~CDemoView()
  40. {
  41. }
  42. BOOL CDemoView::PreCreateWindow(CREATESTRUCT& cs)
  43. {
  44. // TODO: Modify the Window class or styles here by modifying
  45. //  the CREATESTRUCT cs
  46. return CView::PreCreateWindow(cs);
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CDemoView drawing
  50. void CDemoView::OnDraw(CDC* pDC)
  51. {
  52. CDemoDoc* pDoc = GetDocument();
  53. ASSERT_VALID(pDoc);
  54. // TODO: add draw code for native data here
  55. // pDC->TextOut(x+xx,y+yy,"*");
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CDemoView printing
  59. BOOL CDemoView::OnPreparePrinting(CPrintInfo* pInfo)
  60. {
  61. // default preparation
  62. return DoPreparePrinting(pInfo);
  63. }
  64. void CDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  65. {
  66. // TODO: add extra initialization before printing
  67. }
  68. void CDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  69. {
  70. // TODO: add cleanup after printing
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CDemoView diagnostics
  74. #ifdef _DEBUG
  75. void CDemoView::AssertValid() const
  76. {
  77. CView::AssertValid();
  78. }
  79. void CDemoView::Dump(CDumpContext& dc) const
  80. {
  81. CView::Dump(dc);
  82. }
  83. CDemoDoc* CDemoView::GetDocument() // non-debug version is inline
  84. {
  85. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDemoDoc)));
  86. return (CDemoDoc*)m_pDocument;
  87. }
  88. #endif //_DEBUG
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CDemoView message handlers
  91. void CDemoView::OnMedium() 
  92. {
  93. CDC *pDC=GetDC();
  94. pDC->TextOut(100,100,"Medium test");
  95. flag=true;
  96. CFileDialog colordlg(false);
  97. colordlg.DoModal();
  98. }
  99. void CDemoView::OnUpdateMedium(CCmdUI* pCmdUI) 
  100. {
  101. if(flag)
  102. {
  103. pCmdUI->Enable(false);
  104. //pCmdUI->SetCheck(true);
  105. //pCmdUI->SetRadio(true);
  106. pCmdUI->SetText("demo");
  107. }
  108. }
  109. void CDemoView::OnSmall() 
  110. {
  111. CColorDialog color;
  112. color.DoModal();
  113. }
  114. void CDemoView::OnUpdateSmall(CCmdUI* pCmdUI) 
  115. {
  116. // TODO: Add your command update UI handler code here
  117. }
  118. void CDemoView::OnMouseMove(UINT nFlags, CPoint point) 
  119. {
  120. CString str;
  121. str.Format("x=%d,y=%d",point.x,point.y) ;  
  122. // CMainFrame* pMainFrame=(CMainFrame*)(AfxGetApp()->GetMainWnd());
  123. // pMainFrame->m_wndStatusBar. SetPaneText(1,str) ;
  124. ((CMainFrame*)(AfxGetApp()->GetMainWnd()))->m_wndStatusBar. SetPaneText(1,str) ;
  125. CView::OnMouseMove(nFlags, point);
  126. }
  127. void CDemoView::OnUpdateKeyCtrl(CCmdUI* pCmdUI) 
  128. {
  129. pCmdUI->Enable(::GetKeyState(VK_CONTROL)<0);
  130. }
  131. void CDemoView::OnBig() 
  132. {
  133. CNPenDlg nPenDlg ;
  134. nPenDlg.DoModal();
  135. }