CommonControlsView.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:7k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // CommonControlsView.cpp : implementation of the CCommonControlsView class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "CommonControls.h"
  22. #include "CommonControlsDoc.h"
  23. #include "CommonControlsView.h"
  24. #include "MainFrm.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CCommonControlsView
  32. IMPLEMENT_DYNCREATE(CCommonControlsView, CView)
  33. BEGIN_MESSAGE_MAP(CCommonControlsView, CView)
  34. //{{AFX_MSG_MAP(CCommonControlsView)
  35. ON_WM_HSCROLL()
  36. ON_WM_ERASEBKGND()
  37. ON_WM_PAINT()
  38. //}}AFX_MSG_MAP
  39. // Standard printing commands
  40. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  41. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  42. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  43. ON_UPDATE_COMMAND_UI(IDC_SLIDER, OnUpdateSlider)
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CCommonControlsView construction/destruction
  47. CCommonControlsView::CCommonControlsView()
  48. {
  49. m_nGray = 0xFF; // Initialize the value used to create the background color.
  50. }
  51. CCommonControlsView::~CCommonControlsView()
  52. {
  53. }
  54. BOOL CCommonControlsView::PreCreateWindow(CREATESTRUCT& cs)
  55. {
  56. // TODO: Modify the Window class or styles here by modifying
  57. //  the CREATESTRUCT cs
  58. return CView::PreCreateWindow(cs);
  59. }
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CCommonControlsView drawing
  62. void CCommonControlsView::OnDraw(CDC* pDC)
  63. {
  64. // This member function is called by the framework
  65. // to render an image of the document. The framework
  66. // calls this function to perform screen display, printing,
  67. // and print preview, and it passes a different
  68. // device context in each case. There is no default
  69. // implementation.
  70. // Get a pointer to the Document object.
  71. CCommonControlsDoc* pDoc = GetDocument();
  72. // Make certain that the Document pointer is valid.
  73. ASSERT_VALID(pDoc);
  74. // Draw the background of the window.
  75. // CXTPClientRect(this) returns the client area of the window.
  76. // RGB(m_nGray, m_nGray, m_nGray) creates a gray scale color for the window's background.
  77. pDC->FillSolidRect(CXTPClientRect(this), RGB(m_nGray, m_nGray, m_nGray));
  78. }
  79. BOOL CCommonControlsView::OnEraseBkgnd(CDC* /*pDC*/)
  80. {
  81. // The framework calls this member function
  82. // when the CWnd object background needs erasing
  83. // (for example, when resized). It is called to
  84. // prepare an invalidated region for painting.
  85. // Return TRUE to prevent the background from being erased.
  86. // The OnDraw member function draws the background in this application.
  87. return TRUE;
  88. }
  89. void CCommonControlsView::OnPaint()
  90. {
  91. // The framework calls this member
  92. // function when Windows or an application
  93. // makes a request to repaint a portion of
  94. // an application's window. The WM_PAINT message
  95. // is sent when the UpdateWindow or RedrawWindow
  96. // member function is called.
  97. // Create a CPaintDC object and prepares the
  98. // application window for painting.
  99. CPaintDC dc(this);
  100. // Create a CXTPBufferDC.
  101. // This is a memory DC that is used to prevent flickering.
  102. CXTPBufferDC dcMem(dc, CXTPClientRect(this));
  103. // Call OnDraw with the memory DC dcMem.
  104. OnDraw(&dcMem);
  105. }
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CCommonControlsView printing
  108. BOOL CCommonControlsView::OnPreparePrinting(CPrintInfo* pInfo)
  109. {
  110. // default preparation
  111. return DoPreparePrinting(pInfo);
  112. }
  113. void CCommonControlsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  114. {
  115. // TODO: add extra initialization before printing
  116. }
  117. void CCommonControlsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  118. {
  119. // TODO: add cleanup after printing
  120. }
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CCommonControlsView diagnostics
  123. #ifdef _DEBUG
  124. void CCommonControlsView::AssertValid() const
  125. {
  126. CView::AssertValid();
  127. }
  128. void CCommonControlsView::Dump(CDumpContext& dc) const
  129. {
  130. CView::Dump(dc);
  131. }
  132. CCommonControlsDoc* CCommonControlsView::GetDocument() // non-debug version is inline
  133. {
  134. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCommonControlsDoc)));
  135. return (CCommonControlsDoc*)m_pDocument;
  136. }
  137. #endif //_DEBUG
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CCommonControlsView message handlers
  140. void CCommonControlsView::OnUpdateSlider(CCmdUI* pCmdUI)
  141. {
  142. // This function is called when the horizontal scroll
  143. // bar is scrolled on the Slider Control.
  144. // Enable the control.
  145. pCmdUI->Enable();
  146. // Use the DYNAMIC_DOWNCAST macro to cast the CWnd* pCmdUI->m_pOther into a CXTPCommandBar* object.
  147. CXTPCommandBar* pCommandBar = DYNAMIC_DOWNCAST(CXTPCommandBar, pCmdUI->m_pOther);
  148. if (!pCommandBar)
  149. return;
  150. // Use the DYNAMIC_DOWNCAST macro to cast the CSliderCtrl* control into a CXTPControlCustom* control.
  151. CXTPControlCustom* pControlSlider = DYNAMIC_DOWNCAST(CXTPControlCustom, pCommandBar->GetControl(pCmdUI->m_nIndex));
  152. if (!pControlSlider)
  153. return;
  154. // Use the DYNAMIC_DOWNCAST macro to cast the CWnd* control into a CSliderCtrl* control.
  155. CSliderCtrl* pSlider = DYNAMIC_DOWNCAST(CSliderCtrl, pControlSlider->GetControl());
  156. if (pSlider && pSlider->GetSafeHwnd())
  157. {
  158. int nMax = pSlider->GetRangeMax(); // Get the maximum range of the slider control
  159. int nPos = m_nGray * nMax / 0xFF;  // Determine the new position of the slider control's scroll bar.
  160. if (pSlider->GetPos() != nPos)
  161. {
  162. // If the new position of the scroll bar is
  163. // different than the current position
  164. // of the scroll bar then move the scroll
  165. // bar to the new position.
  166. pSlider->SetPos(nPos);
  167. }
  168. }
  169. }
  170. void CCommonControlsView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  171. {
  172. // The framework calls this member function
  173. // when the user clicks a window's horizontal scroll bar.
  174. // Use the DYNAMIC_DOWNCAST macro to cast the
  175. // CScrollBar* object into a CSliderCtrl* object.
  176. CSliderCtrl* pSlider = DYNAMIC_DOWNCAST(CSliderCtrl, pScrollBar);
  177. if (pSlider != 0)
  178. {
  179. int nPos = pSlider->GetPos();      // Get the current position of the Slider control's scroll bar.
  180. int nMax = pSlider->GetRangeMax(); // Get the maximum range of the Sliders control's scroll bar.
  181. m_nGray = nPos * 0xFF / nMax;      // Calculate the value of m_nGray.
  182. // Invalidate the entire client area of the window.
  183. // This sends a WM_PAINT message causing the OnPaint member
  184. // function to be called.  Do not erase the background. The
  185. // FALSE argument tells MFC not to erase the background.
  186. Invalidate(FALSE);
  187. }
  188. // Let the base class handle the message.
  189. CView::OnHScroll(nSBCode, nPos, pScrollBar);
  190. }