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.

224 lines
6.4 KiB

  1. /*---------------------------------------------**
  2. ** Copyright (c) 1998 Microsoft Corporation **
  3. ** All Rights reserved **
  4. ** **
  5. ** save.c **
  6. ** **
  7. ** Save dialog - TSREG **
  8. ** 07-01-98 a-clindh Created **
  9. **---------------------------------------------*/
  10. #include <windows.h>
  11. #include <commctrl.h>
  12. #include <TCHAR.H>
  13. #include <stdlib.h>
  14. #include "tsreg.h"
  15. #include "resource.h"
  16. int SaveKeys(HWND hDlg,
  17. HWND hwndEditSave,
  18. HWND hwndProfilesCBO);
  19. BOOL InitListViewItems(HWND hwndSaveList);
  20. BOOL InitListViewImageLists(HWND hwndSaveList);
  21. ///////////////////////////////////////////////////////////////////////////////
  22. INT_PTR CALLBACK SaveDialog(HWND hDlg, UINT nMsg,
  23. WPARAM wParam, LPARAM lParam)
  24. {
  25. TCHAR lpszBuffer[MAXKEYSIZE];
  26. static HWND hwndProfilesCBO;
  27. static HWND hwndSaveList;
  28. static HWND hwndEditSave;
  29. LPNMLISTVIEW lpnmlv;
  30. NMHDR *lpnmhdr;
  31. lpnmlv = (LPNMLISTVIEW) lParam;
  32. lpnmhdr = ((LPNMHDR)lParam);
  33. switch (nMsg) {
  34. case WM_INITDIALOG:
  35. hwndProfilesCBO = GetDlgItem(g_hwndProfilesDlg, IDC_CBO_PROFILES);
  36. hwndSaveList = GetDlgItem(hDlg, IDC_SAVE_LIST);
  37. hwndEditSave = GetDlgItem(hDlg, IDC_EDIT_KEY);
  38. InitListViewImageLists(hwndSaveList);
  39. InitListViewItems(hwndSaveList);
  40. SetFocus(hwndEditSave);
  41. break;
  42. case WM_NOTIFY:
  43. //
  44. // display text in edit box or save when user
  45. // clicks or double clicks an icon.
  46. //
  47. switch (lpnmlv->hdr.code) {
  48. case NM_DBLCLK:
  49. if (SaveKeys(hDlg, hwndEditSave, hwndProfilesCBO))
  50. EndDialog(hDlg, TRUE);
  51. break;
  52. case NM_CLICK:
  53. ListView_GetItemText(hwndSaveList,
  54. lpnmlv->iItem, 0, lpszBuffer,
  55. sizeof(lpszBuffer));
  56. SetWindowText(hwndEditSave, lpszBuffer);
  57. break;
  58. }
  59. break;
  60. case WM_COMMAND:
  61. switch LOWORD (wParam) {
  62. case IDOK:
  63. if (SaveKeys(hDlg, hwndEditSave, hwndProfilesCBO))
  64. EndDialog(hDlg, TRUE);
  65. break;
  66. case IDCANCEL:
  67. EndDialog(hDlg, FALSE);
  68. break;
  69. }
  70. break;
  71. }
  72. return (FALSE);
  73. }
  74. ///////////////////////////////////////////////////////////////////////////////
  75. BOOL InitListViewImageLists(HWND hwndSaveList)
  76. {
  77. HICON hiconItem = NULL; // icon for list view items
  78. HIMAGELIST himlSmall = NULL; // image list for other views
  79. himlSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
  80. GetSystemMetrics(SM_CYSMICON), TRUE, 1, 1);
  81. // Add an icon to the image list.
  82. hiconItem = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_FOLDER_ICON));
  83. if(( hiconItem != NULL) && (himlSmall != NULL)) {
  84. ImageList_AddIcon(himlSmall, hiconItem);
  85. DeleteObject(hiconItem);
  86. // Assign the image lists to the list view control.
  87. ListView_SetImageList(hwndSaveList, himlSmall, LVSIL_SMALL);
  88. }
  89. return TRUE;
  90. }
  91. ///////////////////////////////////////////////////////////////////////////////
  92. BOOL InitListViewItems(HWND hwndSaveList)
  93. {
  94. int i;
  95. LVITEM lvi;
  96. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  97. lvi.state = 0;
  98. lvi.stateMask = 0;
  99. lvi.iImage = 0;
  100. //
  101. // Get the key names and add them to the image list
  102. //
  103. g_pkfProfile = g_pkfStart;
  104. for (i = 0; i <= g_pkfProfile->Index; i++) {
  105. lvi.pszText = g_pkfProfile->KeyInfo->Key;
  106. lvi.iItem = i;
  107. lvi.iSubItem = 0;
  108. ListView_InsertItem(hwndSaveList, &lvi);
  109. g_pkfProfile = g_pkfProfile->Next;
  110. }
  111. return TRUE;
  112. }
  113. ///////////////////////////////////////////////////////////////////////////////
  114. int SaveKeys(HWND hDlg,
  115. HWND hwndEditSave,
  116. HWND hwndProfilesCBO)
  117. {
  118. TCHAR lpszClientProfilePath[MAX_PATH] = TEXT("");
  119. TCHAR lpszSubKeyPath[MAX_PATH];
  120. TCHAR lpszBuffer[MAXKEYSIZE];
  121. TCHAR lpszText[MAXTEXTSIZE];
  122. static HKEY hKey;
  123. int i;
  124. GetWindowText(hwndEditSave, lpszBuffer, MAXKEYSIZE);
  125. // check for null string
  126. //
  127. if (_tcscmp(lpszBuffer, TEXT("")) == 0) {
  128. LoadString(g_hInst, IDS_KEY_SAVE, lpszText, MAXTEXTSIZE);
  129. MessageBox(hDlg, lpszText, NULL, MB_OK | MB_ICONEXCLAMATION);
  130. SetFocus(hwndEditSave);
  131. return 0;
  132. }
  133. LoadString (g_hInst, IDS_PROFILE_PATH,
  134. lpszClientProfilePath,
  135. sizeof(lpszClientProfilePath));
  136. _tcscpy(lpszSubKeyPath, lpszClientProfilePath);
  137. _tcscat(lpszSubKeyPath, TEXT("\\"));
  138. _tcscat(lpszSubKeyPath, lpszBuffer);
  139. //
  140. // only add values to the combo box that aren't already listed
  141. //
  142. if (SendMessage(hwndProfilesCBO, CB_FINDSTRING, 0,
  143. (LPARAM) lpszBuffer) == CB_ERR) {
  144. SendMessage(hwndProfilesCBO, CB_ADDSTRING, 0,
  145. (LPARAM) lpszBuffer);
  146. }
  147. //
  148. // change window caption
  149. //
  150. ResetTitle(lpszBuffer);
  151. //
  152. // save the settings to the registry
  153. //
  154. WriteBlankKey(lpszSubKeyPath);//save even if nothing is set
  155. SaveBitmapSettings(lpszSubKeyPath);
  156. SaveSettings(g_hwndMiscDlg, DEDICATEDINDEX, IDC_DEDICATED_ENABLED,
  157. IDC_DEDICATED_DISABLED, lpszSubKeyPath);
  158. SaveSettings(g_hwndMiscDlg, SHADOWINDEX, IDC_SHADOW_DISABLED,
  159. IDC_SHADOW_ENABLED, lpszSubKeyPath);
  160. for (i = 2; i < KEYCOUNT; i++) {
  161. if (g_KeyInfo[i].CurrentKeyValue != g_KeyInfo[i].DefaultKeyValue)
  162. SetRegKey(i, lpszSubKeyPath);
  163. else
  164. DeleteRegKey(i, lpszSubKeyPath);
  165. }
  166. //
  167. // release memory and re-read key values for all defined
  168. // profiles
  169. //
  170. ReloadKeys(lpszBuffer, hwndProfilesCBO);
  171. SetEditCell(lpszBuffer,
  172. hwndProfilesCBO);
  173. return 1;
  174. }//////////////////////////////////////////////////////////////////////////////