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.

262 lines
8.8 KiB

  1. /*---------------------------------------------**
  2. ** Copyright (c) 1998 Microsoft Corporation **
  3. ** All Rights reserved **
  4. ** **
  5. ** profiles.c **
  6. ** **
  7. ** Profiles dialog - TSREG **
  8. ** 07-01-98 a-clindh Created **
  9. **---------------------------------------------*/
  10. #include <windows.h>
  11. #include <commctrl.h>
  12. #include <TCHAR.H>
  13. #include "tsreg.h"
  14. #include "resource.h"
  15. PROFILE_KEY_INFO *g_pkfProfile;
  16. PROFILE_KEY_INFO *g_pkfStart;
  17. HWND g_hwndProfilesDlg;
  18. ///////////////////////////////////////////////////////////////////////////////
  19. INT_PTR CALLBACK ProfilePage(HWND hDlg, UINT nMsg,
  20. WPARAM wParam, LPARAM lParam)
  21. {
  22. static HWND hwndProfilesCBO;
  23. static HWND hwndProfilesEdit;
  24. static HKEY hKey;
  25. TCHAR lpszClientProfilePath[MAX_PATH];
  26. TCHAR lpszBuffer[MAXKEYSIZE];
  27. TCHAR lpszKeyName[MAXKEYSIZE];
  28. TCHAR lpszConfirm[MAX_MESSAGE_LEN + MAXKEYSIZE];
  29. TCHAR lpszDeleteCaption[90]; // for message box
  30. TCHAR lpszDeleteTitle[25]; // for message box
  31. TCHAR lpszSubKeyPath[MAX_PATH];
  32. TCHAR lpszText[MAXTEXTSIZE];
  33. ULONG lpPathLen = MAX_PATH;
  34. NMHDR *lpnmhdr;
  35. LPHELPINFO lphi;
  36. LRESULT i;
  37. int index;
  38. BOOL bContinue;
  39. lpnmhdr = (LPNMHDR) lParam;
  40. switch (nMsg) {
  41. case WM_INITDIALOG:
  42. hwndProfilesCBO = GetDlgItem(hDlg, IDC_CBO_PROFILES);
  43. hwndProfilesEdit = GetDlgItem(hDlg, IDC_EDIT_PROFILES);
  44. g_hwndProfilesDlg = hDlg;
  45. LoadKeyValues();
  46. LoadString(g_hInst, IDS_DEFAULT, lpszText, MAXTEXTSIZE);
  47. // display 'Default' in edit cell of combo box
  48. //
  49. i = SendMessage(hwndProfilesCBO,
  50. CB_FINDSTRING, 0,
  51. (LPARAM) lpszText);
  52. SendMessage(hwndProfilesCBO,
  53. CB_SETCURSEL, i, 0);
  54. break;
  55. case WM_NOTIFY:
  56. switch (lpnmhdr->code) {
  57. case PSN_HELP:
  58. lphi = (LPHELPINFO) lParam;
  59. WinHelp(lphi->hItemHandle,
  60. g_lpszPath, HELP_CONTENTS, lphi->iCtrlId);
  61. break;
  62. }
  63. break;
  64. case WM_HELP:
  65. lphi = (LPHELPINFO) lParam;
  66. WinHelp(lphi->hItemHandle,
  67. g_lpszPath, HELP_CONTEXTPOPUP, lphi->iCtrlId);
  68. break;
  69. case WM_COMMAND:
  70. switch LOWORD (wParam) {
  71. case IDC_BTN_LOAD:
  72. GetWindowText(hwndProfilesCBO, lpszBuffer, MAXKEYSIZE);
  73. // if string is null, exit routine
  74. //
  75. if (_tcscmp(lpszBuffer, TEXT("")) == 0) {
  76. LoadString(g_hInst, IDS_PROFILE_LOAD, lpszText, MAXTEXTSIZE);
  77. MessageBox(hDlg, lpszText, NULL, MB_OK | MB_ICONEXCLAMATION);
  78. SetFocus(hwndProfilesCBO);
  79. break;
  80. }
  81. ReloadKeys(lpszBuffer, hwndProfilesCBO);
  82. SetEditCell(lpszBuffer,
  83. hwndProfilesCBO);
  84. // change window caption
  85. ResetTitle(lpszBuffer);
  86. LoadString (g_hInst, IDS_PROFILE_LOADED,
  87. lpszConfirm, sizeof(lpszConfirm));
  88. LoadString (g_hInst, IDS_PROFILE_LOADED2,
  89. lpszText, MAXTEXTSIZE);
  90. _tcscat(lpszConfirm, lpszBuffer);
  91. _tcscat(lpszConfirm, lpszText);
  92. MessageBox(hDlg,
  93. lpszConfirm,
  94. TEXT("Profile Loaded"),
  95. MB_OK | MB_ICONEXCLAMATION);
  96. break;
  97. case IDC_BTN_SAVE:
  98. DialogBox(g_hInst,
  99. MAKEINTRESOURCE(IDD_SAVE_FORM),
  100. g_hwndProfilesDlg,
  101. SaveDialog);
  102. break;
  103. case IDC_BTN_DELETE:
  104. GetWindowText(hwndProfilesCBO, lpszBuffer, MAXKEYSIZE);
  105. if (_tcscmp(lpszBuffer, TEXT("")) == 0) {
  106. LoadString(g_hInst, IDS_PROFILE_DELETE, lpszText, MAXTEXTSIZE);
  107. MessageBox(hDlg, lpszText, NULL, MB_OK | MB_ICONEXCLAMATION);
  108. SetFocus(hwndProfilesCBO);
  109. break;
  110. }
  111. //
  112. // confirm delete
  113. //
  114. LoadString (g_hInst, IDS_DELETE_TITLE,
  115. lpszDeleteTitle,
  116. sizeof (lpszDeleteTitle));
  117. LoadString (g_hInst, IDS_DELETE_CAPTION,
  118. lpszDeleteCaption,
  119. sizeof (lpszDeleteCaption));
  120. i = MessageBox(hDlg, lpszDeleteCaption,
  121. lpszDeleteTitle,
  122. MB_YESNO | MB_ICONEXCLAMATION);
  123. if ( i == IDYES) {
  124. LoadString (g_hInst, IDS_PROFILE_PATH,
  125. lpszClientProfilePath,
  126. sizeof(lpszClientProfilePath));
  127. GetWindowText(hwndProfilesCBO,
  128. lpszBuffer, MAXKEYSIZE);
  129. _tcscpy(lpszSubKeyPath, lpszClientProfilePath);
  130. _tcscat(lpszSubKeyPath, TEXT("\\"));
  131. _tcscat(lpszSubKeyPath, lpszBuffer);
  132. //
  133. // delete all subkeys first
  134. //
  135. index = 0;
  136. if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszSubKeyPath, 0,
  137. KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
  138. do {
  139. if (RegEnumKeyEx(hKey, index, &lpszKeyName[0],
  140. &lpPathLen, NULL, NULL, NULL, NULL) ==
  141. ERROR_SUCCESS) {
  142. if (_tcscmp( lpszKeyName,
  143. TEXT("Default")) != 0) {
  144. RegDeleteKey(hKey,
  145. &lpszKeyName[0]);
  146. }
  147. bContinue = TRUE;
  148. index++;
  149. } else {
  150. bContinue = FALSE;
  151. }
  152. } while (bContinue == TRUE);
  153. RegCloseKey(hKey);
  154. }
  155. //
  156. // delete the parent key
  157. //
  158. if (_tcscmp( lpszBuffer,
  159. TEXT("Default")) == 0) {
  160. MessageBox(hDlg,
  161. TEXT("Can not delete default key."),
  162. NULL, MB_OK | MB_ICONEXCLAMATION);
  163. } else {
  164. if (RegOpenKeyEx(HKEY_CURRENT_USER,
  165. lpszClientProfilePath, 0,
  166. KEY_ALL_ACCESS, &hKey) ==
  167. ERROR_SUCCESS)
  168. {
  169. RegDeleteKey(hKey, &lpszBuffer[0]);
  170. RegCloseKey(hKey);
  171. }
  172. //
  173. // remove key from list box
  174. //
  175. i = SendMessage(hwndProfilesCBO,
  176. CB_FINDSTRING, 0,
  177. (LPARAM) lpszBuffer);
  178. SendMessage(hwndProfilesCBO,
  179. CB_DELETESTRING, i, 0);
  180. // reload the data struct with default key
  181. ReloadKeys(TEXT("Default"), hwndProfilesCBO);
  182. // change window caption
  183. ResetTitle(TEXT("Default"));
  184. SetEditCell(TEXT("Default"),
  185. hwndProfilesCBO);
  186. }
  187. } else {
  188. SetEditCell(lpszBuffer,
  189. hwndProfilesCBO);
  190. SetFocus(hwndProfilesEdit);
  191. }
  192. break;
  193. }
  194. }
  195. return (FALSE);
  196. }
  197. // end of file
  198. ///////////////////////////////////////////////////////////////////////////////