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.

374 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. Controls.c
  5. Abstract:
  6. This module contains support manipulating controls.
  7. Author:
  8. David J. Gilman (davegi) 11-Dec-1992
  9. Environment:
  10. User Mode
  11. --*/
  12. #include "wintools.h"
  13. DWORD
  14. DialogPrintf(
  15. IN HWND hWnd,
  16. IN int ControlId,
  17. IN UINT FormatId,
  18. IN ...
  19. )
  20. /*++
  21. Routine Description:
  22. Display a printf style string in the specified control of the
  23. supplied dialog.
  24. Arguments:
  25. hWnd - Supplies handle to the dialog that contains the control.
  26. ControlId - Supplies the id of the control where the formatted text
  27. will be displayed.
  28. FormatId - Supplies a resource id for a printf style format string.
  29. ... - Supplies zero or more values based on the format
  30. descpritors supplied in Format.
  31. Return Value:
  32. None.
  33. --*/
  34. {
  35. BOOL Success;
  36. DWORD Count;
  37. va_list Args;
  38. DbgHandleAssert( hWnd );
  39. //
  40. // Retrieve the values and format the string.
  41. //
  42. va_start( Args, FormatId );
  43. if( IsDlgItemUnicode( hWnd, ControlId )) {
  44. WCHAR Buffer[ MAX_CHARS ];
  45. Count = FormatMessageW(
  46. FORMAT_MESSAGE_FROM_HMODULE,
  47. NULL,
  48. FormatId,
  49. 0,
  50. Buffer,
  51. sizeof( Buffer ),
  52. &Args
  53. );
  54. DbgAssert( Count != 0 );
  55. //
  56. // Display the formatted text in the specified control.
  57. //
  58. Success = SetDlgItemTextW(
  59. hWnd,
  60. ControlId,
  61. Buffer
  62. );
  63. DbgAssert( Success );
  64. } else {
  65. CHAR Buffer[ MAX_CHARS ];
  66. Count = FormatMessageA(
  67. FORMAT_MESSAGE_FROM_HMODULE,
  68. NULL,
  69. FormatId,
  70. 0,
  71. Buffer,
  72. sizeof( Buffer ),
  73. &Args
  74. );
  75. DbgAssert( Count != 0 );
  76. //
  77. // Display the formatted text in the specified control.
  78. //
  79. Success = SetDlgItemTextA(
  80. hWnd,
  81. ControlId,
  82. Buffer
  83. );
  84. DbgAssert( Success );
  85. }
  86. va_end( Args );
  87. return Count;
  88. }
  89. BOOL
  90. EnableControl(
  91. IN HWND hWnd,
  92. IN int ControlId,
  93. IN BOOL Enable
  94. )
  95. /*++
  96. Routine Description:
  97. Enable or diable the specified control based on the supplied flag.
  98. Arguments:
  99. hWnd - Supplies the window (dialog box) handle that contains the
  100. control.
  101. ControlId - Supplies the control id.
  102. Enable - Supplies a flag which if TRUE causes the control to be enabled
  103. and disables the control if FALSE.
  104. Return Value:
  105. BOOL - Returns TRUE if the control is succesfully enabled / disabled.
  106. --*/
  107. {
  108. HWND hWndControl;
  109. BOOL Success;
  110. DbgHandleAssert( hWnd );
  111. hWndControl = GetDlgItem( hWnd, ControlId );
  112. DbgHandleAssert( hWndControl );
  113. if( hWndControl == NULL ) {
  114. return FALSE;
  115. }
  116. if( Enable == IsWindowEnabled( hWndControl )) {
  117. return TRUE;
  118. }
  119. Success = EnableWindow( hWndControl, Enable );
  120. // if we are always returning true then there should not be any concern
  121. // as to what value EnableWindow returns.
  122. return TRUE; // EnableWindow is returning 8 for TRUE return Success == Enable;
  123. }
  124. BOOL
  125. IsDlgItemUnicode(
  126. IN HWND hWnd,
  127. IN int ControlId
  128. )
  129. /*++
  130. Routine Description:
  131. Determines if the supplied dialog item is a Unicode control.
  132. Arguments:
  133. hWnd - Supplies the window (dialog box) handle that contains the
  134. control.
  135. ControlId - Supplies the control id.
  136. Return Value:
  137. BOOL - Returns TRUE if the control is Unicode, FALSE if ANSI.
  138. --*/
  139. {
  140. HWND hWndControl;
  141. DbgHandleAssert( hWnd );
  142. //
  143. // Get the handle for the supplied control so that it can be determined
  144. // if it is ANSI or UNICODE.
  145. //
  146. hWndControl = GetDlgItem( hWnd, ControlId );
  147. DbgHandleAssert( hWndControl );
  148. return IsWindowUnicode( hWndControl );
  149. }
  150. BOOL
  151. SetDlgItemBigInt(
  152. IN HWND hWnd,
  153. IN int ControlId,
  154. IN UINT Value,
  155. IN BOOL Signed
  156. )
  157. /*++
  158. Routine Description:
  159. Arguments:
  160. hWnd - Supplies the window (dialog box) handle that contains the
  161. control or the window handle where the font should be set.
  162. ControlId - Supplies the control id or xero if the hWnd is a window
  163. rather than a dialog handle.
  164. Return Value:
  165. BOOL -
  166. --*/
  167. {
  168. BOOL Success;
  169. if( IsDlgItemUnicode( hWnd, ControlId )) {
  170. Success = SetDlgItemTextW(
  171. hWnd,
  172. ControlId,
  173. FormatBigIntegerW(
  174. Value,
  175. Signed
  176. )
  177. );
  178. DbgAssert( Success );
  179. } else {
  180. DbgAssert( FALSE );
  181. }
  182. return Success;
  183. }
  184. BOOL
  185. SetDlgItemHex(
  186. IN HWND hWnd,
  187. IN int ControlId,
  188. IN UINT Value
  189. )
  190. /*++
  191. Routine Description:
  192. Arguments:
  193. hWnd - Supplies the window (dialog box) handle that contains the
  194. control or the window handle where the font should be set.
  195. ControlId - Supplies the control id or xero if the hWnd is a window
  196. rather than a dialog handle.
  197. Return Value:
  198. BOOL -
  199. --*/
  200. {
  201. BOOL Success;
  202. DWORD Count;
  203. if( IsDlgItemUnicode( hWnd, ControlId )) {
  204. WCHAR Buffer[ MAX_PATH ];
  205. Count = wsprintfW( Buffer, L"0x%08.8X", Value );
  206. DbgAssert(( Count != 0 ) && ( Count < MAX_PATH ));
  207. Success = SetDlgItemTextW( hWnd, ControlId, Buffer );
  208. DbgAssert( Success );
  209. } else {
  210. CHAR Buffer[ MAX_PATH ];
  211. Count = wsprintfA( Buffer, "0x%08.8X", Value );
  212. DbgAssert(( Count != 0 ) && ( Count < MAX_PATH ));
  213. Success = SetDlgItemTextA( hWnd, ControlId, Buffer );
  214. DbgAssert( Success );
  215. }
  216. return Success;
  217. }
  218. BOOL
  219. SetFixedPitchFont(
  220. IN HWND hWnd,
  221. IN int ControlId
  222. )
  223. /*++
  224. Routine Description:
  225. Set the font for the supplied control to the system's fixed pitch font. If
  226. the ControlId parameter is 0, the font is set in the supplied hWnd.
  227. Arguments:
  228. hWnd - Supplies the window (dialog box) handle that contains the
  229. control or the window handle where the font should be set.
  230. ControlId - Supplies the control id or xero if the hWnd is a window
  231. rather than a dialog handle.
  232. Return Value:
  233. BOOL - Returns TRUE if the font is succesfully set.
  234. --*/
  235. {
  236. HFONT hFont;
  237. hFont = GetStockObject( SYSTEM_FIXED_FONT );
  238. DbgHandleAssert( hFont );
  239. if( ControlId == 0 ) {
  240. HDC hDC;
  241. hDC = GetDC( hWnd );
  242. DbgHandleAssert( hDC );
  243. if( hDC == NULL ) {
  244. return FALSE;
  245. }
  246. SelectObject( hDC, hFont );
  247. } else {
  248. SendDlgItemMessage(
  249. hWnd,
  250. ControlId,
  251. WM_SETFONT,
  252. ( WPARAM ) hFont,
  253. ( LPARAM ) FALSE
  254. );
  255. }
  256. return TRUE;
  257. }