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 BOOL
ImportRegistryFile(HWND hWnd
)
292 InitOpenFileName(hWnd
, &ofn
);
293 LoadString(hInst
, IDS_IMPORT_REG_FILE
, Caption
, COUNT_OF(Caption
));
294 ofn
.lpstrTitle
= Caption
;
295 ofn
.Flags
|= OFN_ENABLESIZING
;
296 /* ofn.lCustData = ;*/
297 if (GetOpenFileName(&ofn
)) {
298 FILE *fp
= _wfopen(ofn
.lpstrFile
, L
"r");
299 if (fp
== NULL
|| !import_registry_file(fp
)) {
300 LPSTR p
= GetMultiByteString(ofn
.lpstrFile
);
301 fprintf(stderr
, "Can't open file \"%s\"\n", p
);
302 HeapFree(GetProcessHeap(), 0, p
);
309 CheckCommDlgError(hWnd
);
312 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
313 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
314 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
320 static UINT_PTR CALLBACK
ExportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
323 HWND hwndExportBranch
;
324 HWND hwndExportBranchText
;
325 UINT_PTR iResult
= 0;
327 LPTSTR pszSelectedKey
;
328 OFNOTIFY
*pOfnNotify
;
330 UNREFERENCED_PARAMETER(wParam
);
334 pOfn
= (OPENFILENAME
*) lParam
;
335 pszSelectedKey
= (LPTSTR
) pOfn
->lCustData
;
337 hwndExportAll
= GetDlgItem(hdlg
, IDC_EXPORT_ALL
);
339 SendMessage(hwndExportAll
, BM_SETCHECK
, pszSelectedKey
? BST_UNCHECKED
: BST_CHECKED
, 0);
341 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
342 if (hwndExportBranch
)
343 SendMessage(hwndExportBranch
, BM_SETCHECK
, pszSelectedKey
? BST_CHECKED
: BST_UNCHECKED
, 0);
345 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
346 if (hwndExportBranchText
)
347 SetWindowText(hwndExportBranchText
, pszSelectedKey
);
351 if (((NMHDR
*) lParam
)->code
== CDN_FILEOK
)
353 pOfnNotify
= (OFNOTIFY
*) lParam
;
354 pszSelectedKey
= (LPTSTR
) pOfnNotify
->lpOFN
->lCustData
;
356 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
357 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
358 if (hwndExportBranch
&& hwndExportBranchText
359 && (SendMessage(hwndExportBranch
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
361 GetWindowText(hwndExportBranchText
, pszSelectedKey
, _MAX_PATH
);
365 pszSelectedKey
[0] = '\0';
373 BOOL
ExportRegistryFile(HWND hWnd
)
376 TCHAR ExportKeyPath
[_MAX_PATH
];
381 /* Figure out which key path we are exporting */
382 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
383 GetKeyName(ExportKeyPath
, COUNT_OF(ExportKeyPath
), hKeyRoot
, pszKeyPath
);
385 InitOpenFileName(hWnd
, &ofn
);
386 LoadString(hInst
, IDS_EXPORT_REG_FILE
, Caption
, sizeof(Caption
)/sizeof(TCHAR
));
387 ofn
.lpstrTitle
= Caption
;
389 /* Only set the path if a key (not the root node) is selected */
392 ofn
.lCustData
= (LPARAM
) ExportKeyPath
;
394 ofn
.Flags
= OFN_ENABLETEMPLATE
| OFN_EXPLORER
| OFN_ENABLEHOOK
| OFN_OVERWRITEPROMPT
;
395 ofn
.lpfnHook
= ExportRegistryFile_OFNHookProc
;
396 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_EXPORTRANGE
);
397 if (GetSaveFileName(&ofn
)) {
401 if (ofn
.nFilterIndex
== 1)
402 format
= REG_FORMAT_5
;
404 format
= REG_FORMAT_4
;
405 result
= export_registry_key(ofn
.lpstrFile
, ExportKeyPath
, format
);
407 LPSTR p
= GetMultiByteString(ofn
.lpstrFile
);
408 fprintf(stderr
, "Can't open file \"%s\"\n", p
);
409 HeapFree(GetProcessHeap(), 0, p
);
413 CheckCommDlgError(hWnd
);
418 BOOL
PrintRegistryHive(HWND hWnd
, LPTSTR path
)
422 UNREFERENCED_PARAMETER(path
);
424 ZeroMemory(&pd
, sizeof(PRINTDLG
));
425 pd
.lStructSize
= sizeof(PRINTDLG
);
427 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
428 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
429 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
431 pd
.nFromPage
= 0xFFFF;
434 pd
.nMaxPage
= 0xFFFF;
436 /* GDI calls to render output. */
437 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
443 hResult
= PrintDlgEx(&pd
);
444 if (hResult
== S_OK
) {
445 switch (pd
.dwResultAction
) {
446 case PD_RESULT_APPLY
:
447 /*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. */
449 case PD_RESULT_CANCEL
:
450 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
452 case PD_RESULT_PRINT
:
453 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
461 /*Insufficient memory. */
464 /* One or more arguments are invalid. */
467 /*Invalid pointer. */
473 /*Unspecified error. */
484 static void ChooseFavorite(LPCTSTR pszFavorite
)
487 TCHAR szFavoritePath
[512];
488 DWORD cbData
, dwType
;
490 if (RegOpenKeyEx(HKEY_CURRENT_USER
, s_szFavoritesRegKey
, 0, KEY_QUERY_VALUE
, &hKey
) != ERROR_SUCCESS
)
493 cbData
= (sizeof(szFavoritePath
) / sizeof(szFavoritePath
[0])) - 1;
494 memset(szFavoritePath
, 0, sizeof(szFavoritePath
));
495 if (RegQueryValueEx(hKey
, pszFavorite
, NULL
, &dwType
, (LPBYTE
) szFavoritePath
, &cbData
) != ERROR_SUCCESS
)
498 if (dwType
== REG_SZ
)
499 SelectNode(g_pChildWnd
->hTreeWnd
, szFavoritePath
);
506 BOOL
CopyKeyName(HWND hWnd
, HKEY hRootKey
, LPCTSTR keyName
)
508 BOOL bClipboardOpened
= FALSE
;
509 BOOL bSuccess
= FALSE
;
514 if (!OpenClipboard(hWnd
))
516 bClipboardOpened
= TRUE
;
518 if (!EmptyClipboard())
521 if (!GetKeyName(szBuffer
, COUNT_OF(szBuffer
), hRootKey
, keyName
))
524 hGlobal
= GlobalAlloc(GMEM_MOVEABLE
, (lstrlen(szBuffer
) + 1) * sizeof(TCHAR
));
528 s
= GlobalLock(hGlobal
);
529 _tcscpy(s
, szBuffer
);
530 GlobalUnlock(hGlobal
);
533 SetClipboardData(CF_UNICODETEXT
, hGlobal
);
535 SetClipboardData(CF_TEXT
, hGlobal
);
540 if (bClipboardOpened
)
545 static BOOL
CreateNewValue(HKEY hRootKey
, LPCTSTR pszKeyPath
, DWORD dwType
)
547 TCHAR szNewValueFormat
[128];
548 TCHAR szNewValue
[128];
551 DWORD dwExistingType
, cbData
;
556 if (RegOpenKeyEx(hRootKey
, pszKeyPath
, 0, KEY_QUERY_VALUE
| KEY_SET_VALUE
,
557 &hKey
) != ERROR_SUCCESS
)
560 LoadString(hInst
, IDS_NEW_VALUE
, szNewValueFormat
, COUNT_OF(szNewValueFormat
));
564 wsprintf(szNewValue
, szNewValueFormat
, iIndex
++);
565 cbData
= sizeof(data
);
566 lResult
= RegQueryValueEx(hKey
, szNewValue
, NULL
, &dwExistingType
, data
, &cbData
);
567 } while(lResult
== ERROR_SUCCESS
);
571 cbData
= sizeof(DWORD
);
575 cbData
= sizeof(TCHAR
);
578 cbData
= sizeof(TCHAR
) * 2;
581 cbData
= sizeof(DWORD
) * 2;
587 memset(data
, 0, cbData
);
588 lResult
= RegSetValueEx(hKey
, szNewValue
, 0, dwType
, data
, cbData
);
590 if (lResult
!= ERROR_SUCCESS
)
595 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
597 /* locate the newly added value, and get ready to rename it */
598 memset(&lvfi
, 0, sizeof(lvfi
));
599 lvfi
.flags
= LVFI_STRING
;
600 lvfi
.psz
= szNewValue
;
601 iIndex
= ListView_FindItem(g_pChildWnd
->hListWnd
, -1, &lvfi
);
603 (void)ListView_EditLabel(g_pChildWnd
->hListWnd
, iIndex
);
609 InitializeRemoteRegistryPicker(OUT IDsObjectPicker
**pDsObjectPicker
)
613 *pDsObjectPicker
= NULL
;
615 hRet
= CoCreateInstance(&CLSID_DsObjectPicker
,
617 CLSCTX_INPROC_SERVER
,
618 &IID_IDsObjectPicker
,
619 (LPVOID
*)pDsObjectPicker
);
622 DSOP_INIT_INFO InitInfo
;
623 static DSOP_SCOPE_INIT_INFO Scopes
[] =
626 sizeof(DSOP_SCOPE_INIT_INFO
),
627 DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE
| DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE
|
628 DSOP_SCOPE_TYPE_GLOBAL_CATALOG
| DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN
|
629 DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN
| DSOP_SCOPE_TYPE_WORKGROUP
|
630 DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
| DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN
,
634 DSOP_FILTER_COMPUTERS
,
638 DSOP_DOWNLEVEL_FILTER_COMPUTERS
646 InitInfo
.cbSize
= sizeof(InitInfo
);
647 InitInfo
.pwzTargetComputer
= NULL
;
648 InitInfo
.cDsScopeInfos
= sizeof(Scopes
) / sizeof(Scopes
[0]);
649 InitInfo
.aDsScopeInfos
= Scopes
;
650 InitInfo
.flOptions
= 0;
651 InitInfo
.cAttributesToFetch
= 0;
652 InitInfo
.apwzAttributeNames
= NULL
;
654 hRet
= (*pDsObjectPicker
)->lpVtbl
->Initialize(*pDsObjectPicker
,
659 /* delete the object picker in case initialization failed! */
660 (*pDsObjectPicker
)->lpVtbl
->Release(*pDsObjectPicker
);
668 InvokeRemoteRegistryPickerDialog(IN IDsObjectPicker
*pDsObjectPicker
,
669 IN HWND hwndParent OPTIONAL
,
673 IDataObject
*pdo
= NULL
;
676 hRet
= pDsObjectPicker
->lpVtbl
->InvokeDialog(pDsObjectPicker
,
684 fe
.cfFormat
= (CLIPFORMAT
) RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST
);
686 fe
.dwAspect
= DVASPECT_CONTENT
;
688 fe
.tymed
= TYMED_HGLOBAL
;
690 hRet
= pdo
->lpVtbl
->GetData(pdo
,
695 PDS_SELECTION_LIST SelectionList
= (PDS_SELECTION_LIST
)GlobalLock(stm
.hGlobal
);
696 if (SelectionList
!= NULL
)
698 if (SelectionList
->cItems
== 1)
700 size_t nlen
= wcslen(SelectionList
->aDsSelection
[0].pwzName
);
707 SelectionList
->aDsSelection
[0].pwzName
,
708 nlen
* sizeof(WCHAR
));
710 WideCharToMultiByte(CP_ACP
,
712 SelectionList
->aDsSelection
[0].pwzName
,
719 lpBuffer
[nlen
] = L
'\0';
722 GlobalUnlock(stm
.hGlobal
);
725 ReleaseStgMedium(&stm
);
728 pdo
->lpVtbl
->Release(pdo
);
735 FreeObjectPicker(IN IDsObjectPicker
*pDsObjectPicker
)
737 pDsObjectPicker
->lpVtbl
->Release(pDsObjectPicker
);
740 /*******************************************************************************
742 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
744 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
747 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
749 HKEY hKeyRoot
= 0, hKey
= 0;
753 REGSAM regsam
= KEY_READ
;
757 UNREFERENCED_PARAMETER(lParam
);
758 UNREFERENCED_PARAMETER(message
);
760 switch (LOWORD(wParam
)) {
761 case ID_REGISTRY_IMPORTREGISTRYFILE
:
762 ImportRegistryFile(hWnd
);
764 case ID_REGISTRY_EXPORTREGISTRYFILE
:
765 ExportRegistryFile(hWnd
);
767 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
769 IDsObjectPicker
*ObjectPicker
;
770 TCHAR szComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
773 hRet
= CoInitialize(NULL
);
776 hRet
= InitializeRemoteRegistryPicker(&ObjectPicker
);
779 hRet
= InvokeRemoteRegistryPickerDialog(ObjectPicker
,
782 sizeof(szComputerName
) / sizeof(szComputerName
[0]));
785 /* FIXME - connect to the registry */
788 FreeObjectPicker(ObjectPicker
);
796 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
798 case ID_REGISTRY_PRINT
:
799 PrintRegistryHive(hWnd
, _T(""));
801 case ID_REGISTRY_EXIT
:
804 case ID_VIEW_STATUSBAR
:
805 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
807 case ID_HELP_HELPTOPICS
:
808 WinHelp(hWnd
, _T("regedit"), HELP_FINDER
, 0);
817 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
818 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
819 pt
.y
= (rt
.bottom
/ 2);
821 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
))
823 SetCursorPos(pts
.x
, pts
.y
);
824 SetCursor(LoadCursor(0, IDC_SIZEWE
));
825 SendMessage(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
831 case ID_EDIT_MODIFY_BIN
:
837 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
838 valueName
= GetValueName(g_pChildWnd
->hListWnd
, -1);
840 lRet
= RegOpenKeyEx(hKeyRoot
, keyPath
, 0, regsam
, &hKey
);
841 if (lRet
!= ERROR_SUCCESS
) hKey
= 0;
844 switch (LOWORD(wParam
)) {
846 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, FALSE
))
847 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
849 case ID_EDIT_MODIFY_BIN
:
850 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, TRUE
))
851 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
854 if (GetFocus() == g_pChildWnd
->hListWnd
)
856 if(ListView_GetSelectedCount(g_pChildWnd
->hListWnd
) == 1)
858 item
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_SELECTED
);
861 (void)ListView_EditLabel(g_pChildWnd
->hListWnd
, item
);
865 else if (GetFocus() == g_pChildWnd
->hTreeWnd
)
867 /* Get focused entry of treeview (if any) */
868 HTREEITEM hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
870 (void)TreeView_EditLabel(g_pChildWnd
->hTreeWnd
, hItem
);
875 if (GetFocus() == g_pChildWnd
->hListWnd
)
877 UINT nSelected
= ListView_GetSelectedCount(g_pChildWnd
->hListWnd
);
880 TCHAR msg
[128], caption
[128];
881 LoadString(hInst
, IDS_QUERY_DELETE_CONFIRM
, caption
, sizeof(caption
)/sizeof(TCHAR
));
882 LoadString(hInst
, (nSelected
== 1 ? IDS_QUERY_DELETE_ONE
: IDS_QUERY_DELETE_MORE
), msg
, sizeof(msg
)/sizeof(TCHAR
));
883 if(MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONQUESTION
| MB_YESNO
) == IDYES
)
889 while((ni
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, item
, LVNI_SELECTED
)) > -1)
891 valueName
= GetValueName(g_pChildWnd
->hListWnd
, item
);
892 if(RegDeleteValue(hKey
, valueName
) != ERROR_SUCCESS
)
899 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
902 LoadString(hInst
, IDS_ERR_DELVAL_CAPTION
, caption
, sizeof(caption
)/sizeof(TCHAR
));
903 LoadString(hInst
, IDS_ERR_DELETEVALUE
, msg
, sizeof(msg
)/sizeof(TCHAR
));
904 MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONSTOP
);
909 else if (GetFocus() == g_pChildWnd
->hTreeWnd
)
911 if (keyPath
== 0 || *keyPath
== 0)
913 MessageBeep(MB_ICONHAND
);
915 if (DeleteKey(hWnd
, hKeyRoot
, keyPath
))
917 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
918 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
923 case ID_EDIT_NEW_STRINGVALUE
:
924 CreateNewValue(hKeyRoot
, keyPath
, REG_SZ
);
926 case ID_EDIT_NEW_BINARYVALUE
:
927 CreateNewValue(hKeyRoot
, keyPath
, REG_BINARY
);
929 case ID_EDIT_NEW_DWORDVALUE
:
930 CreateNewValue(hKeyRoot
, keyPath
, REG_DWORD
);
932 case ID_EDIT_NEW_MULTISTRINGVALUE
:
933 CreateNewValue(hKeyRoot
, keyPath
, REG_MULTI_SZ
);
935 case ID_EDIT_NEW_EXPANDABLESTRINGVALUE
:
936 CreateNewValue(hKeyRoot
, keyPath
, REG_EXPAND_SZ
);
941 case ID_EDIT_FINDNEXT
:
944 case ID_EDIT_COPYKEYNAME
:
945 CopyKeyName(hWnd
, hKeyRoot
, keyPath
);
947 case ID_EDIT_PERMISSIONS
:
948 RegKeyEditPermissions(hWnd
, hKeyRoot
, NULL
, keyPath
);
950 case ID_REGISTRY_PRINTERSETUP
:
953 /*PAGESETUPDLG psd;*/
954 /*PageSetupDlg(&psd);*/
956 case ID_REGISTRY_OPENLOCAL
:
959 case ID_VIEW_REFRESH
:
960 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
961 /*RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); */
963 /*case ID_OPTIONS_TOOLBAR:*/
964 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
966 case ID_EDIT_NEW_KEY
:
967 CreateNewKey(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
));
970 if ((LOWORD(wParam
) >= ID_FAVORITES_MIN
) && (LOWORD(wParam
) <= ID_FAVORITES_MAX
))
974 TCHAR szFavorite
[512];
976 hMenu
= GetSubMenu(GetMenu(hWnd
), FAVORITES_MENU_POSITION
);
978 memset(&mii
, 0, sizeof(mii
));
979 mii
.cbSize
= sizeof(mii
);
980 mii
.fMask
= MIIM_TYPE
;
981 mii
.fType
= MFT_STRING
;
982 mii
.dwTypeData
= szFavorite
;
983 mii
.cch
= sizeof(szFavorite
) / sizeof(szFavorite
[0]);
985 if (GetMenuItemInfo(hMenu
, LOWORD(wParam
) - ID_FAVORITES_MIN
, TRUE
, &mii
))
987 ChooseFavorite(szFavorite
);
1002 /********************************************************************************
1004 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
1006 * PURPOSE: Processes messages for the main frame window.
1008 * WM_COMMAND - process the application menu
1009 * WM_DESTROY - post a quit message and return
1013 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1017 CreateWindowEx(0, szChildClass
, NULL
, WS_CHILD
| WS_VISIBLE
,
1018 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1019 hWnd
, (HMENU
)0, hInst
, 0);
1022 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
1023 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1027 SetFocus(g_pChildWnd
->hWnd
);
1030 resize_frame_client(hWnd
);
1037 case WM_ENTERMENULOOP
:
1038 OnEnterMenuLoop(hWnd
);
1040 case WM_EXITMENULOOP
:
1041 OnExitMenuLoop(hWnd
);
1044 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
1047 WinHelp(hWnd
, _T("regedit"), HELP_QUIT
, 0);
1050 return DefWindowProc(hWnd
, message
, wParam
, lParam
);