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.

366 lines
8.0 KiB

  1. /*++
  2. Microsoft Confidential
  3. Copyright (c) 1992-1997 Microsoft Corporation
  4. All rights reserved
  5. Module Name:
  6. edtenvar.c
  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 "sysdm.h"
  15. //
  16. // Global Variables
  17. //
  18. UINT g_VarType = INVALID_VAR_TYPE;
  19. UINT g_EditType = INVALID_EDIT_TYPE;
  20. TCHAR g_szVarName[BUFZ];
  21. TCHAR g_szVarValue[BUFZ];
  22. //
  23. // Help IDs
  24. //
  25. DWORD aEditEnvVarsHelpIds[] = {
  26. IDC_ENVVAR_EDIT_NAME_LABEL, (IDH_ENV_EDIT + 0),
  27. IDC_ENVVAR_EDIT_NAME, (IDH_ENV_EDIT + 0),
  28. IDC_ENVVAR_EDIT_VALUE_LABEL, (IDH_ENV_EDIT + 1),
  29. IDC_ENVVAR_EDIT_VALUE, (IDH_ENV_EDIT + 1),
  30. 0, 0
  31. };
  32. //
  33. // Function prototypes
  34. //
  35. BOOL
  36. InitEnvVarsEdit(
  37. IN HWND hDlg
  38. );
  39. BOOL
  40. EnvVarsEditHandleCommand(
  41. IN HWND hDlg,
  42. IN WPARAM wParam,
  43. IN LPARAM lParam
  44. );
  45. //
  46. // Function implementation
  47. //
  48. INT_PTR
  49. APIENTRY
  50. EnvVarsEditDlg(
  51. IN HWND hDlg,
  52. IN UINT uMsg,
  53. IN WPARAM wParam,
  54. IN LPARAM lParam
  55. )
  56. /*++
  57. Routine Description:
  58. Handles messages sent to the New.../Edit... dialog.
  59. Arguments:
  60. hDlg -
  61. Supplies the window handle
  62. uMsg -
  63. Supplies the message being sent
  64. wParam -
  65. Supplies message parameter
  66. lParam -
  67. Supplies message parameter
  68. Return Value:
  69. TRUE if message was handled.
  70. FALSE if message was unhandled.
  71. --*/
  72. {
  73. BOOL fInitializing = FALSE;
  74. switch (uMsg) {
  75. case WM_INITDIALOG: {
  76. BOOL fSuccess = FALSE;
  77. fInitializing = TRUE;
  78. fSuccess = InitEnvVarsEdit(hDlg);
  79. if (!fSuccess) {
  80. EndDialog(hDlg, EDIT_ERROR);
  81. } // if
  82. fInitializing = FALSE;
  83. break;
  84. } // case WM_INITDIALOG
  85. case WM_COMMAND:
  86. return EnvVarsEditHandleCommand(hDlg, wParam, lParam);
  87. break;
  88. case WM_HELP: // F1
  89. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP, (DWORD_PTR) (LPSTR) aEditEnvVarsHelpIds);
  90. break;
  91. case WM_CONTEXTMENU: // right mouse click
  92. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU, (DWORD_PTR) (LPSTR) aEditEnvVarsHelpIds);
  93. break;
  94. default:
  95. return(FALSE);
  96. break;
  97. } // switch (uMsg)
  98. return(TRUE);
  99. }
  100. BOOL
  101. InitEnvVarsEdit(
  102. IN HWND hDlg
  103. )
  104. /*++
  105. Routine Description:
  106. Initializes the Edit Environment Variables dialog by placing initial
  107. values into the text editing controls if necessary.
  108. Arguments:
  109. hDlg -
  110. Supplies window handle
  111. Return Value:
  112. TRUE if successful
  113. FALSE if an error occurs
  114. --*/
  115. {
  116. TCHAR szCaption[EDIT_ENVVAR_CAPTION_LENGTH];
  117. LRESULT fRetVal = FALSE;
  118. INT nResult = 0;
  119. ASSERT(INVALID_EDIT_TYPE != g_EditType);
  120. ASSERT(INVALID_VAR_TYPE != g_VarType);
  121. __try {
  122. fRetVal = SendMessage(
  123. GetDlgItem(hDlg, IDC_ENVVAR_EDIT_NAME),
  124. EM_LIMITTEXT,
  125. MAX_PATH - 1,
  126. 0
  127. );
  128. fRetVal = SendMessage(
  129. GetDlgItem(hDlg, IDC_ENVVAR_EDIT_VALUE),
  130. EM_LIMITTEXT,
  131. MAX_VALUE_LEN - 1,
  132. 0
  133. );
  134. switch (g_EditType) {
  135. //
  136. // If this is to be a New.. dialog, we only need to
  137. // load the proper capiton for the variable type
  138. //
  139. case NEW_VAR:
  140. switch (g_VarType) {
  141. case SYSTEM_VAR:
  142. nResult = LoadString(
  143. hInstance,
  144. IDS_NEW_SYSVAR_CAPTION,
  145. szCaption,
  146. EDIT_ENVVAR_CAPTION_LENGTH
  147. );
  148. break;
  149. case USER_VAR:
  150. nResult = LoadString(
  151. hInstance,
  152. IDS_NEW_USERVAR_CAPTION,
  153. szCaption,
  154. EDIT_ENVVAR_CAPTION_LENGTH
  155. );
  156. break;
  157. default:
  158. __leave;
  159. break;
  160. } // switch (g_VarType)
  161. //
  162. // Set the focus to the "Name" field
  163. // SetFocus() doesn't want to work here
  164. //
  165. PostMessage(
  166. hDlg,
  167. WM_NEXTDLGCTL,
  168. (WPARAM) GetDlgItem(hDlg, IDC_ENVVAR_EDIT_NAME),
  169. (LPARAM) TRUE
  170. );
  171. break;
  172. //
  173. // If this is to be an Edit.. dialog, then we need to load the
  174. // proper caption and fill in initial values for the edit
  175. // controls
  176. //
  177. case EDIT_VAR:
  178. switch (g_VarType) {
  179. case SYSTEM_VAR:
  180. nResult = LoadString(
  181. hInstance,
  182. IDS_EDIT_SYSVAR_CAPTION,
  183. szCaption,
  184. EDIT_ENVVAR_CAPTION_LENGTH
  185. );
  186. break;
  187. case USER_VAR:
  188. nResult = LoadString(
  189. hInstance,
  190. IDS_EDIT_USERVAR_CAPTION,
  191. szCaption,
  192. EDIT_ENVVAR_CAPTION_LENGTH
  193. );
  194. break;
  195. default:
  196. __leave;
  197. break;
  198. } // switch (g_VarType)
  199. SetDlgItemText(
  200. hDlg,
  201. IDC_ENVVAR_EDIT_NAME,
  202. g_szVarName
  203. );
  204. SetDlgItemText(
  205. hDlg,
  206. IDC_ENVVAR_EDIT_VALUE,
  207. g_szVarValue
  208. );
  209. //
  210. // Set the focus to the "Value" field
  211. // SetFocus() doesn't want to work here
  212. //
  213. PostMessage(
  214. hDlg,
  215. WM_NEXTDLGCTL,
  216. (WPARAM) GetDlgItem(hDlg, IDC_ENVVAR_EDIT_VALUE),
  217. (LPARAM) TRUE
  218. );
  219. break;
  220. } // switch (g_EditType)
  221. fRetVal = SendMessage(
  222. GetDlgItem(hDlg, IDC_ENVVAR_EDIT_NAME),
  223. EM_SETSEL,
  224. 0,
  225. -1
  226. );
  227. fRetVal = SendMessage(
  228. GetDlgItem(hDlg, IDC_ENVVAR_EDIT_VALUE),
  229. EM_SETSEL,
  230. 0,
  231. -1
  232. );
  233. fRetVal = SetWindowText(hDlg, szCaption);
  234. } // __try
  235. __finally {
  236. //
  237. // Nothing to clean up. __try is only there for __leave on
  238. // failure capability.
  239. //
  240. } // __finally
  241. return fRetVal ? TRUE : FALSE;
  242. }
  243. BOOL
  244. EnvVarsEditHandleCommand(
  245. IN HWND hDlg,
  246. IN WPARAM wParam,
  247. IN LPARAM lParam
  248. )
  249. /*++
  250. Routine Description:
  251. Handles WM_COMMAND messages sent to the Edit Environment Variables
  252. dialog
  253. Arguments:
  254. hDlg -
  255. Supplies window handle
  256. wParam -
  257. Supplies message parameter
  258. lParam -
  259. Supplies message parameter
  260. Return Value:
  261. TRUE if message was handled
  262. FALSE if message was unhandled
  263. --*/
  264. {
  265. switch (LOWORD(wParam)) {
  266. case IDOK:
  267. GetDlgItemText(
  268. hDlg,
  269. IDC_ENVVAR_EDIT_NAME,
  270. g_szVarName,
  271. BUFZ
  272. );
  273. GetDlgItemText(
  274. hDlg,
  275. IDC_ENVVAR_EDIT_VALUE,
  276. g_szVarValue,
  277. BUFZ
  278. );
  279. EndDialog(hDlg, EDIT_CHANGE);
  280. break;
  281. case IDCANCEL:
  282. EndDialog(hDlg, EDIT_NO_CHANGE);
  283. break;
  284. default:
  285. return(FALSE);
  286. break;
  287. } // switch (LOWORD(wParam))
  288. return(TRUE);
  289. }