Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
4.4 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*******************************************************************************
  3. *
  4. * led.cpp
  5. *
  6. * implementation of CLed class
  7. *
  8. * copyright notice: Copyright 1995, Citrix Systems Inc.
  9. *
  10. * $Author: butchd $ Butch Davis
  11. *
  12. * $Log: N:\NT\PRIVATE\UTILS\CITRIX\WINUTILS\COMMON\VCS\LED.CPP $
  13. *
  14. * Rev 1.0 14 Nov 1995 06:40:40 butchd
  15. * Initial revision.
  16. *
  17. *******************************************************************************/
  18. /*
  19. * include files
  20. */
  21. #include "stdafx.h"
  22. #include <afxwin.h> // MFC core and standard components
  23. #include <afxext.h> // MFC extensions
  24. #include "led.h"
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char BASED_CODE THIS_FILE[] = __FILE__;
  28. #endif
  29. ///////////////////////////////////////////////////////////////////////////////
  30. // CLed class construction / destruction, implementation
  31. /*******************************************************************************
  32. *
  33. * CLed - CLed constructor
  34. *
  35. * ENTRY:
  36. * hBrush (input)
  37. * Brush to paint window with.
  38. * EXIT:
  39. * (Refer to MFC CStatic::CStatic documentation)
  40. *
  41. ******************************************************************************/
  42. CLed::CLed( HBRUSH hBrush )
  43. : CStatic(),
  44. m_hBrush(hBrush)
  45. {
  46. //{{AFX_DATA_INIT(CLed)
  47. //}}AFX_DATA_INIT
  48. } // end CLed::CLed
  49. ////////////////////////////////////////////////////////////////////////////////
  50. // CLed operations
  51. /*******************************************************************************
  52. *
  53. * Subclass - CLed member function: public operation
  54. *
  55. * Subclass the specified object to our special blip object.
  56. *
  57. * ENTRY:
  58. * pStatic (input)
  59. * Points to CStatic object to subclass.
  60. * EXIT:
  61. *
  62. ******************************************************************************/
  63. void
  64. CLed::Subclass( CStatic *pStatic )
  65. {
  66. SubclassWindow(pStatic->m_hWnd);
  67. } // end CLed::Subclass
  68. /*******************************************************************************
  69. *
  70. * Update - CLed member function: public operation
  71. *
  72. * Update the LED to 'on' or 'off' state.
  73. *
  74. * ENTRY:
  75. * nOn (input)
  76. * nonzero to set 'on' state; zero for 'off' state.
  77. * EXIT:
  78. *
  79. ******************************************************************************/
  80. void
  81. CLed::Update( int nOn )
  82. {
  83. m_bOn = nOn ? TRUE : FALSE;
  84. InvalidateRect(NULL);
  85. UpdateWindow();
  86. } // end CLed::Update
  87. /*******************************************************************************
  88. *
  89. * Toggle - CLed member function: public operation
  90. *
  91. * Toggle the LED's on/off state.
  92. *
  93. * ENTRY:
  94. * EXIT:
  95. *
  96. ******************************************************************************/
  97. void
  98. CLed::Toggle()
  99. {
  100. m_bOn = !m_bOn;
  101. InvalidateRect(NULL);
  102. UpdateWindow();
  103. } // end CLed::Toggle
  104. ////////////////////////////////////////////////////////////////////////////////
  105. // CLed message map
  106. BEGIN_MESSAGE_MAP(CLed, CStatic)
  107. //{{AFX_MSG_MAP(CLed)
  108. ON_WM_PAINT()
  109. //}}AFX_MSG_MAP
  110. END_MESSAGE_MAP()
  111. ////////////////////////////////////////////////////////////////////////////////
  112. // CLed commands
  113. /*******************************************************************************
  114. *
  115. * OnPaint - CLed member function: public operation
  116. *
  117. * Paint the led with its brush for 'on' state.
  118. *
  119. * ENTRY:
  120. * EXIT:
  121. * (Refer to MFC CWnd::OnPaint documentation)
  122. *
  123. ******************************************************************************/
  124. void
  125. CLed::OnPaint()
  126. {
  127. RECT rect;
  128. CPaintDC dc(this);
  129. CBrush brush;
  130. GetClientRect(&rect);
  131. #ifdef USING_3DCONTROLS
  132. (rect.right)--;
  133. (rect.bottom)--;
  134. dc.FrameRect( &rect, brush.FromHandle((HBRUSH)GetStockObject(GRAY_BRUSH)) );
  135. (rect.top)++;
  136. (rect.left)++;
  137. (rect.right)++;
  138. (rect.bottom)++;
  139. dc.FrameRect( &rect, brush.FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)) );
  140. (rect.top)++;
  141. (rect.left)++;
  142. (rect.right) -= 2;
  143. (rect.bottom) -= 2;
  144. #else
  145. dc.FrameRect( &rect, brush.FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)) );
  146. (rect.top)++;
  147. (rect.left)++;
  148. (rect.right)--;
  149. (rect.bottom)--;
  150. #endif
  151. dc.FillRect( &rect,
  152. brush.FromHandle(
  153. m_bOn ?
  154. m_hBrush :
  155. (HBRUSH)GetStockObject(LTGRAY_BRUSH)) );
  156. } // end CLed::OnPaint
  157. ////////////////////////////////////////////////////////////////////////////////