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 /* get the item key to unload */
364 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
365 /* load and set the caption and flags for dialog */
366 LoadString(hInst
, IDS_UNLOAD_HIVE
, Caption
, COUNT_OF(Caption
));
367 /* now unload the hive */
368 LONG regUnloadResult
= RegUnLoadKey(hRootKey
, pszKeyPath
);
369 if(regUnloadResult
== ERROR_SUCCESS
)
371 /* refresh tree and list views */
372 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
373 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
374 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
378 ErrorMessageBox(hWnd
, Caption
, regUnloadResult
);
384 static BOOL
ImportRegistryFile(HWND hWnd
)
391 InitOpenFileName(hWnd
, &ofn
);
392 LoadString(hInst
, IDS_IMPORT_REG_FILE
, Caption
, COUNT_OF(Caption
));
393 ofn
.lpstrTitle
= Caption
;
394 ofn
.Flags
|= OFN_ENABLESIZING
;
395 /* ofn.lCustData = ;*/
396 if (GetOpenFileName(&ofn
)) {
397 FILE *fp
= _wfopen(ofn
.lpstrFile
, L
"r");
398 if (fp
== NULL
|| !import_registry_file(fp
)) {
399 LPSTR p
= GetMultiByteString(ofn
.lpstrFile
);
400 fprintf(stderr
, "Can't open file \"%s\"\n", p
);
401 HeapFree(GetProcessHeap(), 0, p
);
408 CheckCommDlgError(hWnd
);
411 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
412 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
413 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
418 static UINT_PTR CALLBACK
ExportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
421 HWND hwndExportBranch
;
422 HWND hwndExportBranchText
;
423 UINT_PTR iResult
= 0;
425 LPTSTR pszSelectedKey
;
426 OFNOTIFY
*pOfnNotify
;
428 UNREFERENCED_PARAMETER(wParam
);
432 pOfn
= (OPENFILENAME
*) lParam
;
433 pszSelectedKey
= (LPTSTR
) pOfn
->lCustData
;
435 hwndExportAll
= GetDlgItem(hdlg
, IDC_EXPORT_ALL
);
437 SendMessage(hwndExportAll
, BM_SETCHECK
, pszSelectedKey
? BST_UNCHECKED
: BST_CHECKED
, 0);
439 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
440 if (hwndExportBranch
)
441 SendMessage(hwndExportBranch
, BM_SETCHECK
, pszSelectedKey
? BST_CHECKED
: BST_UNCHECKED
, 0);
443 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
444 if (hwndExportBranchText
)
445 SetWindowText(hwndExportBranchText
, pszSelectedKey
);
449 if (((NMHDR
*) lParam
)->code
== CDN_FILEOK
)
451 pOfnNotify
= (OFNOTIFY
*) lParam
;
452 pszSelectedKey
= (LPTSTR
) pOfnNotify
->lpOFN
->lCustData
;
454 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
455 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
456 if (hwndExportBranch
&& hwndExportBranchText
457 && (SendMessage(hwndExportBranch
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
459 GetWindowText(hwndExportBranchText
, pszSelectedKey
, _MAX_PATH
);
463 pszSelectedKey
[0] = '\0';
471 BOOL
ExportRegistryFile(HWND hWnd
)
474 TCHAR ExportKeyPath
[_MAX_PATH
];
479 /* Figure out which key path we are exporting */
480 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
481 GetKeyName(ExportKeyPath
, COUNT_OF(ExportKeyPath
), hKeyRoot
, pszKeyPath
);
483 InitOpenFileName(hWnd
, &ofn
);
484 LoadString(hInst
, IDS_EXPORT_REG_FILE
, Caption
, sizeof(Caption
)/sizeof(TCHAR
));
485 ofn
.lpstrTitle
= Caption
;
487 /* Only set the path if a key (not the root node) is selected */
490 ofn
.lCustData
= (LPARAM
) ExportKeyPath
;
492 ofn
.Flags
= OFN_ENABLETEMPLATE
| OFN_EXPLORER
| OFN_ENABLEHOOK
| OFN_OVERWRITEPROMPT
;
493 ofn
.lpfnHook
= ExportRegistryFile_OFNHookProc
;
494 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_EXPORTRANGE
);
495 if (GetSaveFileName(&ofn
)) {
499 if (ofn
.nFilterIndex
== 1)
500 format
= REG_FORMAT_5
;
502 format
= REG_FORMAT_4
;
503 result
= export_registry_key(ofn
.lpstrFile
, ExportKeyPath
, format
);
505 LPSTR p
= GetMultiByteString(ofn
.lpstrFile
);
506 fprintf(stderr
, "Can't open file \"%s\"\n", p
);
507 HeapFree(GetProcessHeap(), 0, p
);
511 CheckCommDlgError(hWnd
);
516 BOOL
PrintRegistryHive(HWND hWnd
, LPTSTR path
)
520 UNREFERENCED_PARAMETER(path
);
522 ZeroMemory(&pd
, sizeof(PRINTDLG
));
523 pd
.lStructSize
= sizeof(PRINTDLG
);
525 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
526 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
527 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
529 pd
.nFromPage
= 0xFFFF;
532 pd
.nMaxPage
= 0xFFFF;
534 /* GDI calls to render output. */
535 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
541 hResult
= PrintDlgEx(&pd
);
542 if (hResult
== S_OK
) {
543 switch (pd
.dwResultAction
) {
544 case PD_RESULT_APPLY
:
545 /*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. */
547 case PD_RESULT_CANCEL
:
548 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
550 case PD_RESULT_PRINT
:
551 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
559 /*Insufficient memory. */
562 /* One or more arguments are invalid. */
565 /*Invalid pointer. */
571 /*Unspecified error. */
582 static void ChooseFavorite(LPCTSTR pszFavorite
)
585 TCHAR szFavoritePath
[512];
586 DWORD cbData
, dwType
;
588 if (RegOpenKeyEx(HKEY_CURRENT_USER
, s_szFavoritesRegKey
, 0, KEY_QUERY_VALUE
, &hKey
) != ERROR_SUCCESS
)
591 cbData
= (sizeof(szFavoritePath
) / sizeof(szFavoritePath
[0])) - 1;
592 memset(szFavoritePath
, 0, sizeof(szFavoritePath
));
593 if (RegQueryValueEx(hKey
, pszFavorite
, NULL
, &dwType
, (LPBYTE
) szFavoritePath
, &cbData
) != ERROR_SUCCESS
)
596 if (dwType
== REG_SZ
)
597 SelectNode(g_pChildWnd
->hTreeWnd
, szFavoritePath
);
604 BOOL
CopyKeyName(HWND hWnd
, HKEY hRootKey
, LPCTSTR keyName
)
606 BOOL bClipboardOpened
= FALSE
;
607 BOOL bSuccess
= FALSE
;
612 if (!OpenClipboard(hWnd
))
614 bClipboardOpened
= TRUE
;
616 if (!EmptyClipboard())
619 if (!GetKeyName(szBuffer
, COUNT_OF(szBuffer
), hRootKey
, keyName
))
622 hGlobal
= GlobalAlloc(GMEM_MOVEABLE
, (lstrlen(szBuffer
) + 1) * sizeof(TCHAR
));
626 s
= GlobalLock(hGlobal
);
627 _tcscpy(s
, szBuffer
);
628 GlobalUnlock(hGlobal
);
631 SetClipboardData(CF_UNICODETEXT
, hGlobal
);
633 SetClipboardData(CF_TEXT
, hGlobal
);
638 if (bClipboardOpened
)
643 static BOOL
CreateNewValue(HKEY hRootKey
, LPCTSTR pszKeyPath
, DWORD dwType
)
645 TCHAR szNewValueFormat
[128];
646 TCHAR szNewValue
[128];
649 DWORD dwExistingType
, cbData
;
654 if (RegOpenKeyEx(hRootKey
, pszKeyPath
, 0, KEY_QUERY_VALUE
| KEY_SET_VALUE
,
655 &hKey
) != ERROR_SUCCESS
)
658 LoadString(hInst
, IDS_NEW_VALUE
, szNewValueFormat
, COUNT_OF(szNewValueFormat
));
662 wsprintf(szNewValue
, szNewValueFormat
, iIndex
++);
663 cbData
= sizeof(data
);
664 lResult
= RegQueryValueEx(hKey
, szNewValue
, NULL
, &dwExistingType
, data
, &cbData
);
665 } while(lResult
== ERROR_SUCCESS
);
669 cbData
= sizeof(DWORD
);
673 cbData
= sizeof(TCHAR
);
676 cbData
= sizeof(TCHAR
) * 2;
679 cbData
= sizeof(DWORD
) * 2;
685 memset(data
, 0, cbData
);
686 lResult
= RegSetValueEx(hKey
, szNewValue
, 0, dwType
, data
, cbData
);
688 if (lResult
!= ERROR_SUCCESS
)
693 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
695 /* locate the newly added value, and get ready to rename it */
696 memset(&lvfi
, 0, sizeof(lvfi
));
697 lvfi
.flags
= LVFI_STRING
;
698 lvfi
.psz
= szNewValue
;
699 iIndex
= ListView_FindItem(g_pChildWnd
->hListWnd
, -1, &lvfi
);
701 (void)ListView_EditLabel(g_pChildWnd
->hListWnd
, iIndex
);
707 InitializeRemoteRegistryPicker(OUT IDsObjectPicker
**pDsObjectPicker
)
711 *pDsObjectPicker
= NULL
;
713 hRet
= CoCreateInstance(&CLSID_DsObjectPicker
,
715 CLSCTX_INPROC_SERVER
,
716 &IID_IDsObjectPicker
,
717 (LPVOID
*)pDsObjectPicker
);
720 DSOP_INIT_INFO InitInfo
;
721 static DSOP_SCOPE_INIT_INFO Scopes
[] =
724 sizeof(DSOP_SCOPE_INIT_INFO
),
725 DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE
| DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE
|
726 DSOP_SCOPE_TYPE_GLOBAL_CATALOG
| DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN
|
727 DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN
| DSOP_SCOPE_TYPE_WORKGROUP
|
728 DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
| DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN
,
732 DSOP_FILTER_COMPUTERS
,
736 DSOP_DOWNLEVEL_FILTER_COMPUTERS
744 InitInfo
.cbSize
= sizeof(InitInfo
);
745 InitInfo
.pwzTargetComputer
= NULL
;
746 InitInfo
.cDsScopeInfos
= sizeof(Scopes
) / sizeof(Scopes
[0]);
747 InitInfo
.aDsScopeInfos
= Scopes
;
748 InitInfo
.flOptions
= 0;
749 InitInfo
.cAttributesToFetch
= 0;
750 InitInfo
.apwzAttributeNames
= NULL
;
752 hRet
= (*pDsObjectPicker
)->lpVtbl
->Initialize(*pDsObjectPicker
,
757 /* delete the object picker in case initialization failed! */
758 (*pDsObjectPicker
)->lpVtbl
->Release(*pDsObjectPicker
);
766 InvokeRemoteRegistryPickerDialog(IN IDsObjectPicker
*pDsObjectPicker
,
767 IN HWND hwndParent OPTIONAL
,
771 IDataObject
*pdo
= NULL
;
774 hRet
= pDsObjectPicker
->lpVtbl
->InvokeDialog(pDsObjectPicker
,
782 fe
.cfFormat
= (CLIPFORMAT
) RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST
);
784 fe
.dwAspect
= DVASPECT_CONTENT
;
786 fe
.tymed
= TYMED_HGLOBAL
;
788 hRet
= pdo
->lpVtbl
->GetData(pdo
,
793 PDS_SELECTION_LIST SelectionList
= (PDS_SELECTION_LIST
)GlobalLock(stm
.hGlobal
);
794 if (SelectionList
!= NULL
)
796 if (SelectionList
->cItems
== 1)
798 size_t nlen
= wcslen(SelectionList
->aDsSelection
[0].pwzName
);
805 SelectionList
->aDsSelection
[0].pwzName
,
806 nlen
* sizeof(WCHAR
));
808 WideCharToMultiByte(CP_ACP
,
810 SelectionList
->aDsSelection
[0].pwzName
,
817 lpBuffer
[nlen
] = L
'\0';
820 GlobalUnlock(stm
.hGlobal
);
823 ReleaseStgMedium(&stm
);
826 pdo
->lpVtbl
->Release(pdo
);
833 FreeObjectPicker(IN IDsObjectPicker
*pDsObjectPicker
)
835 pDsObjectPicker
->lpVtbl
->Release(pDsObjectPicker
);
838 /*******************************************************************************
840 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
842 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
845 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
847 HKEY hKeyRoot
= 0, hKey
= 0;
851 REGSAM regsam
= KEY_READ
;
855 UNREFERENCED_PARAMETER(lParam
);
856 UNREFERENCED_PARAMETER(message
);
858 switch (LOWORD(wParam
)) {
859 case ID_REGISTRY_LOADHIVE
:
862 case ID_REGISTRY_UNLOADHIVE
:
865 case ID_REGISTRY_IMPORTREGISTRYFILE
:
866 ImportRegistryFile(hWnd
);
868 case ID_REGISTRY_EXPORTREGISTRYFILE
:
869 ExportRegistryFile(hWnd
);
871 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
873 IDsObjectPicker
*ObjectPicker
;
874 TCHAR szComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
877 hRet
= CoInitialize(NULL
);
880 hRet
= InitializeRemoteRegistryPicker(&ObjectPicker
);
883 hRet
= InvokeRemoteRegistryPickerDialog(ObjectPicker
,
886 sizeof(szComputerName
) / sizeof(szComputerName
[0]));
889 /* FIXME - connect to the registry */
892 FreeObjectPicker(ObjectPicker
);
900 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
902 case ID_REGISTRY_PRINT
:
903 PrintRegistryHive(hWnd
, _T(""));
905 case ID_REGISTRY_EXIT
:
908 case ID_VIEW_STATUSBAR
:
909 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
911 case ID_HELP_HELPTOPICS
:
912 WinHelp(hWnd
, _T("regedit"), HELP_FINDER
, 0);
921 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
922 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
923 pt
.y
= (rt
.bottom
/ 2);
925 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
))
927 SetCursorPos(pts
.x
, pts
.y
);
928 SetCursor(LoadCursor(0, IDC_SIZEWE
));
929 SendMessage(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
935 case ID_EDIT_MODIFY_BIN
:
941 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
942 valueName
= GetValueName(g_pChildWnd
->hListWnd
, -1);
944 lRet
= RegOpenKeyEx(hKeyRoot
, keyPath
, 0, regsam
, &hKey
);
945 if (lRet
!= ERROR_SUCCESS
) hKey
= 0;
948 switch (LOWORD(wParam
)) {
950 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, FALSE
))
951 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
953 case ID_EDIT_MODIFY_BIN
:
954 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, TRUE
))
955 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
958 if (GetFocus() == g_pChildWnd
->hListWnd
)
960 if(ListView_GetSelectedCount(g_pChildWnd
->hListWnd
) == 1)
962 item
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_SELECTED
);
965 (void)ListView_EditLabel(g_pChildWnd
->hListWnd
, item
);
969 else if (GetFocus() == g_pChildWnd
->hTreeWnd
)
971 /* Get focused entry of treeview (if any) */
972 HTREEITEM hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
974 (void)TreeView_EditLabel(g_pChildWnd
->hTreeWnd
, hItem
);
979 if (GetFocus() == g_pChildWnd
->hListWnd
)
981 UINT nSelected
= ListView_GetSelectedCount(g_pChildWnd
->hListWnd
);
984 TCHAR msg
[128], caption
[128];
985 LoadString(hInst
, IDS_QUERY_DELETE_CONFIRM
, caption
, sizeof(caption
)/sizeof(TCHAR
));
986 LoadString(hInst
, (nSelected
== 1 ? IDS_QUERY_DELETE_ONE
: IDS_QUERY_DELETE_MORE
), msg
, sizeof(msg
)/sizeof(TCHAR
));
987 if(MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONQUESTION
| MB_YESNO
) == IDYES
)
993 while((ni
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, item
, LVNI_SELECTED
)) > -1)
995 valueName
= GetValueName(g_pChildWnd
->hListWnd
, item
);
996 if(RegDeleteValue(hKey
, valueName
) != ERROR_SUCCESS
)
1003 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
1006 LoadString(hInst
, IDS_ERR_DELVAL_CAPTION
, caption
, sizeof(caption
)/sizeof(TCHAR
));
1007 LoadString(hInst
, IDS_ERR_DELETEVALUE
, msg
, sizeof(msg
)/sizeof(TCHAR
));
1008 MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONSTOP
);
1013 else if (GetFocus() == g_pChildWnd
->hTreeWnd
)
1015 if (keyPath
== 0 || *keyPath
== 0)
1017 MessageBeep(MB_ICONHAND
);
1019 if (DeleteKey(hWnd
, hKeyRoot
, keyPath
))
1021 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
1022 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
1027 case ID_EDIT_NEW_STRINGVALUE
:
1028 CreateNewValue(hKeyRoot
, keyPath
, REG_SZ
);
1030 case ID_EDIT_NEW_BINARYVALUE
:
1031 CreateNewValue(hKeyRoot
, keyPath
, REG_BINARY
);
1033 case ID_EDIT_NEW_DWORDVALUE
:
1034 CreateNewValue(hKeyRoot
, keyPath
, REG_DWORD
);
1036 case ID_EDIT_NEW_MULTISTRINGVALUE
:
1037 CreateNewValue(hKeyRoot
, keyPath
, REG_MULTI_SZ
);
1039 case ID_EDIT_NEW_EXPANDABLESTRINGVALUE
:
1040 CreateNewValue(hKeyRoot
, keyPath
, REG_EXPAND_SZ
);
1045 case ID_EDIT_FINDNEXT
:
1048 case ID_EDIT_COPYKEYNAME
:
1049 CopyKeyName(hWnd
, hKeyRoot
, keyPath
);
1051 case ID_EDIT_PERMISSIONS
:
1052 RegKeyEditPermissions(hWnd
, hKeyRoot
, NULL
, keyPath
);
1054 case ID_REGISTRY_PRINTERSETUP
:
1057 /*PAGESETUPDLG psd;*/
1058 /*PageSetupDlg(&psd);*/
1060 case ID_REGISTRY_OPENLOCAL
:
1063 case ID_VIEW_REFRESH
:
1064 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
1065 /*RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); */
1067 /*case ID_OPTIONS_TOOLBAR:*/
1068 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
1070 case ID_EDIT_NEW_KEY
:
1071 CreateNewKey(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
));
1074 if ((LOWORD(wParam
) >= ID_FAVORITES_MIN
) && (LOWORD(wParam
) <= ID_FAVORITES_MAX
))
1078 TCHAR szFavorite
[512];
1080 hMenu
= GetSubMenu(GetMenu(hWnd
), FAVORITES_MENU_POSITION
);
1082 memset(&mii
, 0, sizeof(mii
));
1083 mii
.cbSize
= sizeof(mii
);
1084 mii
.fMask
= MIIM_TYPE
;
1085 mii
.fType
= MFT_STRING
;
1086 mii
.dwTypeData
= szFavorite
;
1087 mii
.cch
= sizeof(szFavorite
) / sizeof(szFavorite
[0]);
1089 if (GetMenuItemInfo(hMenu
, LOWORD(wParam
) - ID_FAVORITES_MIN
, TRUE
, &mii
))
1091 ChooseFavorite(szFavorite
);
1106 /********************************************************************************
1108 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
1110 * PURPOSE: Processes messages for the main frame window.
1112 * WM_COMMAND - process the application menu
1113 * WM_DESTROY - post a quit message and return
1117 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1121 CreateWindowEx(0, szChildClass
, NULL
, WS_CHILD
| WS_VISIBLE
,
1122 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1123 hWnd
, (HMENU
)0, hInst
, 0);
1126 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
1127 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1131 SetFocus(g_pChildWnd
->hWnd
);
1134 resize_frame_client(hWnd
);
1141 case WM_ENTERMENULOOP
:
1142 OnEnterMenuLoop(hWnd
);
1144 case WM_EXITMENULOOP
:
1145 OnExitMenuLoop(hWnd
);
1148 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
1151 WinHelp(hWnd
, _T("regedit"), HELP_QUIT
, 0);
1154 return DefWindowProc(hWnd
, message
, wParam
, lParam
);