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.

219 lines
3.5 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1995 - 1996
  3. All rights reserved.
  4. Module Name:
  5. ctl.cxx
  6. Abstract:
  7. Dialog control code.
  8. Author:
  9. Albert Ting (AlbertT) 26-Aug-1995
  10. Revision History:
  11. Lazar Ivanov (LazarI) Oct-2000 - added vEnableControls
  12. --*/
  13. #include "precomp.hxx"
  14. #pragma hdrstop
  15. BOOL
  16. bSetEditText(
  17. HWND hDlg,
  18. UINT uControl,
  19. LPCTSTR pszString
  20. )
  21. {
  22. SPLASSERT( hDlg );
  23. SPLASSERT( uControl );
  24. SendDlgItemMessage( hDlg,
  25. uControl,
  26. WM_SETTEXT,
  27. 0,
  28. (LPARAM)(pszString ?
  29. pszString :
  30. gszNULL ));
  31. return TRUE;
  32. }
  33. /*++
  34. Routine Name:
  35. bSetEditTextFormat
  36. Routine Description:
  37. Sets the text of an edit control using a printf style format
  38. string. Note the format string and any following string
  39. arguments must be TCHARS.
  40. Arguments:
  41. hDlg - handle to dialog which contains the edit control
  42. uControl - edit control ID
  43. pszString - pointer to printf style format string.
  44. Arguments - variable number of arguments matching the format string
  45. Return Value:
  46. TRUE if format string was created and updated to control,
  47. FALSE if error occured allocating format buffer or setting
  48. control value.
  49. --*/
  50. BOOL
  51. bSetEditTextFormat(
  52. HWND hDlg,
  53. UINT uControl,
  54. LPCTSTR pszString,
  55. ...
  56. )
  57. {
  58. SPLASSERT( hDlg );
  59. SPLASSERT( uControl );
  60. LPTSTR pszBuffer = new TCHAR [kMaxEditText];
  61. if( !pszBuffer )
  62. return FALSE;
  63. va_list pArgs;
  64. va_start( pArgs, pszString );
  65. wvsprintf( pszBuffer, pszString, pArgs );
  66. bSetEditText( hDlg, uControl, pszBuffer );
  67. delete [] pszBuffer;
  68. va_end( pArgs );
  69. return TRUE;
  70. }
  71. BOOL
  72. bGetEditText(
  73. IN HWND hDlg,
  74. IN UINT uControl,
  75. OUT TString& strDest
  76. )
  77. /*++
  78. Routine Description:
  79. Retrieves the edit text from a control. If the edit control is
  80. empty, the string holds szNULL.
  81. Arguments:
  82. hDlg - Dlg that owns the control.
  83. uControl - Control ID.
  84. strDest - TString to receive string.
  85. Return Value:
  86. TRUE = success, FALSE = fail.
  87. --*/
  88. {
  89. TCHAR szString[kStrMax*2];
  90. szString[0] = 0;
  91. SendDlgItemMessage( hDlg,
  92. uControl,
  93. WM_GETTEXT,
  94. COUNTOF( szString ),
  95. (LPARAM)szString );
  96. return strDest.bUpdate( szString );
  97. }
  98. VOID
  99. vEnableCtl(
  100. HWND hDlg,
  101. UINT uControl,
  102. BOOL bEnable
  103. )
  104. {
  105. EnableWindow( GetDlgItem( hDlg, uControl ), bEnable );
  106. }
  107. VOID
  108. vSetCheck(
  109. HWND hDlg,
  110. UINT uControl,
  111. BOOL bSet
  112. )
  113. /*++
  114. Routine Description:
  115. Sets a checkbox control on or off.
  116. Arguments:
  117. hDlg - Owning dialog control.
  118. uControl - Checkbox to modify.
  119. bSet - 0 indicates uncheck, non-zero indicates check. (Note this
  120. is not a strict BOOL, _any_ non-zero value is TRUE.)
  121. Return Value:
  122. None
  123. --*/
  124. {
  125. CheckDlgButton( hDlg,
  126. uControl,
  127. bSet ? BST_CHECKED : BST_UNCHECKED );
  128. }
  129. BOOL
  130. bGetCheck(
  131. IN HWND hDlg,
  132. IN UINT uControl
  133. )
  134. {
  135. return IsDlgButtonChecked( hDlg, uControl );
  136. }
  137. VOID
  138. vEnableControls(
  139. IN HWND hDlg,
  140. IN BOOL bEnable,
  141. IN UINT arrIDs[],
  142. IN UINT uCount
  143. )
  144. {
  145. HWND hwnd = NULL;
  146. for( UINT u = 0; u < uCount; u++ )
  147. {
  148. hwnd = GetDlgItem(hDlg, arrIDs[u]);
  149. if( hwnd )
  150. {
  151. EnableWindow(hwnd, bEnable);
  152. }
  153. }
  154. }