CornerBox.cpp
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 5k
Category:

Graph program

Development Platform:

Visual C++

  1. /* ==========================================================================
  2. Class : CCornerBox
  3. Author : Johan Rosengren, Abstrakt Mekanik AB
  4. Date : 2004-07-16
  5. Purpose : "CCornerBox" is a "CWnd"-derived class, used as a button 
  6. in the corner of two rulers. When clicked, a dialog box 
  7. is displayed where the user can select the measurement 
  8. type for the rulers.
  9. Description : The class is an AppWizard-created class. A registered 
  10. message is sent to the parent when the measurement 
  11. type is changed.
  12. Usage : Add with "Create" to the owning window.
  13.    ========================================================================*/
  14. #include "stdafx.h"
  15. #include "..//resource.h"
  16. #include "CornerBox.h"
  17. #include "StdGrfx.h"
  18. #include "RulerMeasurementsDialog.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. UINT UWM_MEASUREMENTS = ::RegisterWindowMessage( _T( "REPORT_EDITOR_MEASUREMENT" ) );
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CCornerBox
  27. CCornerBox::CCornerBox()
  28. /* ============================================================
  29. Function : CCornerBox::CCornerBox
  30. Description : Constructor
  31. Access : Public
  32. Return : void
  33. Parameters : none
  34. Usage :
  35.    ============================================================*/
  36. {
  37. SetMeasurements( MEASURE_INCHES );
  38. }
  39. CCornerBox::~CCornerBox()
  40. /* ============================================================
  41. Function : CCornerBox::~CCornerBox
  42. Description : Destructor
  43. Access : Public
  44. Return : void
  45. Parameters : none
  46. Usage :
  47.    ============================================================*/
  48. {
  49. }
  50. BEGIN_MESSAGE_MAP(CCornerBox, CWnd)
  51. //{{AFX_MSG_MAP(CCornerBox)
  52. ON_WM_ERASEBKGND()
  53. ON_WM_PAINT()
  54. ON_WM_LBUTTONUP()
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CCornerBox message handlers
  59. BOOL CCornerBox::OnEraseBkgnd( CDC* /*pDC*/ ) 
  60. /* ============================================================
  61. Function : CCornerBox::OnEraseBkgnd
  62. Description : Handler for the "WM_ERASEBKGND"-message.
  63. Access : Protected
  64. Return : BOOL - Always "TRUE"
  65. Parameters : CDC* pDC - Not interested
  66. Usage : Called from MFC. Handled to avoid flicker 
  67. as we draw the complete control in "OnPaint".
  68.    ============================================================*/
  69. {
  70. return TRUE;
  71. }
  72. void CCornerBox::OnPaint() 
  73. /* ============================================================
  74. Function : CCornerBox::OnPaint
  75. Description : Handler for the "WM_PAINT"-message.
  76. Access : Protected
  77. Return : void
  78. Parameters : none
  79. Usage : Called from MFC. Paints the control.
  80.    ============================================================*/
  81. {
  82. CPaintDC dc(this);
  83. CRect rect;
  84. GetClientRect( rect );
  85. int width = rect.Width();
  86. int height = rect.Height();
  87. CDC memDC;
  88. memDC.CreateCompatibleDC( &dc );
  89. CBitmap bitmap;
  90. bitmap.CreateCompatibleBitmap( &dc, width, height );
  91. CBitmap* oldbitmap = memDC.SelectObject( &bitmap );
  92. memDC.SelectObject( CStdGrfx::dialogPen() );
  93. memDC.SelectObject( CStdGrfx::dialogBrush() );
  94. memDC.Rectangle( rect );
  95. rect.InflateRect( -2, -2 );
  96. CStdGrfx::draw3dFrame( &memDC, rect );
  97. dc.BitBlt( 0, 0, width, height, &memDC, 0, 0, SRCCOPY );
  98. memDC.SelectObject( oldbitmap );
  99. }
  100. void CCornerBox::OnLButtonUp(UINT nFlags, CPoint point) 
  101. /* ============================================================
  102. Function : CCornerBox::OnLButtonUp
  103. Description : Handler for the "WM_LBUTTONUP"-message.
  104. Access : Protected
  105. Return : void
  106. Parameters : UINT nFlags - Not interested
  107. CPoint point - Not interested
  108. Usage : Called from MFC. Signals to the parent.
  109.    ============================================================*/
  110. {
  111. /*CRulerMeasurementsDialog dlg;
  112. dlg.m_measurements = GetMeasurements();
  113. if( dlg.DoModal() == IDOK )
  114. {
  115. SetMeasurements( dlg.m_measurements );
  116. GetParent()->SendMessage( UWM_MEASUREMENTS, GetMeasurements() );
  117. }
  118. */
  119. CWnd::OnLButtonUp(nFlags, point);
  120. }
  121. void CCornerBox::SetMeasurements( int measurements )
  122. /* ============================================================
  123. Function : CCornerBox::SetMeasurements
  124. Description : Sets the current measurements
  125. Access : Public
  126. Return : void
  127. Parameters : int measurements - New measurements
  128. Usage : Call to set the measurements of this 
  129. control. The measurement can be one of
  130. "MEASURE_PIXELS" In pixels
  131. "MEASURE_INCHES" In inches
  132. "MEASURE_CENTIMETERS" In centimeters
  133.    ============================================================*/
  134. {
  135. m_measurements = measurements;
  136. }
  137. int CCornerBox::GetMeasurements() const
  138. /* ============================================================
  139. Function : CCornerBox::GetMeasurements
  140. Description : Gets the current measurements
  141. Access : Public
  142. Return : int - Current measurement units.
  143. Parameters : none
  144. Usage : Call to get the measurements of this 
  145. control. The measurement can be one of
  146. "MEASURE_PIXELS" In pixels
  147. "MEASURE_INCHES" In inches
  148. "MEASURE_CENTIMETERS" In centimeters
  149.    ============================================================*/
  150. {
  151. return m_measurements;
  152. }