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.

418 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,
  136. (ULONG_PTR) lpHelpIDs);
  137. return TRUE;
  138. }
  139. return FALSE;
  140. }
  141. /*******************************************************************************
  142. *
  143. * RegCommDlg_OnInitDialog
  144. *
  145. * DESCRIPTION:
  146. * Initializes the RegCommDlg dialog box.
  147. *
  148. * PARAMETERS:
  149. * hWnd, handle of RegCommDlg window.
  150. * hFocusWnd, handle of control to receive the default keyboard focus.
  151. * lParam, additional initialization data passed by dialog creation function.
  152. * (returns), TRUE to set focus to hFocusWnd, else FALSE to prevent a
  153. * keyboard focus from being set.
  154. *
  155. *******************************************************************************/
  156. BOOL
  157. PASCAL
  158. RegCommDlg_OnInitDialog(
  159. HWND hWnd,
  160. HWND hFocusWnd,
  161. LPARAM lParam
  162. )
  163. {
  164. HWND hKeyTreeWnd;
  165. HTREEITEM hSelectedTreeItem;
  166. int DlgItem;
  167. g_RegEditData.uExportFormat = FILE_TYPE_REGEDIT5;
  168. hKeyTreeWnd = g_RegEditData.hKeyTreeWnd;
  169. hSelectedTreeItem = TreeView_GetSelection(hKeyTreeWnd);
  170. KeyTree_BuildKeyPath(hKeyTreeWnd, hSelectedTreeItem, g_SelectedPath,
  171. BKP_TOSYMBOLICROOT);
  172. SetDlgItemText(hWnd, IDC_SELECTEDPATH, g_SelectedPath);
  173. DlgItem = (TreeView_GetParent(hKeyTreeWnd, hSelectedTreeItem) == NULL) ?
  174. IDC_RANGEALL : IDC_RANGESELECTEDPATH;
  175. CheckRadioButton(hWnd, IDC_RANGEALL, IDC_RANGESELECTEDPATH, DlgItem);
  176. return TRUE;
  177. UNREFERENCED_PARAMETER(hFocusWnd);
  178. UNREFERENCED_PARAMETER(lParam);
  179. }
  180. /*******************************************************************************
  181. *
  182. * RegCommDlg_OnNotify
  183. *
  184. * DESCRIPTION:
  185. *
  186. * PARAMETERS:
  187. * hWnd, handle of RegCommDlg window.
  188. * DlgItem, identifier of control.
  189. * lpNMHdr, control notification data.
  190. *
  191. *******************************************************************************/
  192. LRESULT
  193. PASCAL
  194. RegCommDlg_OnNotify(
  195. HWND hWnd,
  196. int DlgItem,
  197. LPNMHDR lpNMHdr
  198. )
  199. {
  200. HWND hControlWnd;
  201. RECT DialogRect;
  202. RECT ControlRect;
  203. int dxChange;
  204. LPOFNOTIFY lpon;
  205. switch (lpNMHdr-> code) {
  206. case CDN_INITDONE:
  207. GetWindowRect(hWnd, &DialogRect);
  208. // Use window coordinates because it works for mirrored
  209. // and non mirrored windows.
  210. MapWindowPoints(NULL, hWnd, (LPPOINT)&DialogRect, 2);
  211. hControlWnd = GetDlgItem(hWnd, IDC_EXPORTRANGE);
  212. GetWindowRect(hControlWnd, &ControlRect);
  213. MapWindowPoints(NULL, hWnd, (LPPOINT)&ControlRect, 2);
  214. dxChange = DialogRect.right - ControlRect.right -
  215. (ControlRect.left - DialogRect.left);
  216. SetWindowPos(hControlWnd, NULL, 0, 0, ControlRect.right -
  217. ControlRect.left + dxChange, ControlRect.bottom -
  218. ControlRect.top, SWP_NOMOVE | SWP_NOZORDER);
  219. hControlWnd = GetDlgItem(hWnd, IDC_SELECTEDPATH);
  220. GetWindowRect(hControlWnd, &ControlRect);
  221. MapWindowPoints(NULL, hWnd, (LPPOINT)&ControlRect, 2);
  222. SetWindowPos(hControlWnd, NULL, 0, 0, ControlRect.right -
  223. ControlRect.left + dxChange, ControlRect.bottom -
  224. ControlRect.top, SWP_NOMOVE | SWP_NOZORDER);
  225. break;
  226. case CDN_TYPECHANGE:
  227. // lpon->lpOFN->nFilterIndex corresponds to the format types in
  228. // regdef.h
  229. lpon = (LPOFNOTIFY) lpNMHdr;
  230. g_RegEditData.uExportFormat = lpon->lpOFN->nFilterIndex;
  231. break;
  232. case CDN_FILEOK:
  233. return ( RegCommDlg_ValidateSelectedPath(hWnd, TRUE) != FALSE );
  234. }
  235. return FALSE;
  236. }
  237. /*******************************************************************************
  238. *
  239. * RegCommDlg_OnCommand
  240. *
  241. * DESCRIPTION:
  242. * Handles the selection of a menu item by the user, notification messages
  243. * from a child control, or translated accelerated keystrokes for the
  244. * RegPrint dialog box.
  245. *
  246. * PARAMETERS:
  247. * hWnd, handle of RegCommDlg window.
  248. * DlgItem, identifier of control.
  249. * NotificationCode, notification code from control.
  250. *
  251. *******************************************************************************/
  252. UINT_PTR
  253. PASCAL
  254. RegCommDlg_OnCommand(
  255. HWND hWnd,
  256. int DlgItem,
  257. UINT NotificationCode
  258. )
  259. {
  260. switch (DlgItem) {
  261. case IDC_RANGESELECTEDPATH:
  262. SetFocus(GetDlgItem(hWnd, IDC_SELECTEDPATH));
  263. break;
  264. case IDC_SELECTEDPATH:
  265. switch (NotificationCode) {
  266. case EN_SETFOCUS:
  267. SendDlgItemMessage(hWnd, IDC_SELECTEDPATH, EM_SETSEL,
  268. 0, -1);
  269. break;
  270. case EN_CHANGE:
  271. CheckRadioButton(hWnd, IDC_RANGEALL, IDC_RANGESELECTEDPATH,
  272. IDC_RANGESELECTEDPATH);
  273. break;
  274. }
  275. break;
  276. case IDOK:
  277. return ( RegCommDlg_ValidateSelectedPath(hWnd, FALSE) != FALSE );
  278. }
  279. return FALSE;
  280. }
  281. /*******************************************************************************
  282. *
  283. * RegCommDlg_ValidateSelectedPath
  284. *
  285. * DESCRIPTION:
  286. *
  287. * PARAMETERS:
  288. * hWnd, handle of RegCommDlg window.
  289. * (returns), TRUE if the registry selected path is invalid, else FALSE.
  290. *
  291. *******************************************************************************/
  292. BOOL
  293. PASCAL
  294. RegCommDlg_ValidateSelectedPath(
  295. HWND hWnd,
  296. BOOL fIsFileDialog
  297. )
  298. {
  299. HKEY hKey;
  300. HWND hTitleWnd;
  301. TCHAR Title[256];
  302. if (!(g_fRangeAll = IsDlgButtonChecked(hWnd, IDC_RANGEALL))) {
  303. GetDlgItemText(hWnd, IDC_SELECTEDPATH, g_SelectedPath,
  304. sizeof(g_SelectedPath)/sizeof(TCHAR));
  305. if (g_SelectedPath[0] == '\0')
  306. g_fRangeAll = TRUE;
  307. else
  308. {
  309. HTREEITEM hSelectedTreeItem = TreeView_GetSelection(g_RegEditData.hKeyTreeWnd);
  310. if (EditRegistryKey(RegEdit_GetComputerItem(hSelectedTreeItem), &hKey, g_SelectedPath, ERK_OPEN) !=
  311. ERROR_SUCCESS)
  312. {
  313. //
  314. // Determine the "real" parent of this dialog and get the
  315. // message box title from that window. Our HWND may really
  316. // be a subdialog if we're a file dialog.
  317. //
  318. hTitleWnd = fIsFileDialog ? GetParent(hWnd) : hWnd;
  319. GetWindowText(hTitleWnd, Title, sizeof(Title)/sizeof(TCHAR));
  320. InternalMessageBox(g_hInstance, hTitleWnd,
  321. MAKEINTRESOURCE(IDS_ERRINVALIDREGPATH), Title,
  322. MB_ICONERROR | MB_OK);
  323. return TRUE;
  324. }
  325. RegCloseKey(hKey);
  326. }
  327. }
  328. return FALSE;
  329. }