Leaked source code of windows server 2003
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.

321 lines
7.9 KiB

  1. /*++
  2. Microsoft Confidential
  3. Copyright (c) 1992-1999 Microsoft Corporation
  4. All rights reserved
  5. Module Name:
  6. edtenvar.h
  7. Abstract:
  8. Implements the Edit Environment Variables dialog of the
  9. System Control Panel Applet
  10. Author:
  11. Scott Hallock (scotthal) 11-Nov-1997
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. #ifdef EXT_DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. #include "edtenvar.h"
  20. #include "resource.h"
  21. #include "..\common\util.h"
  22. // Global Variables
  23. UINT g_VarType = INVALID_VAR_TYPE;
  24. UINT g_EditType = INVALID_EDIT_TYPE;
  25. TCHAR g_szVarName[BUFZ];
  26. TCHAR g_szVarValue[BUFZ];
  27. // Help IDs
  28. /*DWORD aEditEnvVarsHelpIds[] = {
  29. IDC_ENVVAR_EDIT_NAME_LABEL, (IDH_ENV_EDIT + 0),
  30. IDC_ENVVAR_EDIT_NAME, (IDH_ENV_EDIT + 0),
  31. IDC_ENVVAR_EDIT_VALUE_LABEL, (IDH_ENV_EDIT + 1),
  32. IDC_ENVVAR_EDIT_VALUE, (IDH_ENV_EDIT + 1),
  33. 0, 0
  34. };
  35. */
  36. // Function prototypes
  37. BOOL InitEnvVarsEdit(HWND hDlg);
  38. BOOL EnvVarsEditHandleCommand(HWND hDlg,
  39. WPARAM wParam,
  40. LPARAM lParam);
  41. // Function implementation
  42. //------------------------------------------------
  43. INT_PTR APIENTRY EnvVarsEditDlg(HWND hDlg,
  44. UINT uMsg,
  45. WPARAM wParam,
  46. LPARAM lParam)
  47. /*++
  48. Routine Description:
  49. Handles messages sent to the New.../Edit... dialog.
  50. Arguments:
  51. hDlg -
  52. Supplies the window handle
  53. uMsg -
  54. Supplies the message being sent
  55. wParam -
  56. Supplies message parameter
  57. lParam -
  58. Supplies message parameter
  59. Return Value:
  60. TRUE if message was handled.
  61. FALSE if message was unhandled.
  62. --*/
  63. {
  64. BOOL fInitializing = FALSE;
  65. switch (uMsg) {
  66. case WM_INITDIALOG: {
  67. BOOL fSuccess = FALSE;
  68. fInitializing = TRUE;
  69. fSuccess = InitEnvVarsEdit(hDlg);
  70. if (!fSuccess) {
  71. EndDialog(hDlg, EDIT_ERROR);
  72. } // if
  73. fInitializing = FALSE;
  74. break;
  75. } // case WM_INITDIALOG
  76. case WM_COMMAND:
  77. return EnvVarsEditHandleCommand(hDlg, wParam, lParam);
  78. break;
  79. case WM_HELP: // F1
  80. // WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP, (DWORD) (LPSTR) aEditEnvVarsHelpIds);
  81. break;
  82. case WM_CONTEXTMENU: // right mouse click
  83. // WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU, (DWORD) (LPSTR) aEditEnvVarsHelpIds);
  84. break;
  85. default:
  86. return(FALSE);
  87. break;
  88. } // switch (uMsg)
  89. return(TRUE);
  90. }
  91. //------------------------------------------------
  92. BOOL InitEnvVarsEdit(HWND hDlg)
  93. /*++
  94. Routine Description:
  95. Initializes the Edit Environment Variables dialog by placing initial
  96. values into the text editing controls if necessary.
  97. Arguments:
  98. hDlg -
  99. Supplies window handle
  100. Return Value:
  101. TRUE if successful
  102. FALSE if an error occurs
  103. --*/
  104. {
  105. TCHAR szCaption[EDIT_ENVVAR_CAPTION_LENGTH] = {0};
  106. BOOL fRetVal = FALSE;
  107. INT nResult = 0;
  108. __try {
  109. // limit variable names to 259 chars (arbitrary value, but will be in line with shell UI)
  110. SendDlgItemMessage(hDlg, IDC_ENVVAR_EDIT_NAME, EM_LIMITTEXT, 259, 0);
  111. // limit variable values to 1023 chars (arbitrary value, but will be in line with shell UI)
  112. SendDlgItemMessage(hDlg, IDC_ENVVAR_EDIT_VALUE, EM_LIMITTEXT, 1023, 0);
  113. switch (g_EditType) {
  114. //
  115. // If this is to be a New.. dialog, we only need to
  116. // load the proper capiton for the variable type
  117. //
  118. case NEW_VAR:
  119. switch (g_VarType) {
  120. case SYSTEM_VAR:
  121. nResult = LoadString(
  122. HINST_THISDLL,
  123. IDS_NEW_SYSVAR_CAPTION,
  124. szCaption,
  125. EDIT_ENVVAR_CAPTION_LENGTH
  126. );
  127. break;
  128. case USER_VAR:
  129. nResult = LoadString(
  130. HINST_THISDLL,
  131. IDS_NEW_USERVAR_CAPTION,
  132. szCaption,
  133. EDIT_ENVVAR_CAPTION_LENGTH
  134. );
  135. break;
  136. default:
  137. __leave;
  138. break;
  139. } // switch (g_VarType)
  140. break;
  141. //
  142. // If this is to be an Edit.. dialog, then we need to load the
  143. // proper caption and fill in initial values for the edit
  144. // controls
  145. //
  146. case EDIT_VAR:
  147. switch (g_VarType) {
  148. case SYSTEM_VAR:
  149. nResult = LoadString(
  150. HINST_THISDLL,
  151. IDS_EDIT_SYSVAR_CAPTION,
  152. szCaption,
  153. EDIT_ENVVAR_CAPTION_LENGTH
  154. );
  155. break;
  156. case USER_VAR:
  157. nResult = LoadString(
  158. HINST_THISDLL,
  159. IDS_EDIT_USERVAR_CAPTION,
  160. szCaption,
  161. EDIT_ENVVAR_CAPTION_LENGTH
  162. );
  163. break;
  164. default:
  165. __leave;
  166. break;
  167. } // switch (g_VarType)
  168. SetDlgItemText(
  169. hDlg,
  170. IDC_ENVVAR_EDIT_NAME,
  171. g_szVarName
  172. );
  173. SetDlgItemText(
  174. hDlg,
  175. IDC_ENVVAR_EDIT_VALUE,
  176. g_szVarValue
  177. );
  178. break;
  179. } // switch (g_EditType)
  180. fRetVal = SendMessage(
  181. GetDlgItem(hDlg, IDC_ENVVAR_EDIT_NAME),
  182. EM_SETSEL,
  183. 0,
  184. -1
  185. ) ? TRUE : FALSE;
  186. fRetVal = SendMessage(
  187. GetDlgItem(hDlg, IDC_ENVVAR_EDIT_VALUE),
  188. EM_SETSEL,
  189. 0,
  190. -1
  191. ) ? TRUE : FALSE;
  192. SetFocus(GetDlgItem(hDlg, IDC_ENVVAR_EDIT_NAME));
  193. fRetVal = SetWindowText(hDlg, szCaption);
  194. } // __try
  195. __finally {
  196. //
  197. // Nothing to clean up. __try is only there for __leave on
  198. // failure capability.
  199. //
  200. } // __finally
  201. return(fRetVal);
  202. }
  203. //------------------------------------------------
  204. BOOL EnvVarsEditHandleCommand(HWND hDlg,
  205. WPARAM wParam,
  206. LPARAM lParam)
  207. /*++
  208. Routine Description:
  209. Handles WM_COMMAND messages sent to the Edit Environment Variables
  210. dialog
  211. Arguments:
  212. hDlg -
  213. Supplies window handle
  214. wParam -
  215. Supplies message parameter
  216. lParam -
  217. Supplies message parameter
  218. Return Value:
  219. TRUE if message was handled
  220. FALSE if message was unhandled
  221. --*/
  222. {
  223. switch (LOWORD(wParam)) {
  224. case IDOK:
  225. GetDlgItemText(
  226. hDlg,
  227. IDC_ENVVAR_EDIT_NAME,
  228. g_szVarName,
  229. BUFZ
  230. );
  231. GetDlgItemText(
  232. hDlg,
  233. IDC_ENVVAR_EDIT_VALUE,
  234. g_szVarValue,
  235. BUFZ
  236. );
  237. EndDialog(hDlg, EDIT_CHANGE);
  238. break;
  239. case IDCANCEL:
  240. EndDialog(hDlg, EDIT_NO_CHANGE);
  241. break;
  242. default:
  243. return(FALSE);
  244. break;
  245. } // switch (LOWORD(wParam))
  246. return(TRUE);
  247. }