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.

188 lines
4.4 KiB

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