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.

257 lines
5.0 KiB

  1. /*****************************************************************************************************************
  2. FILENAME: ESButton.cpp
  3. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  4. CLASS: ESButton
  5. This is a class to create a button window.
  6. */
  7. #include "stdafx.h"
  8. #ifndef SNAPIN
  9. #include <windows.h>
  10. #endif
  11. #include "errmacro.h"
  12. #include "ESButton.h"
  13. /*****************************************************************************************************************
  14. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  15. METHOD DESCRIPTION:
  16. Constructor - Initializes class variables.
  17. CLASS VARIABLES:
  18. INPUT + OUTPUT:
  19. RETURN:
  20. None.
  21. */
  22. ESButton::ESButton(HWND hwndParent, UINT ButtonId, HINSTANCE hInstance)
  23. {
  24. m_hwndButton = CreateWindow(
  25. TEXT("Button"),
  26. TEXT("TEST"),
  27. WS_CHILD|BS_PUSHBUTTON,
  28. 400,
  29. 400,
  30. 100,
  31. 100,
  32. hwndParent,
  33. (HMENU)IntToPtr(ButtonId),
  34. hInstance,
  35. (LPVOID)IntToPtr(NULL));
  36. if (m_hwndButton == NULL){
  37. DWORD dwErrorCode = GetLastError();
  38. }
  39. }
  40. /*****************************************************************************************************************
  41. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  42. METHOD DESCRIPTION:
  43. Destroys the button window
  44. CLASS VARIABLES:
  45. INPUT + OUTPUT:
  46. RETURN:
  47. None.
  48. */
  49. ESButton::~ESButton()
  50. {
  51. if (m_hwndButton != NULL){
  52. if (IsWindow(m_hwndButton)){
  53. DestroyWindow(m_hwndButton);
  54. }
  55. }
  56. }
  57. BOOL
  58. ESButton::ShowButton(int cmdShow)
  59. {
  60. if (m_hwndButton != NULL){
  61. return ::ShowWindow(m_hwndButton, cmdShow);
  62. }
  63. return FALSE;
  64. }
  65. /*****************************************************************************************************************
  66. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  67. METHOD DESCRIPTION:
  68. Initializes class variables.
  69. CLASS VARIABLES:
  70. INPUT + OUTPUT:
  71. RETURN:
  72. None.
  73. */
  74. BOOL ESButton::PositionButton(RECT* prcPos)
  75. {
  76. if (m_hwndButton != NULL){
  77. MoveWindow(m_hwndButton,
  78. prcPos->left,
  79. prcPos->top,
  80. prcPos->right - prcPos->left,
  81. prcPos->bottom - prcPos->top,
  82. FALSE);
  83. }
  84. return TRUE;
  85. }
  86. /*****************************************************************************************************************
  87. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  88. METHOD DESCRIPTION:
  89. Initializes class variables.
  90. CLASS VARIABLES:
  91. INPUT + OUTPUT:
  92. RETURN:
  93. None.
  94. */
  95. BOOL ESButton::SetText(TCHAR* szNewText)
  96. {
  97. if (m_hwndButton != NULL){
  98. SetWindowText(m_hwndButton, szNewText);
  99. }
  100. return TRUE;
  101. }
  102. /*****************************************************************************************************************
  103. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  104. METHOD DESCRIPTION:
  105. CLASS VARIABLES:
  106. INPUT + OUTPUT:
  107. RETURN:
  108. None.
  109. */
  110. BOOL ESButton::LoadString(HINSTANCE hInstance, UINT labelResourceID)
  111. {
  112. if (m_hwndButton != NULL){
  113. TCHAR cText[200];
  114. ::LoadString(hInstance, labelResourceID, cText, sizeof(cText)/sizeof(TCHAR));
  115. SetWindowText(m_hwndButton, cText);
  116. }
  117. return TRUE;
  118. }
  119. /*****************************************************************************************************************
  120. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  121. METHOD DESCRIPTION:
  122. Initializes class variables.
  123. CLASS VARIABLES:
  124. INPUT + OUTPUT:
  125. RETURN:
  126. None.
  127. */
  128. BOOL ESButton::SetFont(HFONT hNewFont)
  129. {
  130. if (m_hwndButton != NULL){
  131. SendMessage(m_hwndButton, WM_SETFONT, (WPARAM)hNewFont, MAKELPARAM(TRUE, 0));
  132. }
  133. return TRUE;
  134. }
  135. /*****************************************************************************************************************
  136. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  137. METHOD DESCRIPTION:
  138. Enables or disables the button.
  139. CLASS VARIABLES:
  140. INPUT + OUTPUT:
  141. RETURN:
  142. None.
  143. */
  144. BOOL ESButton::EnableButton(BOOL bEnable)
  145. {
  146. if (m_hwndButton != NULL){
  147. if (bEnable != ::IsWindowEnabled(m_hwndButton)){
  148. EnableWindow(m_hwndButton, bEnable); // this repaints the button
  149. }
  150. }
  151. return TRUE;
  152. }
  153. /*****************************************************************************************************************
  154. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  155. METHOD DESCRIPTION:
  156. returns the state of the button
  157. CLASS VARIABLES:
  158. INPUT + OUTPUT:
  159. RETURN:
  160. Button State, true or false
  161. */
  162. BOOL ESButton::IsButtonEnabled(void)
  163. {
  164. if (m_hwndButton != NULL)
  165. return ::IsWindowEnabled(m_hwndButton);
  166. else
  167. return FALSE;
  168. }
  169. /*****************************************************************************************************************
  170. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  171. METHOD DESCRIPTION:
  172. Enables or disables the button.
  173. CLASS VARIABLES:
  174. INPUT + OUTPUT:
  175. RETURN:
  176. None.
  177. */
  178. BOOL ESButton::ShowWindow(UINT showState)
  179. {
  180. if (m_hwndButton != NULL){
  181. ::ShowWindow(m_hwndButton, showState); // this repaints the button
  182. }
  183. return TRUE;
  184. }