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
)) {
49 SetupStatusBar(hWnd
, TRUE
);
50 GetClientRect(hStatusBar
, &rt
);
51 prect
->bottom
-= rt
.bottom
;
53 MoveWindow(g_pChildWnd
->hWnd
, prect
->left
, prect
->top
, prect
->right
, prect
->bottom
, TRUE
);
56 static void resize_frame_client(HWND hWnd
)
60 GetClientRect(hWnd
, &rect
);
61 resize_frame_rect(hWnd
, &rect
);
64 /********************************************************************************/
66 static void OnInitMenu(HWND hWnd
)
70 DWORD dwIndex
, cbValueName
, cbValueData
, dwType
;
71 TCHAR szValueName
[256];
72 BYTE abValueData
[256];
73 static int s_nFavoriteMenuSubPos
= -1;
75 BOOL bDisplayedAny
= FALSE
;
77 /* Find Favorites menu and clear it out */
78 hMenu
= GetSubMenu(GetMenu(hWnd
), FAVORITES_MENU_POSITION
);
81 if (s_nFavoriteMenuSubPos
< 0)
83 s_nFavoriteMenuSubPos
= GetMenuItemCount(hMenu
);
87 while(RemoveMenu(hMenu
, s_nFavoriteMenuSubPos
, MF_BYPOSITION
))
91 lResult
= RegOpenKey(HKEY_CURRENT_USER
, s_szFavoritesRegKey
, &hKey
);
92 if (lResult
!= ERROR_SUCCESS
)
98 cbValueName
= COUNT_OF(szValueName
);
99 cbValueData
= sizeof(abValueData
);
100 lResult
= RegEnumValue(hKey
, dwIndex
, szValueName
, &cbValueName
, NULL
, &dwType
, abValueData
, &cbValueData
);
101 if ((lResult
== ERROR_SUCCESS
) && (dwType
== REG_SZ
))
105 AppendMenu(hMenu
, MF_SEPARATOR
, 0, NULL
);
106 bDisplayedAny
= TRUE
;
108 AppendMenu(hMenu
, 0, ID_FAVORITES_MIN
+ GetMenuItemCount(hMenu
), szValueName
);
112 while(lResult
== ERROR_SUCCESS
);
119 static void OnEnterMenuLoop(HWND hWnd
)
122 UNREFERENCED_PARAMETER(hWnd
);
124 /* Update the status bar pane sizes */
126 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
128 SendMessage(hStatusBar
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)_T(""));
131 static void OnExitMenuLoop(HWND hWnd
)
134 /* Update the status bar pane sizes*/
135 SetupStatusBar(hWnd
, TRUE
);
139 static void OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
143 _tcscpy(str
, _T(""));
144 if (nFlags
& MF_POPUP
) {
145 if (hSysMenu
!= GetMenu(hWnd
)) {
146 if (nItemID
== 2) nItemID
= 5;
149 if (LoadString(hInst
, nItemID
, str
, 100)) {
150 /* load appropriate string*/
152 /* first newline terminates actual string*/
153 lpsz
= _tcschr(lpsz
, _T('\n'));
157 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)str
);
160 void SetupStatusBar(HWND hWnd
, BOOL bResize
)
164 GetClientRect(hWnd
, &rc
);
168 SendMessage(hStatusBar
, WM_SIZE
, 0, 0);
169 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
172 void UpdateStatusBar(void)
175 ZeroMemory(&nmhdr
, sizeof(NMHDR
));
176 nmhdr
.code
= TVN_SELCHANGED
;
177 SendMessage(g_pChildWnd
->hWnd
, WM_NOTIFY
, (WPARAM
)TREE_WINDOW
, (LPARAM
)&nmhdr
);
180 static void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
182 BOOL vis
= IsWindowVisible(hchild
);
183 HMENU hMenuView
= GetSubMenu(hMenuFrame
, ID_VIEW_MENU
);
185 CheckMenuItem(hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
186 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
187 resize_frame_client(hWnd
);
190 static BOOL
CheckCommDlgError(HWND hWnd
)
192 DWORD dwErrorCode
= CommDlgExtendedError();
193 UNREFERENCED_PARAMETER(hWnd
);
194 switch (dwErrorCode
) {
195 case CDERR_DIALOGFAILURE
:
197 case CDERR_FINDRESFAILURE
:
199 case CDERR_NOHINSTANCE
:
201 case CDERR_INITIALIZATION
:
205 case CDERR_LOCKRESFAILURE
:
207 case CDERR_NOTEMPLATE
:
209 case CDERR_LOADRESFAILURE
:
211 case CDERR_STRUCTSIZE
:
213 case CDERR_LOADSTRFAILURE
:
215 case FNERR_BUFFERTOOSMALL
:
217 case CDERR_MEMALLOCFAILURE
:
219 case FNERR_INVALIDFILENAME
:
221 case CDERR_MEMLOCKFAILURE
:
223 case FNERR_SUBCLASSFAILURE
:
231 TCHAR FileNameBuffer
[_MAX_PATH
];
232 TCHAR FileTitleBuffer
[_MAX_PATH
];
238 } FILTERPAIR
, *PFILTERPAIR
;
241 BuildFilterStrings(TCHAR
*Filter
, PFILTERPAIR Pairs
, int PairCount
)
246 for(i
= 0; i
< PairCount
; i
++)
248 c
+= LoadString(hInst
, Pairs
[i
].DisplayID
, &Filter
[c
], 255 * sizeof(TCHAR
));
250 c
+= LoadString(hInst
, Pairs
[i
].FilterID
, &Filter
[c
], 255 * sizeof(TCHAR
));
256 static BOOL
InitOpenFileName(HWND hWnd
, OPENFILENAME
* pofn
)
258 FILTERPAIR FilterPairs
[3];
259 static TCHAR Filter
[1024];
261 memset(pofn
, 0, sizeof(OPENFILENAME
));
262 pofn
->lStructSize
= sizeof(OPENFILENAME
);
263 pofn
->hwndOwner
= hWnd
;
264 pofn
->hInstance
= hInst
;
266 /* create filter string */
267 FilterPairs
[0].DisplayID
= IDS_FLT_REGFILES
;
268 FilterPairs
[0].FilterID
= IDS_FLT_REGFILES_FLT
;
269 FilterPairs
[1].DisplayID
= IDS_FLT_REGEDIT4
;
270 FilterPairs
[1].FilterID
= IDS_FLT_REGEDIT4_FLT
;
271 FilterPairs
[2].DisplayID
= IDS_FLT_ALLFILES
;
272 FilterPairs
[2].FilterID
= IDS_FLT_ALLFILES_FLT
;
273 BuildFilterStrings(Filter
, FilterPairs
, sizeof(FilterPairs
) / sizeof(FILTERPAIR
));
275 pofn
->lpstrFilter
= Filter
;
276 pofn
->lpstrFile
= FileNameBuffer
;
277 pofn
->nMaxFile
= _MAX_PATH
;
278 pofn
->lpstrFileTitle
= FileTitleBuffer
;
279 pofn
->nMaxFileTitle
= _MAX_PATH
;
280 pofn
->Flags
= OFN_HIDEREADONLY
;
281 pofn
->lpstrDefExt
= TEXT("reg");
285 static INT_PTR CALLBACK
LoadHive_KeyNameInHookProc(HWND hWndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
287 static LPTSTR sKey
= NULL
;
288 static INT sLength
= 0;
292 sKey
= (LPTSTR
)lParam
;
293 sLength
= 128; /* FIXME: Ugly hack! */
295 switch(LOWORD(wParam
))
298 if(GetDlgItemText(hWndDlg
, IDC_EDIT_KEY
, sKey
, sLength
))
299 return EndDialog(hWndDlg
, -1);
301 return EndDialog(hWndDlg
, 0);
303 return EndDialog(hWndDlg
, 0);
310 static BOOL
LoadHive(HWND hWnd
)
319 /* get the item key to load the hive in */
320 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
321 /* initialize the "open file" dialog */
322 InitOpenFileName(hWnd
, &ofn
);
323 /* build the "All Files" filter up */
324 filter
.DisplayID
= IDS_FLT_ALLFILES
;
325 filter
.FilterID
= IDS_FLT_ALLFILES_FLT
;
326 BuildFilterStrings(Filter
, &filter
, sizeof(filter
));
327 ofn
.lpstrFilter
= Filter
;
328 /* load and set the caption and flags for dialog */
329 LoadString(hInst
, IDS_LOAD_HIVE
, Caption
, COUNT_OF(Caption
));
330 ofn
.lpstrTitle
= Caption
;
331 ofn
.Flags
|= OFN_ENABLESIZING
;
332 /* ofn.lCustData = ;*/
333 /* now load the hive */
334 if (GetOpenFileName(&ofn
))
336 if(DialogBoxParam(hInst
, MAKEINTRESOURCE(IDD_LOADHIVE
), hWnd
, &LoadHive_KeyNameInHookProc
, (LPARAM
)xPath
))
338 LONG regLoadResult
= RegLoadKey(hRootKey
, xPath
, ofn
.lpstrFile
);
339 if(regLoadResult
== ERROR_SUCCESS
)
341 /* refresh tree and list views */
342 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
343 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
344 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
348 ErrorMessageBox(hWnd
, Caption
, regLoadResult
);
353 CheckCommDlgError(hWnd
);
358 static BOOL
UnloadHive(HWND hWnd
)
363 LONG regUnloadResult
;
365 /* get the item key to unload */
366 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
367 /* load and set the caption and flags for dialog */
368 LoadString(hInst
, IDS_UNLOAD_HIVE
, Caption
, COUNT_OF(Caption
));
369 /* now unload the hive */
370 regUnloadResult
= RegUnLoadKey(hRootKey
, pszKeyPath
);
371 if(regUnloadResult
== ERROR_SUCCESS
)
373 /* refresh tree and list views */
374 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
375 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
376 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
380 ErrorMessageBox(hWnd
, Caption
, regUnloadResult
);
386 static BOOL
ImportRegistryFile(HWND hWnd
)
393 InitOpenFileName(hWnd
, &ofn
);
394 LoadString(hInst
, IDS_IMPORT_REG_FILE
, Caption
, COUNT_OF(Caption
));
395 ofn
.lpstrTitle
= Caption
;
396 ofn
.Flags
|= OFN_ENABLESIZING
;
397 /* ofn.lCustData = ;*/
398 if (GetOpenFileName(&ofn
)) {
399 FILE *fp
= _wfopen(ofn
.lpstrFile
, L
"r");
400 if (fp
== NULL
|| !import_registry_file(fp
)) {
401 LPSTR p
= GetMultiByteString(ofn
.lpstrFile
);
402 fprintf(stderr
, "Can't open file \"%s\"\n", p
);
403 HeapFree(GetProcessHeap(), 0, p
);
410 CheckCommDlgError(hWnd
);
413 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
414 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
415 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
420 static UINT_PTR CALLBACK
ExportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
423 HWND hwndExportBranch
;
424 HWND hwndExportBranchText
;
425 UINT_PTR iResult
= 0;
427 LPTSTR pszSelectedKey
;
428 OFNOTIFY
*pOfnNotify
;
430 UNREFERENCED_PARAMETER(wParam
);
434 pOfn
= (OPENFILENAME
*) lParam
;
435 pszSelectedKey
= (LPTSTR
) pOfn
->lCustData
;
437 hwndExportAll
= GetDlgItem(hdlg
, IDC_EXPORT_ALL
);
439 SendMessage(hwndExportAll
, BM_SETCHECK
, pszSelectedKey
? BST_UNCHECKED
: BST_CHECKED
, 0);
441 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
442 if (hwndExportBranch
)
443 SendMessage(hwndExportBranch
, BM_SETCHECK
, pszSelectedKey
? BST_CHECKED
: BST_UNCHECKED
, 0);
445 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
446 if (hwndExportBranchText
)
447 SetWindowText(hwndExportBranchText
, pszSelectedKey
);
451 if (((NMHDR
*) lParam
)->code
== CDN_FILEOK
)
453 pOfnNotify
= (OFNOTIFY
*) lParam
;
454 pszSelectedKey
= (LPTSTR
) pOfnNotify
->lpOFN
->lCustData
;
456 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
457 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
458 if (hwndExportBranch
&& hwndExportBranchText
459 && (SendMessage(hwndExportBranch
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
461 GetWindowText(hwndExportBranchText
, pszSelectedKey
, _MAX_PATH
);
465 pszSelectedKey
[0] = '\0';
473 BOOL
ExportRegistryFile(HWND hWnd
)
476 TCHAR ExportKeyPath
[_MAX_PATH
];
481 /* Figure out which key path we are exporting */
482 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
483 GetKeyName(ExportKeyPath
, COUNT_OF(ExportKeyPath
), hKeyRoot
, pszKeyPath
);
485 InitOpenFileName(hWnd
, &ofn
);
486 LoadString(hInst
, IDS_EXPORT_REG_FILE
, Caption
, sizeof(Caption
)/sizeof(TCHAR
));
487 ofn
.lpstrTitle
= Caption
;
489 /* Only set the path if a key (not the root node) is selected */
492 ofn
.lCustData
= (LPARAM
) ExportKeyPath
;
494 ofn
.Flags
= OFN_ENABLETEMPLATE
| OFN_EXPLORER
| OFN_ENABLEHOOK
| OFN_OVERWRITEPROMPT
;
495 ofn
.lpfnHook
= ExportRegistryFile_OFNHookProc
;
496 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_EXPORTRANGE
);
497 if (GetSaveFileName(&ofn
)) {
501 if (ofn
.nFilterIndex
== 1)
502 format
= REG_FORMAT_5
;
504 format
= REG_FORMAT_4
;
505 result
= export_registry_key(ofn
.lpstrFile
, ExportKeyPath
, format
);
507 LPSTR p
= GetMultiByteString(ofn
.lpstrFile
);
508 fprintf(stderr
, "Can't open file \"%s\"\n", p
);
509 HeapFree(GetProcessHeap(), 0, p
);
513 CheckCommDlgError(hWnd
);
518 BOOL
PrintRegistryHive(HWND hWnd
, LPTSTR path
)
522 UNREFERENCED_PARAMETER(path
);
524 ZeroMemory(&pd
, sizeof(PRINTDLG
));
525 pd
.lStructSize
= sizeof(PRINTDLG
);
527 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
528 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
529 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
531 pd
.nFromPage
= 0xFFFF;
534 pd
.nMaxPage
= 0xFFFF;
536 /* GDI calls to render output. */
537 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
543 hResult
= PrintDlgEx(&pd
);
544 if (hResult
== S_OK
) {
545 switch (pd
.dwResultAction
) {
546 case PD_RESULT_APPLY
:
547 /*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. */
549 case PD_RESULT_CANCEL
:
550 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
552 case PD_RESULT_PRINT
:
553 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
561 /*Insufficient memory. */
564 /* One or more arguments are invalid. */
567 /*Invalid pointer. */
573 /*Unspecified error. */
584 static void ChooseFavorite(LPCTSTR pszFavorite
)
587 TCHAR szFavoritePath
[512];
588 DWORD cbData
, dwType
;
590 if (RegOpenKeyEx(HKEY_CURRENT_USER
, s_szFavoritesRegKey
, 0, KEY_QUERY_VALUE
, &hKey
) != ERROR_SUCCESS
)
593 cbData
= (sizeof(szFavoritePath
) / sizeof(szFavoritePath
[0])) - 1;
594 memset(szFavoritePath
, 0, sizeof(szFavoritePath
));
595 if (RegQueryValueEx(hKey
, pszFavorite
, NULL
, &dwType
, (LPBYTE
) szFavoritePath
, &cbData
) != ERROR_SUCCESS
)
598 if (dwType
== REG_SZ
)
599 SelectNode(g_pChildWnd
->hTreeWnd
, szFavoritePath
);
606 BOOL
CopyKeyName(HWND hWnd
, HKEY hRootKey
, LPCTSTR keyName
)
608 BOOL bClipboardOpened
= FALSE
;
609 BOOL bSuccess
= FALSE
;
614 if (!OpenClipboard(hWnd
))
616 bClipboardOpened
= TRUE
;
618 if (!EmptyClipboard())
621 if (!GetKeyName(szBuffer
, COUNT_OF(szBuffer
), hRootKey
, keyName
))
624 hGlobal
= GlobalAlloc(GMEM_MOVEABLE
, (lstrlen(szBuffer
) + 1) * sizeof(TCHAR
));
628 s
= GlobalLock(hGlobal
);
629 _tcscpy(s
, szBuffer
);
630 GlobalUnlock(hGlobal
);
633 SetClipboardData(CF_UNICODETEXT
, hGlobal
);
635 SetClipboardData(CF_TEXT
, hGlobal
);
640 if (bClipboardOpened
)
645 static BOOL
CreateNewValue(HKEY hRootKey
, LPCTSTR pszKeyPath
, DWORD dwType
)
647 TCHAR szNewValueFormat
[128];
648 TCHAR szNewValue
[128];
651 DWORD dwExistingType
, cbData
;
656 if (RegOpenKeyEx(hRootKey
, pszKeyPath
, 0, KEY_QUERY_VALUE
| KEY_SET_VALUE
,
657 &hKey
) != ERROR_SUCCESS
)
660 LoadString(hInst
, IDS_NEW_VALUE
, szNewValueFormat
, COUNT_OF(szNewValueFormat
));
664 wsprintf(szNewValue
, szNewValueFormat
, iIndex
++);
665 cbData
= sizeof(data
);
666 lResult
= RegQueryValueEx(hKey
, szNewValue
, NULL
, &dwExistingType
, data
, &cbData
);
667 } while(lResult
== ERROR_SUCCESS
);
671 cbData
= sizeof(DWORD
);
675 cbData
= sizeof(TCHAR
);
678 cbData
= sizeof(TCHAR
) * 2;
681 cbData
= sizeof(DWORD
) * 2;
687 memset(data
, 0, cbData
);
688 lResult
= RegSetValueEx(hKey
, szNewValue
, 0, dwType
, data
, cbData
);
690 if (lResult
!= ERROR_SUCCESS
)
695 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
697 /* locate the newly added value, and get ready to rename it */
698 memset(&lvfi
, 0, sizeof(lvfi
));
699 lvfi
.flags
= LVFI_STRING
;
700 lvfi
.psz
= szNewValue
;
701 iIndex
= ListView_FindItem(g_pChildWnd
->hListWnd
, -1, &lvfi
);
703 (void)ListView_EditLabel(g_pChildWnd
->hListWnd
, iIndex
);
709 InitializeRemoteRegistryPicker(OUT IDsObjectPicker
**pDsObjectPicker
)
713 *pDsObjectPicker
= NULL
;
715 hRet
= CoCreateInstance(&CLSID_DsObjectPicker
,
717 CLSCTX_INPROC_SERVER
,
718 &IID_IDsObjectPicker
,
719 (LPVOID
*)pDsObjectPicker
);
722 DSOP_INIT_INFO InitInfo
;
723 static DSOP_SCOPE_INIT_INFO Scopes
[] =
726 sizeof(DSOP_SCOPE_INIT_INFO
),
727 DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE
| DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE
|
728 DSOP_SCOPE_TYPE_GLOBAL_CATALOG
| DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN
|
729 DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN
| DSOP_SCOPE_TYPE_WORKGROUP
|
730 DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
| DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN
,
734 DSOP_FILTER_COMPUTERS
,
738 DSOP_DOWNLEVEL_FILTER_COMPUTERS
746 InitInfo
.cbSize
= sizeof(InitInfo
);
747 InitInfo
.pwzTargetComputer
= NULL
;
748 InitInfo
.cDsScopeInfos
= sizeof(Scopes
) / sizeof(Scopes
[0]);
749 InitInfo
.aDsScopeInfos
= Scopes
;
750 InitInfo
.flOptions
= 0;
751 InitInfo
.cAttributesToFetch
= 0;
752 InitInfo
.apwzAttributeNames
= NULL
;
754 hRet
= (*pDsObjectPicker
)->lpVtbl
->Initialize(*pDsObjectPicker
,
759 /* delete the object picker in case initialization failed! */
760 (*pDsObjectPicker
)->lpVtbl
->Release(*pDsObjectPicker
);
768 InvokeRemoteRegistryPickerDialog(IN IDsObjectPicker
*pDsObjectPicker
,
769 IN HWND hwndParent OPTIONAL
,
773 IDataObject
*pdo
= NULL
;
776 hRet
= pDsObjectPicker
->lpVtbl
->InvokeDialog(pDsObjectPicker
,
784 fe
.cfFormat
= (CLIPFORMAT
) RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST
);
786 fe
.dwAspect
= DVASPECT_CONTENT
;
788 fe
.tymed
= TYMED_HGLOBAL
;
790 hRet
= pdo
->lpVtbl
->GetData(pdo
,
795 PDS_SELECTION_LIST SelectionList
= (PDS_SELECTION_LIST
)GlobalLock(stm
.hGlobal
);
796 if (SelectionList
!= NULL
)
798 if (SelectionList
->cItems
== 1)
800 size_t nlen
= wcslen(SelectionList
->aDsSelection
[0].pwzName
);
807 SelectionList
->aDsSelection
[0].pwzName
,
808 nlen
* sizeof(WCHAR
));
810 WideCharToMultiByte(CP_ACP
,
812 SelectionList
->aDsSelection
[0].pwzName
,
819 lpBuffer
[nlen
] = L
'\0';
822 GlobalUnlock(stm
.hGlobal
);
825 ReleaseStgMedium(&stm
);
828 pdo
->lpVtbl
->Release(pdo
);
835 FreeObjectPicker(IN IDsObjectPicker
*pDsObjectPicker
)
837 pDsObjectPicker
->lpVtbl
->Release(pDsObjectPicker
);
840 /*******************************************************************************
842 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
844 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
847 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
849 HKEY hKeyRoot
= 0, hKey
= 0;
853 REGSAM regsam
= KEY_READ
;
857 UNREFERENCED_PARAMETER(lParam
);
858 UNREFERENCED_PARAMETER(message
);
860 switch (LOWORD(wParam
)) {
861 case ID_REGISTRY_LOADHIVE
:
864 case ID_REGISTRY_UNLOADHIVE
:
867 case ID_REGISTRY_IMPORTREGISTRYFILE
:
868 ImportRegistryFile(hWnd
);
870 case ID_REGISTRY_EXPORTREGISTRYFILE
:
871 ExportRegistryFile(hWnd
);
873 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
875 IDsObjectPicker
*ObjectPicker
;
876 TCHAR szComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
879 hRet
= CoInitialize(NULL
);
882 hRet
= InitializeRemoteRegistryPicker(&ObjectPicker
);
885 hRet
= InvokeRemoteRegistryPickerDialog(ObjectPicker
,
888 sizeof(szComputerName
) / sizeof(szComputerName
[0]));
891 /* FIXME - connect to the registry */
894 FreeObjectPicker(ObjectPicker
);
902 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
904 case ID_REGISTRY_PRINT
:
905 PrintRegistryHive(hWnd
, _T(""));
907 case ID_REGISTRY_EXIT
:
910 case ID_VIEW_STATUSBAR
:
911 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
913 case ID_HELP_HELPTOPICS
:
914 WinHelp(hWnd
, _T("regedit"), HELP_FINDER
, 0);
923 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
924 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
925 pt
.y
= (rt
.bottom
/ 2);
927 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
))
929 SetCursorPos(pts
.x
, pts
.y
);
930 SetCursor(LoadCursor(0, IDC_SIZEWE
));
931 SendMessage(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
937 case ID_EDIT_MODIFY_BIN
:
943 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
944 valueName
= GetValueName(g_pChildWnd
->hListWnd
, -1);
946 lRet
= RegOpenKeyEx(hKeyRoot
, keyPath
, 0, regsam
, &hKey
);
947 if (lRet
!= ERROR_SUCCESS
) hKey
= 0;
950 switch (LOWORD(wParam
)) {
952 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, FALSE
))
953 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
955 case ID_EDIT_MODIFY_BIN
:
956 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, TRUE
))
957 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
960 if (GetFocus() == g_pChildWnd
->hListWnd
)
962 if(ListView_GetSelectedCount(g_pChildWnd
->hListWnd
) == 1)
964 item
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_SELECTED
);
967 (void)ListView_EditLabel(g_pChildWnd
->hListWnd
, item
);
971 else if (GetFocus() == g_pChildWnd
->hTreeWnd
)
973 /* Get focused entry of treeview (if any) */
974 HTREEITEM hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
976 (void)TreeView_EditLabel(g_pChildWnd
->hTreeWnd
, hItem
);
981 if (GetFocus() == g_pChildWnd
->hListWnd
)
983 UINT nSelected
= ListView_GetSelectedCount(g_pChildWnd
->hListWnd
);
986 TCHAR msg
[128], caption
[128];
987 LoadString(hInst
, IDS_QUERY_DELETE_CONFIRM
, caption
, sizeof(caption
)/sizeof(TCHAR
));
988 LoadString(hInst
, (nSelected
== 1 ? IDS_QUERY_DELETE_ONE
: IDS_QUERY_DELETE_MORE
), msg
, sizeof(msg
)/sizeof(TCHAR
));
989 if(MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONQUESTION
| MB_YESNO
) == IDYES
)
995 while((ni
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, item
, LVNI_SELECTED
)) > -1)
997 valueName
= GetValueName(g_pChildWnd
->hListWnd
, item
);
998 if(RegDeleteValue(hKey
, valueName
) != ERROR_SUCCESS
)
1005 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
1008 LoadString(hInst
, IDS_ERR_DELVAL_CAPTION
, caption
, sizeof(caption
)/sizeof(TCHAR
));
1009 LoadString(hInst
, IDS_ERR_DELETEVALUE
, msg
, sizeof(msg
)/sizeof(TCHAR
));
1010 MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONSTOP
);
1015 else if (GetFocus() == g_pChildWnd
->hTreeWnd
)
1017 if (keyPath
== 0 || *keyPath
== 0)
1019 MessageBeep(MB_ICONHAND
);
1021 if (DeleteKey(hWnd
, hKeyRoot
, keyPath
))
1023 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
1024 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
1029 case ID_EDIT_NEW_STRINGVALUE
:
1030 CreateNewValue(hKeyRoot
, keyPath
, REG_SZ
);
1032 case ID_EDIT_NEW_BINARYVALUE
:
1033 CreateNewValue(hKeyRoot
, keyPath
, REG_BINARY
);
1035 case ID_EDIT_NEW_DWORDVALUE
:
1036 CreateNewValue(hKeyRoot
, keyPath
, REG_DWORD
);
1038 case ID_EDIT_NEW_MULTISTRINGVALUE
:
1039 CreateNewValue(hKeyRoot
, keyPath
, REG_MULTI_SZ
);
1041 case ID_EDIT_NEW_EXPANDABLESTRINGVALUE
:
1042 CreateNewValue(hKeyRoot
, keyPath
, REG_EXPAND_SZ
);
1047 case ID_EDIT_FINDNEXT
:
1050 case ID_EDIT_COPYKEYNAME
:
1051 CopyKeyName(hWnd
, hKeyRoot
, keyPath
);
1053 case ID_EDIT_PERMISSIONS
:
1054 RegKeyEditPermissions(hWnd
, hKeyRoot
, NULL
, keyPath
);
1056 case ID_REGISTRY_PRINTERSETUP
:
1059 /*PAGESETUPDLG psd;*/
1060 /*PageSetupDlg(&psd);*/
1062 case ID_REGISTRY_OPENLOCAL
:
1065 case ID_VIEW_REFRESH
:
1066 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
1067 /*RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); */
1069 /*case ID_OPTIONS_TOOLBAR:*/
1070 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
1072 case ID_EDIT_NEW_KEY
:
1073 CreateNewKey(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
));
1076 if ((LOWORD(wParam
) >= ID_FAVORITES_MIN
) && (LOWORD(wParam
) <= ID_FAVORITES_MAX
))
1080 TCHAR szFavorite
[512];
1082 hMenu
= GetSubMenu(GetMenu(hWnd
), FAVORITES_MENU_POSITION
);
1084 memset(&mii
, 0, sizeof(mii
));
1085 mii
.cbSize
= sizeof(mii
);
1086 mii
.fMask
= MIIM_TYPE
;
1087 mii
.fType
= MFT_STRING
;
1088 mii
.dwTypeData
= szFavorite
;
1089 mii
.cch
= sizeof(szFavorite
) / sizeof(szFavorite
[0]);
1091 if (GetMenuItemInfo(hMenu
, LOWORD(wParam
) - ID_FAVORITES_MIN
, TRUE
, &mii
))
1093 ChooseFavorite(szFavorite
);
1108 /********************************************************************************
1110 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
1112 * PURPOSE: Processes messages for the main frame window.
1114 * WM_COMMAND - process the application menu
1115 * WM_DESTROY - post a quit message and return
1119 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1123 CreateWindowEx(0, szChildClass
, NULL
, WS_CHILD
| WS_VISIBLE
,
1124 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1125 hWnd
, (HMENU
)0, hInst
, 0);
1128 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
1129 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1133 SetFocus(g_pChildWnd
->hWnd
);
1136 resize_frame_client(hWnd
);
1143 case WM_ENTERMENULOOP
:
1144 OnEnterMenuLoop(hWnd
);
1146 case WM_EXITMENULOOP
:
1147 OnExitMenuLoop(hWnd
);
1150 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
1153 WinHelp(hWnd
, _T("regedit"), HELP_QUIT
, 0);
1156 return DefWindowProc(hWnd
, message
, wParam
, lParam
);