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.

816 lines
23 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1994
  4. *
  5. * TITLE: REGFILE.C
  6. *
  7. * VERSION: 4.0
  8. *
  9. * AUTHOR: Tracy Sharpe
  10. *
  11. * DATE: 21 Nov 1993
  12. *
  13. * File import and export user interface routines for the Registry Editor.
  14. *
  15. *******************************************************************************/
  16. #include "pch.h"
  17. #include "regedit.h"
  18. #include "regkey.h"
  19. #include "regfile.h"
  20. #include "regcdhk.h"
  21. #include "regresid.h"
  22. #include "reghelp.h"
  23. #include "regstred.h"
  24. #include "regprint.h"
  25. INT_PTR
  26. CALLBACK
  27. RegProgressDlgProc(
  28. HWND hWnd,
  29. UINT Message,
  30. WPARAM wParam,
  31. LPARAM lParam
  32. );
  33. /*******************************************************************************
  34. *
  35. * RegEdit_ImportRegFile
  36. *
  37. * DESCRIPTION:
  38. *
  39. * PARAMETERS:
  40. * hWnd, handle of RegEdit window.
  41. * fSilentMode, TRUE if no messages should be displayed, else FALSE.
  42. * lpFileName, address of file name buffer.
  43. *
  44. *******************************************************************************/
  45. VOID RegEdit_ImportRegFile(HWND hWnd, BOOL fSilentMode, LPTSTR lpFileName, HTREEITEM hComputerItem)
  46. {
  47. if (!fSilentMode && hWnd != NULL) {
  48. if ((g_hRegProgressWnd = CreateDialogParam(g_hInstance,
  49. MAKEINTRESOURCE(IDD_REGPROGRESS), hWnd, RegProgressDlgProc,
  50. (LPARAM) lpFileName)) != NULL)
  51. EnableWindow(hWnd, FALSE);
  52. }
  53. else
  54. g_hRegProgressWnd = NULL;
  55. //
  56. // Prompt user to confirm importing a .reg file if running in silent mode
  57. // without a window (i.e. invoked .reg from a folder)
  58. //
  59. if (!fSilentMode && !hWnd)
  60. {
  61. if (InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(IDS_CONFIRMIMPFILE),
  62. MAKEINTRESOURCE(IDS_REGEDIT), MB_ICONQUESTION | MB_YESNO , lpFileName) != IDYES)
  63. {
  64. return;
  65. }
  66. }
  67. ImportRegFile(hWnd, lpFileName, hComputerItem);
  68. if (g_hRegProgressWnd != NULL) {
  69. EnableWindow(hWnd, TRUE);
  70. DestroyWindow(g_hRegProgressWnd);
  71. }
  72. if (!fSilentMode && g_FileErrorStringID != IDS_IMPFILEERRORCANCEL)
  73. {
  74. //
  75. // set defaults
  76. //
  77. UINT uStyle = MB_ICONERROR;
  78. TCHAR szComputerName[MAXKEYNAME + 1];
  79. LPTSTR pszComputerName = szComputerName;
  80. KeyTree_GetKeyName(hComputerItem, pszComputerName, ARRAYSIZE(szComputerName));
  81. //
  82. // For the resource messages that take the pszComputerName parameter,
  83. // map them to a local-computer version if pszComputerName is empty.
  84. // (Alternatively, we could fill in "this computer" or somesuch for
  85. // pszComputerName, but the resulting text is sort of weird, which
  86. // which isn't acceptable since local-computer is the 99% case.)
  87. //
  88. // Also map the uStyle as needed.
  89. //
  90. switch (g_FileErrorStringID)
  91. {
  92. case IDS_IMPFILEERRSUCCESS:
  93. if (!hWnd || *pszComputerName == 0)
  94. {
  95. g_FileErrorStringID += LOCAL_OFFSET;
  96. }
  97. uStyle = MB_ICONINFORMATION | MB_OK;
  98. break;
  99. case IDS_IMPFILEERRREGOPEN:
  100. case IDS_IMPFILEERRNOFILE:
  101. if (*pszComputerName == 0)
  102. {
  103. g_FileErrorStringID += LOCAL_OFFSET;
  104. }
  105. break;
  106. }
  107. //
  108. // Put up the message box
  109. //
  110. InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(g_FileErrorStringID),
  111. MAKEINTRESOURCE(IDS_REGEDIT), uStyle, lpFileName, pszComputerName);
  112. }
  113. }
  114. /*******************************************************************************
  115. *
  116. * RegEdit_OnDropFiles
  117. *
  118. * DESCRIPTION:
  119. *
  120. * PARAMETERS:
  121. * hWnd, handle of RegEdit window.
  122. *
  123. *******************************************************************************/
  124. VOID
  125. PASCAL
  126. RegEdit_OnDropFiles(
  127. HWND hWnd,
  128. HDROP hDrop
  129. )
  130. {
  131. TCHAR FileName[MAX_PATH];
  132. UINT NumberOfDrops;
  133. UINT CurrentDrop;
  134. BOOL me;
  135. HTREEITEM hSelectedTreeItem = TreeView_GetSelection(g_RegEditData.hKeyTreeWnd);
  136. TreeView_SelectDropTarget(g_RegEditData.hKeyTreeWnd, hSelectedTreeItem);
  137. RegEdit_SetWaitCursor(TRUE);
  138. NumberOfDrops = DragQueryFile(hDrop, (UINT) -1, NULL, 0);
  139. for (CurrentDrop = 0; CurrentDrop < NumberOfDrops; CurrentDrop++)
  140. {
  141. DragQueryFile(hDrop, CurrentDrop, FileName, sizeof(FileName)/sizeof(TCHAR));
  142. if (TreeView_GetNextSibling(g_RegEditData.hKeyTreeWnd,
  143. TreeView_GetRoot(g_RegEditData.hKeyTreeWnd)) != NULL)
  144. {
  145. // Remote connections exist
  146. RegEdit_ImportToConnectedComputer(hWnd, FileName);
  147. }
  148. else
  149. {
  150. RegEdit_ImportRegFile(hWnd, FALSE, FileName, RegEdit_GetComputerItem(hSelectedTreeItem));
  151. }
  152. }
  153. DragFinish(hDrop);
  154. TreeView_SelectDropTarget(g_RegEditData.hKeyTreeWnd, NULL);
  155. RegEdit_OnKeyTreeRefresh(hWnd);
  156. RegEdit_SetWaitCursor(FALSE);
  157. }
  158. //------------------------------------------------------------------------------
  159. // RegEdit_SetPrivilege
  160. //
  161. // DESCRIPTION: Enable a priviledge
  162. //
  163. // PARAMETERS: lpszPrivilege - the securty constant or its corresponding string
  164. // bEnablePrivilege - TRUE = enable, False = disable
  165. //
  166. //------------------------------------------------------------------------------
  167. BOOL RegEdit_SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnablePrivilege)
  168. {
  169. TOKEN_PRIVILEGES tp;
  170. LUID luid;
  171. HANDLE hToken;
  172. BOOL fSuccess = FALSE;
  173. HRESULT hr;
  174. if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
  175. {
  176. if (LookupPrivilegeValue(NULL, lpszPrivilege, &luid))
  177. {
  178. tp.PrivilegeCount = 1;
  179. tp.Privileges[0].Luid = luid;
  180. tp.Privileges[0].Attributes = (bEnablePrivilege) ? SE_PRIVILEGE_ENABLED : 0;
  181. // Enable or disable the privilege
  182. if (AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
  183. (PTOKEN_PRIVILEGES) NULL, (PDWORD) NULL))
  184. {
  185. fSuccess = TRUE;
  186. }
  187. }
  188. CloseHandle(hToken);
  189. }
  190. return fSuccess;
  191. }
  192. //------------------------------------------------------------------------------
  193. // RegEdit_OnCommandLoadHive
  194. //
  195. // DESCRIPTION: Open and Load a Hive
  196. //
  197. // PARAMETERS: hWnd - handle of RegEdit window.
  198. //
  199. //------------------------------------------------------------------------------
  200. VOID RegEdit_OnCommandLoadHive(HWND hWnd)
  201. {
  202. TCHAR achFileName[MAX_PATH];
  203. if (RegEdit_GetFileName(hWnd, IDS_LOADHVREGFILETITLE, IDS_REGLOADHVFILEFILTER,
  204. IDS_REGNODEFEXT, achFileName, ARRAYSIZE(achFileName), TRUE))
  205. {
  206. EDITVALUEPARAM EditValueParam;
  207. RegEdit_SetWaitCursor(TRUE);
  208. EditValueParam.cbValueData = sizeof(TCHAR) * 50;
  209. EditValueParam.pValueData = LocalAlloc(LPTR, EditValueParam.cbValueData);
  210. if (EditValueParam.pValueData)
  211. {
  212. EditValueParam.pValueData[0] = TEXT('\0');
  213. if (DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_INPUTHIVENAME), hWnd,
  214. EditStringValueDlgProc, (LPARAM) &EditValueParam) == IDOK)
  215. {
  216. HRESULT hr;
  217. RegEdit_SetPrivilege(SE_RESTORE_NAME, TRUE);
  218. if ((hr = RegLoadKey(g_RegEditData.hCurrentSelectionKey, (PTSTR)EditValueParam.pValueData,
  219. achFileName)) == ERROR_SUCCESS)
  220. {
  221. RegEdit_OnKeyTreeRefresh(hWnd);
  222. }
  223. else
  224. {
  225. UINT uErrorStringID = IDS_ERRORLOADHV;
  226. switch (hr)
  227. {
  228. case ERROR_PRIVILEGE_NOT_HELD:
  229. uErrorStringID = IDS_ERRORLOADHVPRIV;
  230. break;
  231. case ERROR_SHARING_VIOLATION:
  232. uErrorStringID = IDS_ERRORLOADHVNOSHARE;
  233. break;
  234. case ERROR_ACCESS_DENIED:
  235. uErrorStringID = IDS_ERRORLOADHVNOACC;
  236. break;
  237. }
  238. InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(uErrorStringID),
  239. MAKEINTRESOURCE(IDS_LOADHVREGFILETITLE), MB_ICONERROR | MB_OK, achFileName);
  240. }
  241. RegEdit_SetPrivilege(SE_RESTORE_NAME, FALSE);
  242. }
  243. LocalFree(EditValueParam.pValueData);
  244. }
  245. RegEdit_SetWaitCursor(FALSE);
  246. }
  247. }
  248. //------------------------------------------------------------------------------
  249. // RegEdit_OnCommandUnloadHive
  250. //
  251. // DESCRIPTION: Open and Load a Hive
  252. //
  253. // PARAMETERS: hWnd - handle of RegEdit window.
  254. //
  255. //------------------------------------------------------------------------------
  256. VOID RegEdit_OnCommandUnloadHive(HWND hWnd)
  257. {
  258. if (InternalMessageBox(g_hInstance, hWnd,
  259. MAKEINTRESOURCE(IDS_CONFIRMDELHIVETEXT), MAKEINTRESOURCE(IDS_CONFIRMDELHIVETITLE),
  260. MB_ICONWARNING | MB_YESNO) == IDYES)
  261. {
  262. HRESULT hr;
  263. TCHAR achKeyName[MAXKEYNAME];
  264. HTREEITEM hSelectedTreeItem = TreeView_GetSelection(g_RegEditData.hKeyTreeWnd);
  265. RegEdit_SetPrivilege(SE_RESTORE_NAME, TRUE);
  266. // must close key to unload it
  267. RegCloseKey(g_RegEditData.hCurrentSelectionKey);
  268. if ((hr = RegUnLoadKey(KeyTree_GetRootKey(hSelectedTreeItem),
  269. KeyTree_GetKeyName(hSelectedTreeItem, achKeyName, ARRAYSIZE(achKeyName)))) ==
  270. ERROR_SUCCESS)
  271. {
  272. g_RegEditData.hCurrentSelectionKey = NULL;
  273. RegEdit_OnKeyTreeRefresh(hWnd);
  274. }
  275. else
  276. {
  277. UINT uErrorStringID = IDS_ERRORUNLOADHV;
  278. switch (hr)
  279. {
  280. case ERROR_PRIVILEGE_NOT_HELD:
  281. uErrorStringID = IDS_ERRORUNLOADHVPRIV;
  282. break;
  283. case ERROR_ACCESS_DENIED:
  284. uErrorStringID = IDS_ERRORUNLOADHVNOACC;
  285. break;
  286. }
  287. InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(uErrorStringID),
  288. MAKEINTRESOURCE(IDS_UNLOADHIVETITLE), MB_ICONERROR | MB_OK, achKeyName);
  289. // The key couldn't be unloaded so select it again
  290. g_RegEditData.hCurrentSelectionKey = NULL;
  291. RegEdit_KeyTreeSelChanged(hWnd);
  292. }
  293. RegEdit_SetPrivilege(SE_RESTORE_NAME, FALSE);
  294. }
  295. }
  296. /*******************************************************************************
  297. *
  298. * RegEdit_OnCommandImportRegFile
  299. *
  300. * DESCRIPTION:
  301. *
  302. * PARAMETERS:
  303. * hWnd, handle of RegEdit window.
  304. *
  305. *******************************************************************************/
  306. VOID RegEdit_OnCommandImportRegFile(HWND hWnd)
  307. {
  308. TCHAR achFileName[MAX_PATH];
  309. if (RegEdit_GetFileName(hWnd, IDS_IMPORTREGFILETITLE, IDS_REGIMPORTFILEFILTER,
  310. IDS_REGFILEDEFEXT, achFileName, ARRAYSIZE(achFileName), TRUE))
  311. {
  312. // check for networked registries
  313. if (TreeView_GetNextSibling(g_RegEditData.hKeyTreeWnd,
  314. TreeView_GetRoot(g_RegEditData.hKeyTreeWnd)) != NULL)
  315. {
  316. // Remote connections exist
  317. RegEdit_ImportToConnectedComputer(hWnd, achFileName);
  318. }
  319. else
  320. {
  321. RegEdit_SetWaitCursor(TRUE);
  322. RegEdit_ImportRegFile(hWnd, FALSE, achFileName, NULL);
  323. // PERF: Only need to refresh the computer that we imported the
  324. // file into, not the whole thing.
  325. RegEdit_OnKeyTreeRefresh(hWnd);
  326. RegEdit_SetWaitCursor(FALSE);
  327. }
  328. }
  329. }
  330. /*******************************************************************************
  331. *
  332. * RegEdit_ExportRegFile
  333. *
  334. * DESCRIPTION:
  335. *
  336. * PARAMETERS:
  337. * hWnd, handle of RegEdit window.
  338. * fSilentMode, TRUE if no messages should be displayed, else FALSE.
  339. * lpFileName, address of file name buffer.
  340. * lpSelectedPath,
  341. *
  342. *******************************************************************************/
  343. VOID
  344. PASCAL
  345. RegEdit_ExportRegFile(
  346. HWND hWnd,
  347. BOOL fSilentMode,
  348. LPTSTR lpFileName,
  349. LPTSTR lpSelectedPath
  350. )
  351. {
  352. //
  353. // Fix a bug where /a or /e is specified and no file is passed in
  354. //
  355. if (lpFileName == NULL)
  356. {
  357. InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(IDS_NOFILESPECIFIED),
  358. MAKEINTRESOURCE(IDS_REGEDIT), MB_ICONERROR | MB_OK, lpFileName);
  359. return;
  360. }
  361. switch (g_RegEditData.uExportFormat)
  362. {
  363. case FILE_TYPE_REGEDT32:
  364. ExportRegedt32File(lpFileName, lpSelectedPath);
  365. break;
  366. case FILE_TYPE_REGEDIT4:
  367. ExportWin40RegFile(lpFileName, lpSelectedPath);
  368. break;
  369. case FILE_TYPE_TEXT:
  370. RegEdit_SaveAsSubtree(lpFileName, lpSelectedPath);
  371. break;
  372. default:
  373. ExportWinNT50RegFile(lpFileName, lpSelectedPath);
  374. break;
  375. }
  376. if (g_FileErrorStringID != IDS_EXPFILEERRSUCCESS && g_FileErrorStringID != IDS_IMPFILEERRSUCCESSLOCAL)
  377. {
  378. InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(g_FileErrorStringID),
  379. MAKEINTRESOURCE(IDS_REGEDIT), MB_ICONERROR | MB_OK, lpFileName);
  380. }
  381. }
  382. //------------------------------------------------------------------------------
  383. // RegEdit_OnCommandExportRegFile
  384. //
  385. // DESCRIPTION:
  386. //
  387. // PARAMETERS: - hWnd, handle of RegEdit window.
  388. //------------------------------------------------------------------------------
  389. VOID RegEdit_OnCommandExportRegFile(HWND hWnd)
  390. {
  391. TCHAR achFileName[MAX_PATH];
  392. LPTSTR lpSelectedPath;
  393. if (RegEdit_GetFileName(hWnd, IDS_EXPORTREGFILETITLE, IDS_REGEXPORTFILEFILTER,
  394. IDS_REGFILEDEFEXT, achFileName, ARRAYSIZE(achFileName), FALSE))
  395. {
  396. RegEdit_SetWaitCursor(TRUE);
  397. lpSelectedPath = g_fRangeAll ? NULL : g_SelectedPath;
  398. RegEdit_ExportRegFile(hWnd, FALSE, achFileName, lpSelectedPath);
  399. RegEdit_SetWaitCursor(FALSE);
  400. }
  401. }
  402. //------------------------------------------------------------------------------
  403. // RegEdit_GetFileName
  404. //
  405. // DESCRIPTION: Gets a file name
  406. //
  407. // PARAMETERS: hWnd - handle of RegEdit window.
  408. // fOpen - TRUE if importing a file, else FALSE if exporting a file.
  409. // lpFileName - address of file name buffer.
  410. // cchFileName - size of file name buffer in TCHARacters.
  411. //
  412. // RETURN: True, if successfull
  413. //------------------------------------------------------------------------------
  414. BOOL RegEdit_GetFileName(HWND hWnd, UINT uTitleStringID, UINT uFilterStringID,
  415. UINT uDefExtStringID, LPTSTR lpFileName, DWORD cchFileName, BOOL fOpen)
  416. {
  417. PTSTR pTitle = NULL;
  418. PTSTR pDefaultExtension = NULL;
  419. PTSTR pFilter = NULL;
  420. PTSTR pFilterChar;
  421. OPENFILENAME OpenFileName;
  422. BOOL fSuccess;
  423. //
  424. // Load various strings that will be displayed and used by the common open
  425. // or save dialog box. Note that if any of these fail, the error is not
  426. // fatal-- the common dialog box may look odd, but will still work.
  427. //
  428. pTitle = LoadDynamicString(uTitleStringID);
  429. if (uDefExtStringID != IDS_REGNODEFEXT)
  430. {
  431. pDefaultExtension = LoadDynamicString(uDefExtStringID);
  432. }
  433. if ((pFilter = LoadDynamicString(uFilterStringID)) != NULL)
  434. {
  435. // The common dialog library requires that the substrings of the
  436. // filter string be separated by nulls, but we cannot load a string
  437. // containing nulls. So we use some dummy character in the resource
  438. // that we now convert to nulls.
  439. for (pFilterChar = pFilter; *pFilterChar != 0; pFilterChar =
  440. CharNext(pFilterChar))
  441. {
  442. if (*pFilterChar == TEXT('#'))
  443. *pFilterChar++ = 0;
  444. }
  445. }
  446. *lpFileName = 0;
  447. memset(&OpenFileName, 0, sizeof(OPENFILENAME));
  448. OpenFileName.lStructSize = sizeof(OPENFILENAME);
  449. OpenFileName.hwndOwner = hWnd;
  450. OpenFileName.hInstance = g_hInstance;
  451. OpenFileName.lpstrFilter = pFilter;
  452. OpenFileName.lpstrFile = lpFileName;
  453. OpenFileName.nMaxFile = cchFileName;
  454. OpenFileName.lpstrTitle = pTitle;
  455. if (fOpen)
  456. {
  457. OpenFileName.Flags = OFN_HIDEREADONLY | OFN_EXPLORER |
  458. OFN_FILEMUSTEXIST;
  459. fSuccess = GetOpenFileName(&OpenFileName);
  460. }
  461. else
  462. {
  463. OpenFileName.lpstrDefExt = pDefaultExtension;
  464. OpenFileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |
  465. OFN_EXPLORER | OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST |
  466. OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
  467. OpenFileName.lpfnHook = RegCommDlgHookProc;
  468. OpenFileName.lpTemplateName = MAKEINTRESOURCE(IDD_REGEXPORT);
  469. g_RegCommDlgDialogTemplate = IDD_REGEXPORT;
  470. fSuccess = GetSaveFileName(&OpenFileName);
  471. }
  472. //
  473. // Delete all of the dynamic strings that we loaded.
  474. //
  475. if (pTitle != NULL)
  476. DeleteDynamicString(pTitle);
  477. if (pDefaultExtension != NULL)
  478. DeleteDynamicString(pDefaultExtension);
  479. if (pFilter != NULL)
  480. DeleteDynamicString(pFilter);
  481. return fSuccess;
  482. }
  483. /*******************************************************************************
  484. *
  485. * RegProgressDlgProc
  486. *
  487. * DESCRIPTION:
  488. * Callback procedure for the RegAbort dialog box.
  489. *
  490. * PARAMETERS:
  491. * hWnd, handle of RegProgress window.
  492. * Message,
  493. * wParam,
  494. * lParam,
  495. * (returns),
  496. *
  497. *******************************************************************************/
  498. INT_PTR
  499. CALLBACK
  500. RegProgressDlgProc(
  501. HWND hWnd,
  502. UINT Message,
  503. WPARAM wParam,
  504. LPARAM lParam
  505. )
  506. {
  507. switch (Message) {
  508. case WM_INITDIALOG:
  509. //PathSetDlgItemPath(hWnd, IDC_FILENAME, (LPTSTR)lParam);
  510. SetDlgItemText(hWnd, IDC_FILENAME, (LPTSTR) lParam);
  511. break;
  512. default:
  513. return FALSE;
  514. }
  515. return TRUE;
  516. }
  517. /*******************************************************************************
  518. *
  519. * ImportRegFileUICallback
  520. *
  521. * DESCRIPTION:
  522. *
  523. * PARAMETERS:
  524. *
  525. *******************************************************************************/
  526. VOID ImportRegFileUICallback(UINT uPercentage)
  527. {
  528. if (g_hRegProgressWnd != NULL)
  529. {
  530. SendDlgItemMessage(g_hRegProgressWnd, IDC_PROGRESSBAR, PBM_SETPOS,
  531. (WPARAM) uPercentage, 0);
  532. while (MessagePump(g_hRegProgressWnd));
  533. }
  534. }
  535. //------------------------------------------------------------------------------
  536. // RegEdit_ImportToConnectedComputer
  537. //
  538. // DESCRIPTION: Imports a reg. file one or more of the connected computers
  539. //
  540. // PARAMETERS: HWND hWnd
  541. // PTSTR pszFileName - import file
  542. //------------------------------------------------------------------------------
  543. void RegEdit_ImportToConnectedComputer(HWND hWnd, PTSTR pszFileName)
  544. {
  545. DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_REGIMPORTNET), hWnd,
  546. RegConnectedComputerDlgProc, (LPARAM) pszFileName);
  547. }
  548. //------------------------------------------------------------------------------
  549. // RegConnectedComputerDlgProc
  550. //
  551. // DESCRIPTION: Dlg Proc for selecting a connected computer
  552. //
  553. // PARAMETERS:
  554. //------------------------------------------------------------------------------
  555. INT_PTR RegConnectedComputerDlgProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  556. {
  557. switch (uMessage)
  558. {
  559. case WM_INITDIALOG:
  560. SetWindowLongPtr(hWnd, DWLP_USER, lParam);
  561. return RegImport_OnInitDialog(hWnd);
  562. case WM_COMMAND:
  563. switch (GET_WM_COMMAND_ID(wParam, lParam))
  564. {
  565. case IDOK:
  566. {
  567. PTSTR pszFileName = (PTSTR) GetWindowLongPtr(hWnd, DWLP_USER);
  568. // (pszFileName == NULL) is checked later
  569. RegImport_OnCommandOk(hWnd, pszFileName);
  570. }
  571. // FALL THROUGH
  572. case IDCANCEL:
  573. EndDialog(hWnd, 0);
  574. break;
  575. }
  576. return TRUE;
  577. }
  578. return FALSE;
  579. }
  580. //------------------------------------------------------------------------------
  581. // RegImport_OnInitDialog
  582. //
  583. // DESCRIPTION: Create a list of all the connected computers
  584. //
  585. // PARAMETERS: HWND hWnd
  586. //------------------------------------------------------------------------------
  587. INT_PTR RegImport_OnInitDialog(HWND hWnd)
  588. {
  589. HWND hComputerListWnd;
  590. RECT ClientRect;
  591. LV_COLUMN LVColumn;
  592. LV_ITEM LVItem;
  593. TCHAR achComputerName[MAX_PATH];
  594. HWND hKeyTreeWnd;
  595. TV_ITEM TVItem;
  596. hComputerListWnd = GetDlgItem(hWnd, IDC_COMPUTERLIST);
  597. // Initialize the ListView control.
  598. ListView_SetImageList(hComputerListWnd, g_RegEditData.hImageList,
  599. LVSIL_SMALL);
  600. LVColumn.mask = LVCF_FMT | LVCF_WIDTH;
  601. LVColumn.fmt = LVCFMT_LEFT;
  602. GetClientRect(hComputerListWnd, &ClientRect);
  603. LVColumn.cx = ClientRect.right - GetSystemMetrics(SM_CXVSCROLL) -
  604. 2 * GetSystemMetrics(SM_CXEDGE);
  605. ListView_InsertColumn(hComputerListWnd, 0, &LVColumn);
  606. // Walk through the local machine and each remote connection listed
  607. // in the KeyTree and add it to our RemoteList.
  608. LVItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  609. LVItem.pszText = achComputerName;
  610. LVItem.iItem = 0;
  611. LVItem.iSubItem = 0;
  612. LVItem.iImage = IMAGEINDEX(IDI_COMPUTER);
  613. hKeyTreeWnd = g_RegEditData.hKeyTreeWnd;
  614. TVItem.mask = TVIF_TEXT;
  615. TVItem.hItem = TreeView_GetRoot(hKeyTreeWnd);
  616. TVItem.pszText = achComputerName;
  617. TVItem.cchTextMax = sizeof(achComputerName)/sizeof(TCHAR);
  618. // Set "local computer" in list
  619. LVItem.lParam = (LPARAM) TVItem.hItem;
  620. TreeView_GetItem(hKeyTreeWnd, &TVItem);
  621. ListView_InsertItem(hComputerListWnd, &LVItem);
  622. LVItem.iItem++;
  623. LVItem.iImage = IMAGEINDEX(IDI_REMOTE);
  624. while ((TVItem.hItem = TreeView_GetNextSibling(hKeyTreeWnd,
  625. TVItem.hItem)) != NULL)
  626. {
  627. LVItem.lParam = (LPARAM) TVItem.hItem;
  628. TreeView_GetItem(hKeyTreeWnd, &TVItem);
  629. ListView_InsertItem(hComputerListWnd, &LVItem);
  630. LVItem.iItem++;
  631. }
  632. ListView_SetItemState(hComputerListWnd, 0, LVIS_FOCUSED, LVIS_FOCUSED);
  633. return TRUE;
  634. }
  635. //------------------------------------------------------------------------------
  636. // RegImport_OnCommandOk
  637. //
  638. // DESCRIPTION: Import key to selected computers
  639. //
  640. // PARAMETERS: HWND hWnd,
  641. // PTSTR pszFileName - file to import
  642. //------------------------------------------------------------------------------
  643. void RegImport_OnCommandOk(HWND hWnd, PTSTR pszFileName)
  644. {
  645. LV_ITEM LVItem;
  646. HWND hComputerListWnd;
  647. // Walk through each selected item in the ListView and import the reg file
  648. LVItem.mask = LVIF_PARAM;
  649. LVItem.iItem = -1;
  650. LVItem.iSubItem = 0;
  651. hComputerListWnd = GetDlgItem(hWnd, IDC_COMPUTERLIST);
  652. while ((LVItem.iItem = ListView_GetNextItem(hComputerListWnd, LVItem.iItem,
  653. LVNI_SELECTED)) != -1)
  654. {
  655. ListView_GetItem(hComputerListWnd, &LVItem);
  656. RegEdit_SetWaitCursor(TRUE);
  657. RegEdit_ImportRegFile(hWnd, FALSE, pszFileName, (HTREEITEM) LVItem.lParam);
  658. RegEdit_OnKeyTreeRefresh(hWnd);
  659. RegEdit_SetWaitCursor(FALSE);
  660. }
  661. }