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.

420 lines
11 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1994
  4. *
  5. * TITLE: REGCDHK.C
  6. *
  7. * VERSION: 4.0
  8. *
  9. * AUTHOR: Tracy Sharpe
  10. *
  11. * DATE: 21 Nov 1993
  12. *
  13. * Common dialog box hook functions for the Registry Editor.
  14. *
  15. *******************************************************************************/
  16. #include "pch.h"
  17. #include "regedit.h"
  18. #include "regkey.h"
  19. #include "regcdhk.h"
  20. #include "regresid.h"
  21. #include "reghelp.h"
  22. // Buffer to store the starting path for a registry export or print operation.
  23. TCHAR g_SelectedPath[SIZE_SELECTED_PATH];
  24. // TRUE if registry operation should be applied to the entire registry or to
  25. // only start at g_SelectedPath.
  26. BOOL g_fRangeAll;
  27. // Contains the resource identifier for the dialog that is currently being
  28. // used. Assumes that there is only one instance of a hook dialog at a time.
  29. UINT g_RegCommDlgDialogTemplate;
  30. const DWORD s_RegCommDlgExportHelpIDs[] = {
  31. stc32, NO_HELP,
  32. IDC_EXPORTRANGE, IDH_REGEDIT_EXPORT,
  33. IDC_RANGEALL, IDH_REGEDIT_EXPORT,
  34. IDC_RANGESELECTEDPATH, IDH_REGEDIT_EXPORT,
  35. IDC_SELECTEDPATH, IDH_REGEDIT_EXPORT,
  36. 0, 0
  37. };
  38. const DWORD s_RegCommDlgPrintHelpIDs[] = {
  39. IDC_EXPORTRANGE, IDH_REGEDIT_PRINTRANGE,
  40. IDC_RANGEALL, IDH_REGEDIT_PRINTRANGE,
  41. IDC_RANGESELECTEDPATH, IDH_REGEDIT_PRINTRANGE,
  42. IDC_SELECTEDPATH, IDH_REGEDIT_PRINTRANGE,
  43. 0, 0
  44. };
  45. BOOL
  46. PASCAL
  47. RegCommDlg_OnInitDialog(
  48. HWND hWnd,
  49. HWND hFocusWnd,
  50. LPARAM lParam
  51. );
  52. LRESULT
  53. PASCAL
  54. RegCommDlg_OnNotify(
  55. HWND hWnd,
  56. int DlgItem,
  57. LPNMHDR lpNMHdr
  58. );
  59. UINT_PTR
  60. PASCAL
  61. RegCommDlg_OnCommand(
  62. HWND hWnd,
  63. int DlgItem,
  64. UINT NotificationCode
  65. );
  66. BOOL
  67. PASCAL
  68. RegCommDlg_ValidateSelectedPath(
  69. HWND hWnd,
  70. BOOL fIsFileDialog
  71. );
  72. /*******************************************************************************
  73. *
  74. * RegCommDlgHookProc
  75. *
  76. * DESCRIPTION:
  77. * Callback procedure for the RegCommDlg common dialog box.
  78. *
  79. * PARAMETERS:
  80. * hWnd, handle of RegCommDlg window.
  81. * Message,
  82. * wParam,
  83. * lParam,
  84. * (returns),
  85. *
  86. *******************************************************************************/
  87. UINT_PTR
  88. CALLBACK
  89. RegCommDlgHookProc(
  90. HWND hWnd,
  91. UINT Message,
  92. WPARAM wParam,
  93. LPARAM lParam
  94. )
  95. {
  96. int DlgItem;
  97. const DWORD FAR* lpHelpIDs;
  98. switch (Message) {
  99. HANDLE_MSG(hWnd, WM_INITDIALOG, RegCommDlg_OnInitDialog);
  100. case WM_NOTIFY:
  101. SetDlgMsgResult(hWnd, WM_NOTIFY, HANDLE_WM_NOTIFY(hWnd, wParam,
  102. lParam, RegCommDlg_OnNotify));
  103. return TRUE;
  104. case WM_COMMAND:
  105. return RegCommDlg_OnCommand(hWnd, GET_WM_COMMAND_ID(wParam, lParam),
  106. GET_WM_COMMAND_CMD(wParam, lParam));
  107. case WM_HELP:
  108. //
  109. // We only want to intercept help messages for controls that we are
  110. // responsible for.
  111. //
  112. DlgItem = GetDlgCtrlID(((LPHELPINFO) lParam)-> hItemHandle);
  113. if (DlgItem < IDC_FIRSTREGCOMMDLGID || DlgItem >
  114. IDC_LASTREGCOMMDLGID)
  115. break;
  116. lpHelpIDs = (g_RegCommDlgDialogTemplate == IDD_REGEXPORT) ?
  117. s_RegCommDlgExportHelpIDs : s_RegCommDlgPrintHelpIDs;
  118. WinHelp(((LPHELPINFO) lParam)-> hItemHandle, g_pHelpFileName,
  119. HELP_WM_HELP, (ULONG_PTR) lpHelpIDs);
  120. return TRUE;
  121. case WM_CONTEXTMENU:
  122. //
  123. // We only want to intercept help messages for controls that we are
  124. // responsible for.
  125. //
  126. DlgItem = GetDlgCtrlID((HWND) wParam);
  127. if (g_RegCommDlgDialogTemplate == IDD_REGEXPORT)
  128. lpHelpIDs = s_RegCommDlgExportHelpIDs;
  129. else {
  130. if (DlgItem < IDC_FIRSTREGCOMMDLGID || DlgItem >
  131. IDC_LASTREGCOMMDLGID)
  132. break;
  133. lpHelpIDs = s_RegCommDlgPrintHelpIDs;
  134. }
  135. WinHelp((HWND) wParam, g_pHelpFileName, HELP_CONTEXTMENU, (ULONG_PTR) lpHelpIDs);
  136. return TRUE;
  137. }
  138. return FALSE;
  139. }
  140. /*******************************************************************************
  141. *
  142. * RegCommDlg_OnInitDialog
  143. *
  144. * DESCRIPTION:
  145. * Initializes the RegCommDlg dialog box.
  146. *
  147. * PARAMETERS:
  148. * hWnd, handle of RegCommDlg window.
  149. * hFocusWnd, handle of control to receive the default keyboard focus.
  150. * lParam, additional initialization data passed by dialog creation function.
  151. * (returns), TRUE to set focus to hFocusWnd, else FALSE to prevent a
  152. * keyboard focus from being set.
  153. *
  154. *******************************************************************************/
  155. BOOL
  156. PASCAL
  157. RegCommDlg_OnInitDialog(
  158. HWND hWnd,
  159. HWND hFocusWnd,
  160. LPARAM lParam
  161. )
  162. {
  163. HWND hKeyTreeWnd;
  164. HTREEITEM hSelectedTreeItem;
  165. int DlgItem;
  166. g_RegEditData.uExportFormat = FILE_TYPE_REGEDIT5;
  167. hKeyTreeWnd = g_RegEditData.hKeyTreeWnd;
  168. hSelectedTreeItem = TreeView_GetSelection(hKeyTreeWnd);
  169. KeyTree_BuildKeyPath( hKeyTreeWnd,
  170. hSelectedTreeItem,
  171. g_SelectedPath,
  172. ARRAYSIZE(g_SelectedPath),
  173. BKP_TOSYMBOLICROOT);
  174. SetDlgItemText(hWnd, IDC_SELECTEDPATH, g_SelectedPath);
  175. DlgItem = (TreeView_GetParent(hKeyTreeWnd, hSelectedTreeItem) == NULL) ?
  176. IDC_RANGEALL : IDC_RANGESELECTEDPATH;
  177. CheckRadioButton(hWnd, IDC_RANGEALL, IDC_RANGESELECTEDPATH, DlgItem);
  178. return TRUE;
  179. UNREFERENCED_PARAMETER(hFocusWnd);
  180. UNREFERENCED_PARAMETER(lParam);
  181. }
  182. /*******************************************************************************
  183. *
  184. * RegCommDlg_OnNotify
  185. *
  186. * DESCRIPTION:
  187. *
  188. * PARAMETERS:
  189. * hWnd, handle of RegCommDlg window.
  190. * DlgItem, identifier of control.
  191. * lpNMHdr, control notification data.
  192. *
  193. *******************************************************************************/
  194. LRESULT
  195. PASCAL
  196. RegCommDlg_OnNotify(
  197. HWND hWnd,
  198. int DlgItem,
  199. LPNMHDR lpNMHdr
  200. )
  201. {
  202. HWND hControlWnd;
  203. RECT DialogRect;
  204. RECT ControlRect;
  205. int dxChange;
  206. LPOFNOTIFY lpon;
  207. switch (lpNMHdr-> code) {
  208. case CDN_INITDONE:
  209. GetWindowRect(hWnd, &DialogRect);
  210. // Use window coordinates because it works for mirrored
  211. // and non mirrored windows.
  212. MapWindowPoints(NULL, hWnd, (LPPOINT)&DialogRect, 2);
  213. hControlWnd = GetDlgItem(hWnd, IDC_EXPORTRANGE);
  214. GetWindowRect(hControlWnd, &ControlRect);
  215. MapWindowPoints(NULL, hWnd, (LPPOINT)&ControlRect, 2);
  216. dxChange = DialogRect.right - ControlRect.right -
  217. (ControlRect.left - DialogRect.left);
  218. SetWindowPos(hControlWnd, NULL, 0, 0, ControlRect.right -
  219. ControlRect.left + dxChange, ControlRect.bottom -
  220. ControlRect.top, SWP_NOMOVE | SWP_NOZORDER);
  221. hControlWnd = GetDlgItem(hWnd, IDC_SELECTEDPATH);
  222. GetWindowRect(hControlWnd, &ControlRect);
  223. MapWindowPoints(NULL, hWnd, (LPPOINT)&ControlRect, 2);
  224. SetWindowPos(hControlWnd, NULL, 0, 0, ControlRect.right -
  225. ControlRect.left + dxChange, ControlRect.bottom -
  226. ControlRect.top, SWP_NOMOVE | SWP_NOZORDER);
  227. break;
  228. case CDN_TYPECHANGE:
  229. // lpon->lpOFN->nFilterIndex corresponds to the format types in
  230. // regdef.h
  231. lpon = (LPOFNOTIFY) lpNMHdr;
  232. g_RegEditData.uExportFormat = lpon->lpOFN->nFilterIndex;
  233. break;
  234. case CDN_FILEOK:
  235. return ( RegCommDlg_ValidateSelectedPath(hWnd, TRUE) != FALSE );
  236. }
  237. return FALSE;
  238. }
  239. /*******************************************************************************
  240. *
  241. * RegCommDlg_OnCommand
  242. *
  243. * DESCRIPTION:
  244. * Handles the selection of a menu item by the user, notification messages
  245. * from a child control, or translated accelerated keystrokes for the
  246. * RegPrint dialog box.
  247. *
  248. * PARAMETERS:
  249. * hWnd, handle of RegCommDlg window.
  250. * DlgItem, identifier of control.
  251. * NotificationCode, notification code from control.
  252. *
  253. *******************************************************************************/
  254. UINT_PTR
  255. PASCAL
  256. RegCommDlg_OnCommand(
  257. HWND hWnd,
  258. int DlgItem,
  259. UINT NotificationCode
  260. )
  261. {
  262. switch (DlgItem) {
  263. case IDC_RANGESELECTEDPATH:
  264. SetFocus(GetDlgItem(hWnd, IDC_SELECTEDPATH));
  265. break;
  266. case IDC_SELECTEDPATH:
  267. switch (NotificationCode) {
  268. case EN_SETFOCUS:
  269. SendDlgItemMessage(hWnd, IDC_SELECTEDPATH, EM_SETSEL,
  270. 0, -1);
  271. break;
  272. case EN_CHANGE:
  273. CheckRadioButton(hWnd, IDC_RANGEALL, IDC_RANGESELECTEDPATH,
  274. IDC_RANGESELECTEDPATH);
  275. break;
  276. }
  277. break;
  278. case IDOK:
  279. return ( RegCommDlg_ValidateSelectedPath(hWnd, FALSE) != FALSE );
  280. }
  281. return FALSE;
  282. }
  283. /*******************************************************************************
  284. *
  285. * RegCommDlg_ValidateSelectedPath
  286. *
  287. * DESCRIPTION:
  288. *
  289. * PARAMETERS:
  290. * hWnd, handle of RegCommDlg window.
  291. * (returns), TRUE if the registry selected path is invalid, else FALSE.
  292. *
  293. *******************************************************************************/
  294. BOOL
  295. PASCAL
  296. RegCommDlg_ValidateSelectedPath(
  297. HWND hWnd,
  298. BOOL fIsFileDialog
  299. )
  300. {
  301. HKEY hKey;
  302. HWND hTitleWnd;
  303. TCHAR Title[256];
  304. if (!(g_fRangeAll = IsDlgButtonChecked(hWnd, IDC_RANGEALL))) {
  305. GetDlgItemText(hWnd, IDC_SELECTEDPATH, g_SelectedPath, ARRAYSIZE(g_SelectedPath));
  306. if (g_SelectedPath[0] == '\0')
  307. g_fRangeAll = TRUE;
  308. else
  309. {
  310. HTREEITEM hSelectedTreeItem = TreeView_GetSelection(g_RegEditData.hKeyTreeWnd);
  311. if (EditRegistryKey(RegEdit_GetComputerItem(hSelectedTreeItem), &hKey, g_SelectedPath, ERK_OPEN) !=
  312. ERROR_SUCCESS)
  313. {
  314. //
  315. // Determine the "real" parent of this dialog and get the
  316. // message box title from that window. Our HWND may really
  317. // be a subdialog if we're a file dialog.
  318. //
  319. hTitleWnd = fIsFileDialog ? GetParent(hWnd) : hWnd;
  320. GetWindowText(hTitleWnd, Title, ARRAYSIZE(Title));
  321. InternalMessageBox(g_hInstance, hTitleWnd,
  322. MAKEINTRESOURCE(IDS_ERRINVALIDREGPATH), Title,
  323. MB_ICONERROR | MB_OK);
  324. return TRUE;
  325. }
  326. RegCloseKey(hKey);
  327. }
  328. }
  329. return FALSE;
  330. }