4 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 /********************************************************************************
24 * Global and Local Variables:
27 #define FAVORITES_MENU_POSITION 3
29 static TCHAR s_szFavoritesRegKey
[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit\\Favorites");
31 static BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
33 /*******************************************************************************
34 * Local module support methods
37 static void resize_frame_rect(HWND hWnd
, PRECT prect
)
41 if (IsWindowVisible(hToolBar)) {
42 SendMessage(hToolBar, WM_SIZE, 0, 0);
43 GetClientRect(hToolBar, &rt);
44 prect->top = rt.bottom+3;
45 prect->bottom -= rt.bottom+3;
48 if (IsWindowVisible(hStatusBar
))
50 SetupStatusBar(hWnd
, TRUE
);
51 GetClientRect(hStatusBar
, &rt
);
52 prect
->bottom
-= rt
.bottom
;
54 MoveWindow(g_pChildWnd
->hWnd
, prect
->left
, prect
->top
, prect
->right
, prect
->bottom
, TRUE
);
57 static void resize_frame_client(HWND hWnd
)
61 GetClientRect(hWnd
, &rect
);
62 resize_frame_rect(hWnd
, &rect
);
65 /********************************************************************************/
67 static void OnInitMenu(HWND hWnd
)
71 DWORD dwIndex
, cbValueName
, cbValueData
, dwType
;
72 TCHAR szValueName
[256];
73 BYTE abValueData
[256];
74 static int s_nFavoriteMenuSubPos
= -1;
76 BOOL bDisplayedAny
= FALSE
;
78 /* Find Favorites menu and clear it out */
79 hMenu
= GetSubMenu(GetMenu(hWnd
), FAVORITES_MENU_POSITION
);
82 if (s_nFavoriteMenuSubPos
< 0)
84 s_nFavoriteMenuSubPos
= GetMenuItemCount(hMenu
);
88 while(RemoveMenu(hMenu
, s_nFavoriteMenuSubPos
, MF_BYPOSITION
))
92 lResult
= RegOpenKey(HKEY_CURRENT_USER
, s_szFavoritesRegKey
, &hKey
);
93 if (lResult
!= ERROR_SUCCESS
)
99 cbValueName
= COUNT_OF(szValueName
);
100 cbValueData
= sizeof(abValueData
);
101 lResult
= RegEnumValue(hKey
, dwIndex
, szValueName
, &cbValueName
, NULL
, &dwType
, abValueData
, &cbValueData
);
102 if ((lResult
== ERROR_SUCCESS
) && (dwType
== REG_SZ
))
106 AppendMenu(hMenu
, MF_SEPARATOR
, 0, NULL
);
107 bDisplayedAny
= TRUE
;
109 AppendMenu(hMenu
, 0, ID_FAVORITES_MIN
+ GetMenuItemCount(hMenu
), szValueName
);
113 while(lResult
== ERROR_SUCCESS
);
120 static void OnEnterMenuLoop(HWND hWnd
)
123 UNREFERENCED_PARAMETER(hWnd
);
125 /* Update the status bar pane sizes */
127 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
129 SendMessage(hStatusBar
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)_T(""));
132 static void OnExitMenuLoop(HWND hWnd
)
135 /* Update the status bar pane sizes*/
136 SetupStatusBar(hWnd
, TRUE
);
140 static void OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
144 _tcscpy(str
, _T(""));
145 if (nFlags
& MF_POPUP
)
147 if (hSysMenu
!= GetMenu(hWnd
))
149 if (nItemID
== 2) nItemID
= 5;
152 if (LoadString(hInst
, nItemID
, str
, 100))
154 /* load appropriate string*/
156 /* first newline terminates actual string*/
157 lpsz
= _tcschr(lpsz
, _T('\n'));
161 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)str
);
164 void SetupStatusBar(HWND hWnd
, BOOL bResize
)
168 GetClientRect(hWnd
, &rc
);
172 SendMessage(hStatusBar
, WM_SIZE
, 0, 0);
173 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
176 void UpdateStatusBar(void)
179 ZeroMemory(&nmhdr
, sizeof(NMHDR
));
180 nmhdr
.code
= TVN_SELCHANGED
;
181 SendMessage(g_pChildWnd
->hWnd
, WM_NOTIFY
, (WPARAM
)TREE_WINDOW
, (LPARAM
)&nmhdr
);
184 static void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
186 BOOL vis
= IsWindowVisible(hchild
);
187 HMENU hMenuView
= GetSubMenu(hMenuFrame
, ID_VIEW_MENU
);
189 CheckMenuItem(hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
190 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
191 resize_frame_client(hWnd
);
194 static BOOL
CheckCommDlgError(HWND hWnd
)
196 DWORD dwErrorCode
= CommDlgExtendedError();
197 UNREFERENCED_PARAMETER(hWnd
);
200 case CDERR_DIALOGFAILURE
:
202 case CDERR_FINDRESFAILURE
:
204 case CDERR_NOHINSTANCE
:
206 case CDERR_INITIALIZATION
:
210 case CDERR_LOCKRESFAILURE
:
212 case CDERR_NOTEMPLATE
:
214 case CDERR_LOADRESFAILURE
:
216 case CDERR_STRUCTSIZE
:
218 case CDERR_LOADSTRFAILURE
:
220 case FNERR_BUFFERTOOSMALL
:
222 case CDERR_MEMALLOCFAILURE
:
224 case FNERR_INVALIDFILENAME
:
226 case CDERR_MEMLOCKFAILURE
:
228 case FNERR_SUBCLASSFAILURE
:
236 TCHAR FileNameBuffer
[_MAX_PATH
];
237 TCHAR FileTitleBuffer
[_MAX_PATH
];
243 } FILTERPAIR
, *PFILTERPAIR
;
246 BuildFilterStrings(TCHAR
*Filter
, PFILTERPAIR Pairs
, int PairCount
)
251 for(i
= 0; i
< PairCount
; i
++)
253 c
+= LoadString(hInst
, Pairs
[i
].DisplayID
, &Filter
[c
], 255 * sizeof(TCHAR
));
255 c
+= LoadString(hInst
, Pairs
[i
].FilterID
, &Filter
[c
], 255 * sizeof(TCHAR
));
261 static BOOL
InitOpenFileName(HWND hWnd
, OPENFILENAME
* pofn
)
263 FILTERPAIR FilterPairs
[3];
264 static TCHAR Filter
[1024];
266 memset(pofn
, 0, sizeof(OPENFILENAME
));
267 pofn
->lStructSize
= sizeof(OPENFILENAME
);
268 pofn
->hwndOwner
= hWnd
;
269 pofn
->hInstance
= hInst
;
271 /* create filter string */
272 FilterPairs
[0].DisplayID
= IDS_FLT_REGFILES
;
273 FilterPairs
[0].FilterID
= IDS_FLT_REGFILES_FLT
;
274 FilterPairs
[1].DisplayID
= IDS_FLT_REGEDIT4
;
275 FilterPairs
[1].FilterID
= IDS_FLT_REGEDIT4_FLT
;
276 FilterPairs
[2].DisplayID
= IDS_FLT_ALLFILES
;
277 FilterPairs
[2].FilterID
= IDS_FLT_ALLFILES_FLT
;
278 BuildFilterStrings(Filter
, FilterPairs
, sizeof(FilterPairs
) / sizeof(FILTERPAIR
));
280 pofn
->lpstrFilter
= Filter
;
281 pofn
->lpstrFile
= FileNameBuffer
;
282 pofn
->nMaxFile
= _MAX_PATH
;
283 pofn
->lpstrFileTitle
= FileTitleBuffer
;
284 pofn
->nMaxFileTitle
= _MAX_PATH
;
285 pofn
->Flags
= OFN_HIDEREADONLY
;
286 pofn
->lpstrDefExt
= TEXT("reg");
290 static INT_PTR CALLBACK
LoadHive_KeyNameInHookProc(HWND hWndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
292 static LPTSTR sKey
= NULL
;
293 static INT sLength
= 0;
297 sKey
= (LPTSTR
)lParam
;
298 sLength
= 128; /* FIXME: Ugly hack! */
300 switch(LOWORD(wParam
))
303 if(GetDlgItemText(hWndDlg
, IDC_EDIT_KEY
, sKey
, sLength
))
304 return EndDialog(hWndDlg
, -1);
306 return EndDialog(hWndDlg
, 0);
308 return EndDialog(hWndDlg
, 0);
315 static BOOL
LoadHive(HWND hWnd
)
324 /* get the item key to load the hive in */
325 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
326 /* initialize the "open file" dialog */
327 InitOpenFileName(hWnd
, &ofn
);
328 /* build the "All Files" filter up */
329 filter
.DisplayID
= IDS_FLT_ALLFILES
;
330 filter
.FilterID
= IDS_FLT_ALLFILES_FLT
;
331 BuildFilterStrings(Filter
, &filter
, sizeof(filter
));
332 ofn
.lpstrFilter
= Filter
;
333 /* load and set the caption and flags for dialog */
334 LoadString(hInst
, IDS_LOAD_HIVE
, Caption
, COUNT_OF(Caption
));
335 ofn
.lpstrTitle
= Caption
;
336 ofn
.Flags
|= OFN_ENABLESIZING
;
337 /* ofn.lCustData = ;*/
338 /* now load the hive */
339 if (GetOpenFileName(&ofn
))
341 if(DialogBoxParam(hInst
, MAKEINTRESOURCE(IDD_LOADHIVE
), hWnd
, &LoadHive_KeyNameInHookProc
, (LPARAM
)xPath
))
343 LONG regLoadResult
= RegLoadKey(hRootKey
, xPath
, ofn
.lpstrFile
);
344 if(regLoadResult
== ERROR_SUCCESS
)
346 /* refresh tree and list views */
347 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
348 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
349 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
353 ErrorMessageBox(hWnd
, Caption
, regLoadResult
);
360 CheckCommDlgError(hWnd
);
365 static BOOL
UnloadHive(HWND hWnd
)
370 LONG regUnloadResult
;
372 /* get the item key to unload */
373 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
374 /* load and set the caption and flags for dialog */
375 LoadString(hInst
, IDS_UNLOAD_HIVE
, Caption
, COUNT_OF(Caption
));
376 /* now unload the hive */
377 regUnloadResult
= RegUnLoadKey(hRootKey
, pszKeyPath
);
378 if(regUnloadResult
== ERROR_SUCCESS
)
380 /* refresh tree and list views */
381 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
382 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
383 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
387 ErrorMessageBox(hWnd
, Caption
, regUnloadResult
);
393 static BOOL
ImportRegistryFile(HWND hWnd
)
400 InitOpenFileName(hWnd
, &ofn
);
401 LoadString(hInst
, IDS_IMPORT_REG_FILE
, Caption
, COUNT_OF(Caption
));
402 ofn
.lpstrTitle
= Caption
;
403 ofn
.Flags
|= OFN_ENABLESIZING
;
404 /* ofn.lCustData = ;*/
405 if (GetOpenFileName(&ofn
))
407 FILE *fp
= _wfopen(ofn
.lpstrFile
, L
"r");
408 if (fp
== NULL
|| !import_registry_file(fp
))
410 LPSTR p
= GetMultiByteString(ofn
.lpstrFile
);
411 fprintf(stderr
, "Can't open file \"%s\"\n", p
);
412 HeapFree(GetProcessHeap(), 0, p
);
421 CheckCommDlgError(hWnd
);
424 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
425 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
426 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
431 static UINT_PTR CALLBACK
ExportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
434 HWND hwndExportBranch
;
435 HWND hwndExportBranchText
;
436 UINT_PTR iResult
= 0;
438 LPTSTR pszSelectedKey
;
439 OFNOTIFY
*pOfnNotify
;
441 UNREFERENCED_PARAMETER(wParam
);
446 pOfn
= (OPENFILENAME
*) lParam
;
447 pszSelectedKey
= (LPTSTR
) pOfn
->lCustData
;
449 hwndExportAll
= GetDlgItem(hdlg
, IDC_EXPORT_ALL
);
451 SendMessage(hwndExportAll
, BM_SETCHECK
, pszSelectedKey
? BST_UNCHECKED
: BST_CHECKED
, 0);
453 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
454 if (hwndExportBranch
)
455 SendMessage(hwndExportBranch
, BM_SETCHECK
, pszSelectedKey
? BST_CHECKED
: BST_UNCHECKED
, 0);
457 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
458 if (hwndExportBranchText
)
459 SetWindowText(hwndExportBranchText
, pszSelectedKey
);
463 if (((NMHDR
*) lParam
)->code
== CDN_FILEOK
)
465 pOfnNotify
= (OFNOTIFY
*) lParam
;
466 pszSelectedKey
= (LPTSTR
) pOfnNotify
->lpOFN
->lCustData
;
468 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
469 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
470 if (hwndExportBranch
&& hwndExportBranchText
471 && (SendMessage(hwndExportBranch
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
473 GetWindowText(hwndExportBranchText
, pszSelectedKey
, _MAX_PATH
);
477 pszSelectedKey
[0] = '\0';
485 BOOL
ExportRegistryFile(HWND hWnd
)
488 TCHAR ExportKeyPath
[_MAX_PATH
];
493 /* Figure out which key path we are exporting */
494 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
495 GetKeyName(ExportKeyPath
, COUNT_OF(ExportKeyPath
), hKeyRoot
, pszKeyPath
);
497 InitOpenFileName(hWnd
, &ofn
);
498 LoadString(hInst
, IDS_EXPORT_REG_FILE
, Caption
, sizeof(Caption
)/sizeof(TCHAR
));
499 ofn
.lpstrTitle
= Caption
;
501 /* Only set the path if a key (not the root node) is selected */
504 ofn
.lCustData
= (LPARAM
) ExportKeyPath
;
506 ofn
.Flags
= OFN_ENABLETEMPLATE
| OFN_EXPLORER
| OFN_ENABLEHOOK
| OFN_OVERWRITEPROMPT
;
507 ofn
.lpfnHook
= ExportRegistryFile_OFNHookProc
;
508 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_EXPORTRANGE
);
509 if (GetSaveFileName(&ofn
))
514 if (ofn
.nFilterIndex
== 1)
515 format
= REG_FORMAT_5
;
517 format
= REG_FORMAT_4
;
518 result
= export_registry_key(ofn
.lpstrFile
, ExportKeyPath
, format
);
521 LPSTR p
= GetMultiByteString(ofn
.lpstrFile
);
522 fprintf(stderr
, "Can't open file \"%s\"\n", p
);
523 HeapFree(GetProcessHeap(), 0, p
);
529 CheckCommDlgError(hWnd
);
534 BOOL
PrintRegistryHive(HWND hWnd
, LPTSTR path
)
538 UNREFERENCED_PARAMETER(path
);
540 ZeroMemory(&pd
, sizeof(PRINTDLG
));
541 pd
.lStructSize
= sizeof(PRINTDLG
);
543 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
544 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
545 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
547 pd
.nFromPage
= 0xFFFF;
550 pd
.nMaxPage
= 0xFFFF;
553 /* GDI calls to render output. */
554 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
560 hResult
= PrintDlgEx(&pd
);
563 switch (pd
.dwResultAction
)
565 case PD_RESULT_APPLY
:
566 /*The user clicked the Apply button and later clicked the Cancel button. This indicates that the user wants to apply the changes made in the property sheet, but does not yet want to print. The PRINTDLGEX structure contains the information specified by the user at the time the Apply button was clicked. */
568 case PD_RESULT_CANCEL
:
569 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
571 case PD_RESULT_PRINT
:
572 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
583 /*Insufficient memory. */
586 /* One or more arguments are invalid. */
589 /*Invalid pointer. */
595 /*Unspecified error. */
606 static void ChooseFavorite(LPCTSTR pszFavorite
)
609 TCHAR szFavoritePath
[512];
610 DWORD cbData
, dwType
;
612 if (RegOpenKeyEx(HKEY_CURRENT_USER
, s_szFavoritesRegKey
, 0, KEY_QUERY_VALUE
, &hKey
) != ERROR_SUCCESS
)
615 cbData
= (sizeof(szFavoritePath
) / sizeof(szFavoritePath
[0])) - 1;
616 memset(szFavoritePath
, 0, sizeof(szFavoritePath
));
617 if (RegQueryValueEx(hKey
, pszFavorite
, NULL
, &dwType
, (LPBYTE
) szFavoritePath
, &cbData
) != ERROR_SUCCESS
)
620 if (dwType
== REG_SZ
)
621 SelectNode(g_pChildWnd
->hTreeWnd
, szFavoritePath
);
628 BOOL
CopyKeyName(HWND hWnd
, HKEY hRootKey
, LPCTSTR keyName
)
630 BOOL bClipboardOpened
= FALSE
;
631 BOOL bSuccess
= FALSE
;
636 if (!OpenClipboard(hWnd
))
638 bClipboardOpened
= TRUE
;
640 if (!EmptyClipboard())
643 if (!GetKeyName(szBuffer
, COUNT_OF(szBuffer
), hRootKey
, keyName
))
646 hGlobal
= GlobalAlloc(GMEM_MOVEABLE
, (lstrlen(szBuffer
) + 1) * sizeof(TCHAR
));
650 s
= GlobalLock(hGlobal
);
651 _tcscpy(s
, szBuffer
);
652 GlobalUnlock(hGlobal
);
655 SetClipboardData(CF_UNICODETEXT
, hGlobal
);
657 SetClipboardData(CF_TEXT
, hGlobal
);
662 if (bClipboardOpened
)
667 static BOOL
CreateNewValue(HKEY hRootKey
, LPCTSTR pszKeyPath
, DWORD dwType
)
669 TCHAR szNewValueFormat
[128];
670 TCHAR szNewValue
[128];
673 DWORD dwExistingType
, cbData
;
678 if (RegOpenKeyEx(hRootKey
, pszKeyPath
, 0, KEY_QUERY_VALUE
| KEY_SET_VALUE
,
679 &hKey
) != ERROR_SUCCESS
)
682 LoadString(hInst
, IDS_NEW_VALUE
, szNewValueFormat
, COUNT_OF(szNewValueFormat
));
686 wsprintf(szNewValue
, szNewValueFormat
, iIndex
++);
687 cbData
= sizeof(data
);
688 lResult
= RegQueryValueEx(hKey
, szNewValue
, NULL
, &dwExistingType
, data
, &cbData
);
690 while(lResult
== ERROR_SUCCESS
);
695 cbData
= sizeof(DWORD
);
699 cbData
= sizeof(TCHAR
);
702 cbData
= sizeof(TCHAR
) * 2;
705 cbData
= sizeof(DWORD
) * 2;
711 memset(data
, 0, cbData
);
712 lResult
= RegSetValueEx(hKey
, szNewValue
, 0, dwType
, data
, cbData
);
714 if (lResult
!= ERROR_SUCCESS
)
719 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
721 /* locate the newly added value, and get ready to rename it */
722 memset(&lvfi
, 0, sizeof(lvfi
));
723 lvfi
.flags
= LVFI_STRING
;
724 lvfi
.psz
= szNewValue
;
725 iIndex
= ListView_FindItem(g_pChildWnd
->hListWnd
, -1, &lvfi
);
727 (void)ListView_EditLabel(g_pChildWnd
->hListWnd
, iIndex
);
733 InitializeRemoteRegistryPicker(OUT IDsObjectPicker
**pDsObjectPicker
)
737 *pDsObjectPicker
= NULL
;
739 hRet
= CoCreateInstance(&CLSID_DsObjectPicker
,
741 CLSCTX_INPROC_SERVER
,
742 &IID_IDsObjectPicker
,
743 (LPVOID
*)pDsObjectPicker
);
746 DSOP_INIT_INFO InitInfo
;
747 static DSOP_SCOPE_INIT_INFO Scopes
[] =
750 sizeof(DSOP_SCOPE_INIT_INFO
),
751 DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE
| DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE
|
752 DSOP_SCOPE_TYPE_GLOBAL_CATALOG
| DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN
|
753 DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN
| DSOP_SCOPE_TYPE_WORKGROUP
|
754 DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
| DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN
,
758 DSOP_FILTER_COMPUTERS
,
762 DSOP_DOWNLEVEL_FILTER_COMPUTERS
770 InitInfo
.cbSize
= sizeof(InitInfo
);
771 InitInfo
.pwzTargetComputer
= NULL
;
772 InitInfo
.cDsScopeInfos
= sizeof(Scopes
) / sizeof(Scopes
[0]);
773 InitInfo
.aDsScopeInfos
= Scopes
;
774 InitInfo
.flOptions
= 0;
775 InitInfo
.cAttributesToFetch
= 0;
776 InitInfo
.apwzAttributeNames
= NULL
;
778 hRet
= (*pDsObjectPicker
)->lpVtbl
->Initialize(*pDsObjectPicker
,
783 /* delete the object picker in case initialization failed! */
784 (*pDsObjectPicker
)->lpVtbl
->Release(*pDsObjectPicker
);
792 InvokeRemoteRegistryPickerDialog(IN IDsObjectPicker
*pDsObjectPicker
,
793 IN HWND hwndParent OPTIONAL
,
797 IDataObject
*pdo
= NULL
;
800 hRet
= pDsObjectPicker
->lpVtbl
->InvokeDialog(pDsObjectPicker
,
808 fe
.cfFormat
= (CLIPFORMAT
) RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST
);
810 fe
.dwAspect
= DVASPECT_CONTENT
;
812 fe
.tymed
= TYMED_HGLOBAL
;
814 hRet
= pdo
->lpVtbl
->GetData(pdo
,
819 PDS_SELECTION_LIST SelectionList
= (PDS_SELECTION_LIST
)GlobalLock(stm
.hGlobal
);
820 if (SelectionList
!= NULL
)
822 if (SelectionList
->cItems
== 1)
824 size_t nlen
= wcslen(SelectionList
->aDsSelection
[0].pwzName
);
831 SelectionList
->aDsSelection
[0].pwzName
,
832 nlen
* sizeof(WCHAR
));
834 WideCharToMultiByte(CP_ACP
,
836 SelectionList
->aDsSelection
[0].pwzName
,
843 lpBuffer
[nlen
] = L
'\0';
846 GlobalUnlock(stm
.hGlobal
);
849 ReleaseStgMedium(&stm
);
852 pdo
->lpVtbl
->Release(pdo
);
859 FreeObjectPicker(IN IDsObjectPicker
*pDsObjectPicker
)
861 pDsObjectPicker
->lpVtbl
->Release(pDsObjectPicker
);
864 /*******************************************************************************
866 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
868 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
871 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
873 HKEY hKeyRoot
= 0, hKey
= 0;
877 REGSAM regsam
= KEY_READ
;
881 UNREFERENCED_PARAMETER(lParam
);
882 UNREFERENCED_PARAMETER(message
);
884 switch (LOWORD(wParam
))
886 case ID_REGISTRY_LOADHIVE
:
889 case ID_REGISTRY_UNLOADHIVE
:
892 case ID_REGISTRY_IMPORTREGISTRYFILE
:
893 ImportRegistryFile(hWnd
);
895 case ID_REGISTRY_EXPORTREGISTRYFILE
:
896 ExportRegistryFile(hWnd
);
898 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
900 IDsObjectPicker
*ObjectPicker
;
901 TCHAR szComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
904 hRet
= CoInitialize(NULL
);
907 hRet
= InitializeRemoteRegistryPicker(&ObjectPicker
);
910 hRet
= InvokeRemoteRegistryPickerDialog(ObjectPicker
,
913 sizeof(szComputerName
) / sizeof(szComputerName
[0]));
916 /* FIXME - connect to the registry */
919 FreeObjectPicker(ObjectPicker
);
927 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
929 case ID_REGISTRY_PRINT
:
930 PrintRegistryHive(hWnd
, _T(""));
932 case ID_REGISTRY_EXIT
:
935 case ID_VIEW_STATUSBAR
:
936 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
938 case ID_HELP_HELPTOPICS
:
939 WinHelp(hWnd
, _T("regedit"), HELP_FINDER
, 0);
948 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
949 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
950 pt
.y
= (rt
.bottom
/ 2);
952 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
))
954 SetCursorPos(pts
.x
, pts
.y
);
955 SetCursor(LoadCursor(0, IDC_SIZEWE
));
956 SendMessage(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
962 case ID_EDIT_MODIFY_BIN
:
968 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
969 valueName
= GetValueName(g_pChildWnd
->hListWnd
, -1);
972 lRet
= RegOpenKeyEx(hKeyRoot
, keyPath
, 0, regsam
, &hKey
);
973 if (lRet
!= ERROR_SUCCESS
) hKey
= 0;
976 switch (LOWORD(wParam
))
979 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, FALSE
))
980 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
982 case ID_EDIT_MODIFY_BIN
:
983 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, TRUE
))
984 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
987 if (GetFocus() == g_pChildWnd
->hListWnd
)
989 if(ListView_GetSelectedCount(g_pChildWnd
->hListWnd
) == 1)
991 item
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_SELECTED
);
994 (void)ListView_EditLabel(g_pChildWnd
->hListWnd
, item
);
998 else if (GetFocus() == g_pChildWnd
->hTreeWnd
)
1000 /* Get focused entry of treeview (if any) */
1001 HTREEITEM hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
1003 (void)TreeView_EditLabel(g_pChildWnd
->hTreeWnd
, hItem
);
1006 case ID_EDIT_DELETE
:
1008 if (GetFocus() == g_pChildWnd
->hListWnd
)
1010 UINT nSelected
= ListView_GetSelectedCount(g_pChildWnd
->hListWnd
);
1013 TCHAR msg
[128], caption
[128];
1014 LoadString(hInst
, IDS_QUERY_DELETE_CONFIRM
, caption
, sizeof(caption
)/sizeof(TCHAR
));
1015 LoadString(hInst
, (nSelected
== 1 ? IDS_QUERY_DELETE_ONE
: IDS_QUERY_DELETE_MORE
), msg
, sizeof(msg
)/sizeof(TCHAR
));
1016 if(MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONQUESTION
| MB_YESNO
) == IDYES
)
1022 while((ni
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, item
, LVNI_SELECTED
)) > -1)
1024 valueName
= GetValueName(g_pChildWnd
->hListWnd
, item
);
1025 if(RegDeleteValue(hKey
, valueName
) != ERROR_SUCCESS
)
1032 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
1035 LoadString(hInst
, IDS_ERR_DELVAL_CAPTION
, caption
, sizeof(caption
)/sizeof(TCHAR
));
1036 LoadString(hInst
, IDS_ERR_DELETEVALUE
, msg
, sizeof(msg
)/sizeof(TCHAR
));
1037 MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONSTOP
);
1042 else if (GetFocus() == g_pChildWnd
->hTreeWnd
)
1044 if (keyPath
== 0 || *keyPath
== 0)
1046 MessageBeep(MB_ICONHAND
);
1048 else if (DeleteKey(hWnd
, hKeyRoot
, keyPath
))
1050 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
1051 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
1056 case ID_EDIT_NEW_STRINGVALUE
:
1057 CreateNewValue(hKeyRoot
, keyPath
, REG_SZ
);
1059 case ID_EDIT_NEW_BINARYVALUE
:
1060 CreateNewValue(hKeyRoot
, keyPath
, REG_BINARY
);
1062 case ID_EDIT_NEW_DWORDVALUE
:
1063 CreateNewValue(hKeyRoot
, keyPath
, REG_DWORD
);
1065 case ID_EDIT_NEW_MULTISTRINGVALUE
:
1066 CreateNewValue(hKeyRoot
, keyPath
, REG_MULTI_SZ
);
1068 case ID_EDIT_NEW_EXPANDABLESTRINGVALUE
:
1069 CreateNewValue(hKeyRoot
, keyPath
, REG_EXPAND_SZ
);
1074 case ID_EDIT_FINDNEXT
:
1077 case ID_EDIT_COPYKEYNAME
:
1078 CopyKeyName(hWnd
, hKeyRoot
, keyPath
);
1080 case ID_EDIT_PERMISSIONS
:
1081 RegKeyEditPermissions(hWnd
, hKeyRoot
, NULL
, keyPath
);
1083 case ID_REGISTRY_PRINTERSETUP
:
1086 /*PAGESETUPDLG psd;*/
1087 /*PageSetupDlg(&psd);*/
1089 case ID_REGISTRY_OPENLOCAL
:
1092 case ID_VIEW_REFRESH
:
1093 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
1094 /*RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); */
1096 /*case ID_OPTIONS_TOOLBAR:*/
1097 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
1099 case ID_EDIT_NEW_KEY
:
1100 CreateNewKey(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
));
1103 if ((LOWORD(wParam
) >= ID_FAVORITES_MIN
) && (LOWORD(wParam
) <= ID_FAVORITES_MAX
))
1107 TCHAR szFavorite
[512];
1109 hMenu
= GetSubMenu(GetMenu(hWnd
), FAVORITES_MENU_POSITION
);
1111 memset(&mii
, 0, sizeof(mii
));
1112 mii
.cbSize
= sizeof(mii
);
1113 mii
.fMask
= MIIM_TYPE
;
1114 mii
.fType
= MFT_STRING
;
1115 mii
.dwTypeData
= szFavorite
;
1116 mii
.cch
= sizeof(szFavorite
) / sizeof(szFavorite
[0]);
1118 if (GetMenuItemInfo(hMenu
, LOWORD(wParam
) - ID_FAVORITES_MIN
, TRUE
, &mii
))
1120 ChooseFavorite(szFavorite
);
1135 /********************************************************************************
1137 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
1139 * PURPOSE: Processes messages for the main frame window.
1141 * WM_COMMAND - process the application menu
1142 * WM_DESTROY - post a quit message and return
1146 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1151 CreateWindowEx(0, szChildClass
, NULL
, WS_CHILD
| WS_VISIBLE
,
1152 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1153 hWnd
, (HMENU
)0, hInst
, 0);
1156 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
1157 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1161 SetFocus(g_pChildWnd
->hWnd
);
1164 resize_frame_client(hWnd
);
1171 case WM_ENTERMENULOOP
:
1172 OnEnterMenuLoop(hWnd
);
1174 case WM_EXITMENULOOP
:
1175 OnExitMenuLoop(hWnd
);
1178 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
1180 case WM_SYSCOLORCHANGE
:
1181 /* Forward WM_SYSCOLORCHANGE to common controls */
1182 SendMessage(g_pChildWnd
->hListWnd
, WM_SYSCOLORCHANGE
, 0, 0);
1183 SendMessage(g_pChildWnd
->hTreeWnd
, WM_SYSCOLORCHANGE
, 0, 0);
1186 WinHelp(hWnd
, _T("regedit"), HELP_QUIT
, 0);
1189 return DefWindowProc(hWnd
, message
, wParam
, lParam
);