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.

236 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1993-2001 Microsoft Corporation
  3. Module Name:
  4. controls.cpp
  5. Abstract:
  6. This file implements the sun-classing and message processing of
  7. the controls on the main ui dialog.
  8. Author:
  9. Wesley Witt (wesw) 1-May-1993
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "pch.cpp"
  14. typedef struct _tagDWCONTROLINFO {
  15. struct _tagDWCONTROLINFO *next;
  16. HWND hwnd;
  17. WNDPROC wndProc;
  18. } DWCONTROLINFO, *PDWCONTROLINFO;
  19. PDWCONTROLINFO ciHead = NULL;
  20. PDWCONTROLINFO ciTail = NULL;
  21. PDWCONTROLINFO ciFocus = NULL;
  22. PDWCONTROLINFO ciDefault = NULL;
  23. void
  24. SetFocusToCurrentControl(
  25. void
  26. )
  27. /*++
  28. Routine Description:
  29. Sets the focus to the current control.
  30. Arguments:
  31. None.
  32. Return Value:
  33. None.
  34. --*/
  35. {
  36. if (ciFocus != NULL) {
  37. SetFocus( ciFocus->hwnd );
  38. SendMessage( ciFocus->hwnd, BM_SETSTATE, 0, 0 );
  39. }
  40. }
  41. LRESULT
  42. ControlWndProc(
  43. HWND hwnd,
  44. UINT message,
  45. WPARAM wParam,
  46. LPARAM lParam
  47. )
  48. /*++
  49. Routine Description:
  50. Processes focus messages and ensures that when the focus changes
  51. from one button to another that the old button looses the focus
  52. and the "default" state.
  53. Arguments:
  54. Standard WNDPROC entry.
  55. Return Value:
  56. LRESULT - Depending on input message and processing options.
  57. --*/
  58. {
  59. PDWCONTROLINFO ci = ciHead;
  60. while (ci->hwnd != hwnd) {
  61. ci = ci->next;
  62. if (ci == NULL) {
  63. return FALSE;
  64. }
  65. }
  66. switch(message) {
  67. case WM_SETFOCUS:
  68. ciFocus = ci;
  69. break;
  70. case BM_SETSTYLE:
  71. if (wParam == BS_DEFPUSHBUTTON) {
  72. ciDefault = ci;
  73. }
  74. break;
  75. case BM_SETSTATE:
  76. if ((GetWindowLong( hwnd, GWL_STYLE ) & 0xff) < BS_CHECKBOX) {
  77. //
  78. // change the button that had the focus
  79. //
  80. SendMessage( ciDefault->hwnd,
  81. BM_SETSTYLE,
  82. ( WPARAM ) BS_PUSHBUTTON,
  83. ( LPARAM ) TRUE
  84. );
  85. UpdateWindow( ciDefault->hwnd );
  86. //
  87. // change the button that is getting the focus
  88. //
  89. SendMessage( hwnd,
  90. BM_SETSTYLE,
  91. ( WPARAM ) BS_DEFPUSHBUTTON,
  92. ( LPARAM ) TRUE
  93. );
  94. SetFocus( hwnd );
  95. UpdateWindow( hwnd );
  96. }
  97. break;
  98. }
  99. return CallWindowProc( ci->wndProc, hwnd, message, wParam, lParam );
  100. }
  101. BOOL
  102. CALLBACK
  103. EnumChildProc(
  104. HWND hwnd,
  105. LPARAM lParam
  106. )
  107. /*++
  108. Routine Description:
  109. Subclass a controls in DrWatson's main window.
  110. Arguments:
  111. hwnd - Supplies the window handle for the main window.
  112. lParam - non used
  113. Return Value:
  114. BOOL - Returns TRUE if each of the buttons in the ButtonHelpTable is
  115. subclassed.
  116. --*/
  117. {
  118. PDWCONTROLINFO ci;
  119. //
  120. // add the control to the linked list
  121. //
  122. ci = (PDWCONTROLINFO) calloc( sizeof(DWCONTROLINFO), sizeof(BYTE) );
  123. if (ci == NULL) {
  124. return FALSE;
  125. }
  126. if (ciHead == NULL) {
  127. ciHead = ciTail = ci;
  128. }
  129. else {
  130. ciTail->next = ci;
  131. ciTail = ci;
  132. }
  133. //
  134. // save the HWND
  135. //
  136. ci->hwnd = hwnd;
  137. //
  138. // change the WNDPROC and save the address of the old one
  139. //
  140. ci->wndProc = (WNDPROC) SetWindowLongPtr( hwnd,
  141. GWLP_WNDPROC,
  142. (LONG_PTR)ControlWndProc
  143. );
  144. if (GetWindowLong( hwnd, GWL_STYLE ) & BS_DEFPUSHBUTTON) {
  145. ciDefault = ci;
  146. }
  147. return TRUE;
  148. }
  149. BOOL
  150. SubclassControls(
  151. HWND hwnd
  152. )
  153. /*++
  154. Routine Description:
  155. Subclass the controls in DrWatson's main window.
  156. Arguments:
  157. hWnd - Supplies the window handle for the main window.
  158. Return Value:
  159. BOOL - Returns TRUE if each of the buttons in the ButtonHelpTable is
  160. subclassed.
  161. --*/
  162. {
  163. EnumChildWindows( hwnd, EnumChildProc, 0 );
  164. return TRUE;
  165. }