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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
= sizeof(szValueName
) / sizeof(szValueName
[0]);
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
, '\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)
177 size
= sizeof(text
)/sizeof(TCHAR
);
178 GetComputerName(text
, &size
);
179 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)text
);
182 static void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
184 BOOL vis
= IsWindowVisible(hchild
);
185 HMENU hMenuView
= GetSubMenu(hMenuFrame
, ID_VIEW_MENU
);
187 CheckMenuItem(hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
188 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
189 resize_frame_client(hWnd
);
192 static BOOL
CheckCommDlgError(HWND hWnd
)
194 DWORD dwErrorCode
= CommDlgExtendedError();
195 UNREFERENCED_PARAMETER(hWnd
);
196 switch (dwErrorCode
) {
197 case CDERR_DIALOGFAILURE
:
199 case CDERR_FINDRESFAILURE
:
201 case CDERR_NOHINSTANCE
:
203 case CDERR_INITIALIZATION
:
207 case CDERR_LOCKRESFAILURE
:
209 case CDERR_NOTEMPLATE
:
211 case CDERR_LOADRESFAILURE
:
213 case CDERR_STRUCTSIZE
:
215 case CDERR_LOADSTRFAILURE
:
217 case FNERR_BUFFERTOOSMALL
:
219 case CDERR_MEMALLOCFAILURE
:
221 case FNERR_INVALIDFILENAME
:
223 case CDERR_MEMLOCKFAILURE
:
225 case FNERR_SUBCLASSFAILURE
:
233 #define MAX_CUSTOM_FILTER_SIZE 50
234 TCHAR CustomFilterBuffer
[MAX_CUSTOM_FILTER_SIZE
];
235 TCHAR FileNameBuffer
[_MAX_PATH
];
236 TCHAR FileTitleBuffer
[_MAX_PATH
];
242 } FILTERPAIR
, *PFILTERPAIR
;
245 BuildFilterStrings(TCHAR
*Filter
, PFILTERPAIR Pairs
, int PairCount
)
250 for(i
= 0; i
< PairCount
; i
++)
252 c
+= LoadString(hInst
, Pairs
[i
].DisplayID
, &Filter
[c
], 255 * sizeof(TCHAR
));
254 c
+= LoadString(hInst
, Pairs
[i
].FilterID
, &Filter
[c
], 255 * sizeof(TCHAR
));
260 static BOOL
InitOpenFileName(HWND hWnd
, OPENFILENAME
* pofn
)
262 FILTERPAIR FilterPairs
[3];
263 static TCHAR Filter
[1024];
265 memset(pofn
, 0, sizeof(OPENFILENAME
));
266 pofn
->lStructSize
= sizeof(OPENFILENAME
);
267 pofn
->hwndOwner
= hWnd
;
268 pofn
->hInstance
= hInst
;
270 /* create filter string */
271 FilterPairs
[0].DisplayID
= IDS_FLT_REGFILES
;
272 FilterPairs
[0].FilterID
= IDS_FLT_REGFILES_FLT
;
273 FilterPairs
[1].DisplayID
= IDS_FLT_REGEDIT4
;
274 FilterPairs
[1].FilterID
= IDS_FLT_REGEDIT4_FLT
;
275 FilterPairs
[2].DisplayID
= IDS_FLT_ALLFILES
;
276 FilterPairs
[2].FilterID
= IDS_FLT_ALLFILES_FLT
;
277 BuildFilterStrings(Filter
, FilterPairs
, sizeof(FilterPairs
) / sizeof(FILTERPAIR
));
279 pofn
->lpstrFilter
= Filter
;
280 pofn
->lpstrCustomFilter
= CustomFilterBuffer
;
281 pofn
->nMaxCustFilter
= MAX_CUSTOM_FILTER_SIZE
;
282 pofn
->nFilterIndex
= 0;
283 pofn
->lpstrFile
= FileNameBuffer
;
284 pofn
->nMaxFile
= _MAX_PATH
;
285 pofn
->lpstrFileTitle
= FileTitleBuffer
;
286 pofn
->nMaxFileTitle
= _MAX_PATH
;
287 /* pofn->lpstrInitialDir = _T("");*/
288 /* pofn->lpstrTitle = _T("Import Registry File");*/
289 /* pofn->Flags = OFN_ENABLETEMPLATE + OFN_EXPLORER + OFN_ENABLESIZING;*/
290 pofn
->Flags
= OFN_HIDEREADONLY
;
291 /* pofn->nFileOffset = ;*/
292 /* pofn->nFileExtension = ;*/
293 /* pofn->lpstrDefExt = _T("");*/
294 /* pofn->lCustData = ;*/
295 /* pofn->lpfnHook = ImportRegistryFile_OFNHookProc;*/
296 /* pofn->lpTemplateName = _T("ID_DLG_IMPORT_REGFILE");*/
297 /* pofn->lpTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);*/
298 /* pofn->FlagsEx = ;*/
302 static BOOL
ImportRegistryFile(HWND hWnd
)
307 InitOpenFileName(hWnd
, &ofn
);
308 LoadString(hInst
, IDS_IMPORT_REG_FILE
, Caption
, sizeof(Caption
)/sizeof(TCHAR
));
309 ofn
.lpstrTitle
= Caption
;
310 /* ofn.lCustData = ;*/
311 if (GetOpenFileName(&ofn
)) {
312 /* FIXME - convert to ascii */
313 if (!import_registry_file(ofn
.lpstrFile
)) {
314 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
318 get_file_name(&s
, filename
, MAX_PATH
);
320 printf("No file name is specified\n%s", usage
);
324 while (filename
[0]) {
325 if (!import_registry_file(filename
)) {
327 printf("Can't open file \"%s\"\n", filename
);
331 get_file_name(&s
, filename
, MAX_PATH
);
336 CheckCommDlgError(hWnd
);
342 static UINT_PTR CALLBACK
ExportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
345 HWND hwndExportBranch
;
346 HWND hwndExportBranchText
;
347 UINT_PTR iResult
= 0;
349 LPTSTR pszSelectedKey
;
350 OFNOTIFY
*pOfnNotify
;
352 UNREFERENCED_PARAMETER(wParam
);
356 pOfn
= (OPENFILENAME
*) lParam
;
357 pszSelectedKey
= (LPTSTR
) pOfn
->lCustData
;
359 hwndExportAll
= GetDlgItem(hdlg
, IDC_EXPORT_ALL
);
361 SendMessage(hwndExportAll
, BM_SETCHECK
, pszSelectedKey
[0] ? BST_UNCHECKED
: BST_CHECKED
, 0);
363 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
364 if (hwndExportBranch
)
365 SendMessage(hwndExportBranch
, BM_SETCHECK
, pszSelectedKey
[0] ? BST_CHECKED
: BST_UNCHECKED
, 0);
367 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
368 if (hwndExportBranchText
)
369 SetWindowText(hwndExportBranchText
, pszSelectedKey
);
373 if (((NMHDR
*) lParam
)->code
== CDN_FILEOK
)
375 pOfnNotify
= (OFNOTIFY
*) lParam
;
376 pszSelectedKey
= (LPTSTR
) pOfnNotify
->lpOFN
->lCustData
;
378 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
379 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
380 if (hwndExportBranch
&& hwndExportBranchText
381 && (SendMessage(hwndExportBranch
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
383 GetWindowText(hwndExportBranchText
, pszSelectedKey
, _MAX_PATH
);
387 pszSelectedKey
[0] = '\0';
395 BOOL
ExportRegistryFile(HWND hWnd
)
398 TCHAR ExportKeyPath
[_MAX_PATH
];
403 /* Figure out which key path we are exporting */
404 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
405 RegKeyGetName(ExportKeyPath
, sizeof(ExportKeyPath
) / sizeof(ExportKeyPath
[0]),
406 hKeyRoot
, pszKeyPath
);
408 InitOpenFileName(hWnd
, &ofn
);
409 LoadString(hInst
, IDS_EXPORT_REG_FILE
, Caption
, sizeof(Caption
)/sizeof(TCHAR
));
410 ofn
.lpstrTitle
= Caption
;
411 ofn
.lCustData
= (LPARAM
) ExportKeyPath
;
412 ofn
.Flags
= OFN_ENABLETEMPLATE
| OFN_EXPLORER
| OFN_ENABLEHOOK
;
413 ofn
.lpfnHook
= ExportRegistryFile_OFNHookProc
;
414 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_EXPORTRANGE
);
415 if (GetSaveFileName(&ofn
)) {
417 LPSTR pszExportKeyPath
;
419 CHAR buffer
[_MAX_PATH
];
421 WideCharToMultiByte(CP_ACP
, 0, ExportKeyPath
, -1, buffer
, sizeof(buffer
), NULL
, NULL
);
422 pszExportKeyPath
= buffer
;
424 pszExportKeyPath
= ExportKeyPath
;
427 result
= export_registry_key(ofn
.lpstrFile
, pszExportKeyPath
);
429 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
433 TCHAR filename
[MAX_PATH
];
435 get_file_name(&s
, filename
, MAX_PATH
);
437 printf("No file name is specified\n%s", usage
);
442 TCHAR reg_key_name
[KEY_MAX_LEN
];
443 get_file_name(&s
, reg_key_name
, KEY_MAX_LEN
);
444 export_registry_key((CHAR
)filename
, reg_key_name
);
446 export_registry_key(filename
, NULL
);
451 CheckCommDlgError(hWnd
);
456 BOOL
PrintRegistryHive(HWND hWnd
, LPTSTR path
)
460 UNREFERENCED_PARAMETER(path
);
462 ZeroMemory(&pd
, sizeof(PRINTDLG
));
463 pd
.lStructSize
= sizeof(PRINTDLG
);
465 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
466 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
467 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
469 pd
.nFromPage
= 0xFFFF;
472 pd
.nMaxPage
= 0xFFFF;
474 /* GDI calls to render output. */
475 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
481 hResult
= PrintDlgEx(&pd
);
482 if (hResult
== S_OK
) {
483 switch (pd
.dwResultAction
) {
484 case PD_RESULT_APPLY
:
485 /*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. */
487 case PD_RESULT_CANCEL
:
488 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
490 case PD_RESULT_PRINT
:
491 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
499 /*Insufficient memory. */
502 /* One or more arguments are invalid. */
505 /*Invalid pointer. */
511 /*Unspecified error. */
522 static void ChooseFavorite(LPCTSTR pszFavorite
)
525 TCHAR szFavoritePath
[512];
526 DWORD cbData
, dwType
;
528 if (RegOpenKeyEx(HKEY_CURRENT_USER
, s_szFavoritesRegKey
, 0, KEY_QUERY_VALUE
, &hKey
) != ERROR_SUCCESS
)
531 cbData
= (sizeof(szFavoritePath
) / sizeof(szFavoritePath
[0])) - 1;
532 memset(szFavoritePath
, 0, sizeof(szFavoritePath
));
533 if (RegQueryValueEx(hKey
, pszFavorite
, NULL
, &dwType
, (LPBYTE
) szFavoritePath
, &cbData
) != ERROR_SUCCESS
)
536 if (dwType
== REG_SZ
)
537 SelectNode(g_pChildWnd
->hTreeWnd
, szFavoritePath
);
544 BOOL
CopyKeyName(HWND hWnd
, HKEY hRootKey
, LPCTSTR keyName
)
546 BOOL bClipboardOpened
= FALSE
;
547 BOOL bSuccess
= FALSE
;
552 if (!OpenClipboard(hWnd
))
554 bClipboardOpened
= TRUE
;
556 if (!EmptyClipboard())
559 if (!RegKeyGetName(szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0]), hRootKey
, keyName
))
562 hGlobal
= GlobalAlloc(GMEM_MOVEABLE
, (_tcslen(szBuffer
) + 1) * sizeof(TCHAR
));
566 s
= GlobalLock(hGlobal
);
567 _tcscpy(s
, szBuffer
);
568 GlobalUnlock(hGlobal
);
571 SetClipboardData(CF_UNICODETEXT
, hGlobal
);
573 SetClipboardData(CF_TEXT
, hGlobal
);
578 if (bClipboardOpened
)
583 static BOOL
CreateNewValue(HKEY hRootKey
, LPCTSTR pszKeyPath
, DWORD dwType
)
585 TCHAR szNewValueFormat
[128];
586 TCHAR szNewValue
[128];
589 DWORD dwExistingType
, cbData
;
594 if (RegOpenKey(hRootKey
, pszKeyPath
, &hKey
) != ERROR_SUCCESS
)
597 LoadString(hInst
, IDS_NEW_VALUE
, szNewValueFormat
, sizeof(szNewValueFormat
)
598 / sizeof(szNewValueFormat
[0]));
602 _sntprintf(szNewValue
, sizeof(szNewValue
) / sizeof(szNewValue
[0]),
603 szNewValueFormat
, iIndex
++);
605 cbData
= sizeof(data
);
606 lResult
= RegQueryValueEx(hKey
, szNewValue
, NULL
, &dwExistingType
, data
, &cbData
);
608 while(lResult
== ERROR_SUCCESS
);
612 cbData
= sizeof(DWORD
);
616 cbData
= sizeof(TCHAR
);
619 cbData
= sizeof(TCHAR
) * 2;
622 cbData
= sizeof(DWORD
) * 2;
628 memset(data
, 0, cbData
);
629 lResult
= RegSetValueEx(hKey
, szNewValue
, 0, dwType
, data
, cbData
);
630 if (lResult
!= ERROR_SUCCESS
)
633 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
635 /* locate the newly added value, and get ready to rename it */
636 memset(&lvfi
, 0, sizeof(lvfi
));
637 lvfi
.flags
= LVFI_STRING
;
638 lvfi
.psz
= szNewValue
;
639 iIndex
= ListView_FindItem(g_pChildWnd
->hListWnd
, -1, &lvfi
);
641 (void)ListView_EditLabel(g_pChildWnd
->hListWnd
, iIndex
);
647 InitializeRemoteRegistryPicker(OUT IDsObjectPicker
**pDsObjectPicker
)
651 *pDsObjectPicker
= NULL
;
653 hRet
= CoCreateInstance(&CLSID_DsObjectPicker
,
655 CLSCTX_INPROC_SERVER
,
656 &IID_IDsObjectPicker
,
657 (LPVOID
*)pDsObjectPicker
);
660 DSOP_INIT_INFO InitInfo
;
661 static DSOP_SCOPE_INIT_INFO Scopes
[] =
664 sizeof(DSOP_SCOPE_INIT_INFO
),
665 DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE
| DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE
|
666 DSOP_SCOPE_TYPE_GLOBAL_CATALOG
| DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN
|
667 DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN
| DSOP_SCOPE_TYPE_WORKGROUP
|
668 DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
| DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN
,
672 DSOP_FILTER_COMPUTERS
,
676 DSOP_DOWNLEVEL_FILTER_COMPUTERS
684 InitInfo
.cbSize
= sizeof(InitInfo
);
685 InitInfo
.pwzTargetComputer
= NULL
;
686 InitInfo
.cDsScopeInfos
= sizeof(Scopes
) / sizeof(Scopes
[0]);
687 InitInfo
.aDsScopeInfos
= Scopes
;
688 InitInfo
.flOptions
= 0;
689 InitInfo
.cAttributesToFetch
= 0;
690 InitInfo
.apwzAttributeNames
= NULL
;
692 hRet
= (*pDsObjectPicker
)->lpVtbl
->Initialize(*pDsObjectPicker
,
697 /* delete the object picker in case initialization failed! */
698 (*pDsObjectPicker
)->lpVtbl
->Release(*pDsObjectPicker
);
706 InvokeRemoteRegistryPickerDialog(IN IDsObjectPicker
*pDsObjectPicker
,
707 IN HWND hwndParent OPTIONAL
,
711 IDataObject
*pdo
= NULL
;
714 hRet
= pDsObjectPicker
->lpVtbl
->InvokeDialog(pDsObjectPicker
,
722 fe
.cfFormat
= (CLIPFORMAT
) RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST
);
724 fe
.dwAspect
= DVASPECT_CONTENT
;
726 fe
.tymed
= TYMED_HGLOBAL
;
728 hRet
= pdo
->lpVtbl
->GetData(pdo
,
733 PDS_SELECTION_LIST SelectionList
= (PDS_SELECTION_LIST
)GlobalLock(stm
.hGlobal
);
734 if (SelectionList
!= NULL
)
736 if (SelectionList
->cItems
== 1)
738 size_t nlen
= wcslen(SelectionList
->aDsSelection
[0].pwzName
);
745 SelectionList
->aDsSelection
[0].pwzName
,
746 nlen
* sizeof(WCHAR
));
748 WideCharToMultiByte(CP_ACP
,
750 SelectionList
->aDsSelection
[0].pwzName
,
757 lpBuffer
[nlen
] = L
'\0';
760 GlobalUnlock(stm
.hGlobal
);
763 ReleaseStgMedium(&stm
);
766 pdo
->lpVtbl
->Release(pdo
);
773 FreeObjectPicker(IN IDsObjectPicker
*pDsObjectPicker
)
775 pDsObjectPicker
->lpVtbl
->Release(pDsObjectPicker
);
778 /*******************************************************************************
780 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
782 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
785 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
787 HKEY hKeyRoot
= 0, hKey
= 0;
791 REGSAM regsam
= KEY_READ
;
795 UNREFERENCED_PARAMETER(lParam
);
796 UNREFERENCED_PARAMETER(message
);
798 switch (LOWORD(wParam
)) {
799 case ID_REGISTRY_IMPORTREGISTRYFILE
:
800 ImportRegistryFile(hWnd
);
802 case ID_REGISTRY_EXPORTREGISTRYFILE
:
803 ExportRegistryFile(hWnd
);
805 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
807 IDsObjectPicker
*ObjectPicker
;
808 TCHAR szComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
811 hRet
= CoInitialize(NULL
);
814 hRet
= InitializeRemoteRegistryPicker(&ObjectPicker
);
817 hRet
= InvokeRemoteRegistryPickerDialog(ObjectPicker
,
820 sizeof(szComputerName
) / sizeof(szComputerName
[0]));
823 /* FIXME - connect to the registry */
826 FreeObjectPicker(ObjectPicker
);
834 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
836 case ID_REGISTRY_PRINT
:
837 PrintRegistryHive(hWnd
, _T(""));
839 case ID_REGISTRY_EXIT
:
842 case ID_VIEW_STATUSBAR
:
843 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
845 case ID_HELP_HELPTOPICS
:
846 WinHelp(hWnd
, _T("regedit"), HELP_FINDER
, 0);
855 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
856 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
857 pt
.y
= (rt
.bottom
/ 2);
859 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
))
861 SetCursorPos(pts
.x
, pts
.y
);
862 SetCursor(LoadCursor(0, IDC_SIZEWE
));
863 SendMessage(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
869 case ID_EDIT_MODIFY_BIN
:
875 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
876 valueName
= GetValueName(g_pChildWnd
->hListWnd
, -1);
878 lRet
= RegOpenKeyEx(hKeyRoot
, keyPath
, 0, regsam
, &hKey
);
879 if (lRet
!= ERROR_SUCCESS
) hKey
= 0;
882 switch (LOWORD(wParam
)) {
884 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, FALSE
))
885 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
887 case ID_EDIT_MODIFY_BIN
:
888 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, TRUE
))
889 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
892 if(ListView_GetSelectedCount(g_pChildWnd
->hListWnd
) == 1)
894 item
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_SELECTED
);
897 (void)ListView_EditLabel(g_pChildWnd
->hListWnd
, item
);
903 if (GetFocus() == g_pChildWnd
->hListWnd
)
905 UINT nSelected
= ListView_GetSelectedCount(g_pChildWnd
->hListWnd
);
908 TCHAR msg
[128], caption
[128];
909 LoadString(hInst
, IDS_QUERY_DELETE_CONFIRM
, caption
, sizeof(caption
)/sizeof(TCHAR
));
910 LoadString(hInst
, (nSelected
== 1 ? IDS_QUERY_DELETE_ONE
: IDS_QUERY_DELETE_MORE
), msg
, sizeof(msg
)/sizeof(TCHAR
));
911 if(MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONQUESTION
| MB_YESNO
) == IDYES
)
917 while((ni
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, item
, LVNI_SELECTED
)) > -1)
919 valueName
= GetValueName(g_pChildWnd
->hListWnd
, item
);
920 if(RegDeleteValue(hKey
, valueName
) != ERROR_SUCCESS
)
927 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
930 LoadString(hInst
, IDS_ERR_DELVAL_CAPTION
, caption
, sizeof(caption
)/sizeof(TCHAR
));
931 LoadString(hInst
, IDS_ERR_DELETEVALUE
, msg
, sizeof(msg
)/sizeof(TCHAR
));
932 MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONSTOP
);
937 if (GetFocus() == g_pChildWnd
->hTreeWnd
)
939 if (keyPath
== 0 || *keyPath
== 0)
941 MessageBeep(MB_ICONHAND
);
943 if (DeleteKey(hWnd
, hKeyRoot
, keyPath
))
944 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
947 case ID_EDIT_NEW_STRINGVALUE
:
948 CreateNewValue(hKeyRoot
, keyPath
, REG_SZ
);
950 case ID_EDIT_NEW_BINARYVALUE
:
951 CreateNewValue(hKeyRoot
, keyPath
, REG_BINARY
);
953 case ID_EDIT_NEW_DWORDVALUE
:
954 CreateNewValue(hKeyRoot
, keyPath
, REG_DWORD
);
956 case ID_EDIT_NEW_MULTISTRINGVALUE
:
957 CreateNewValue(hKeyRoot
, keyPath
, REG_MULTI_SZ
);
959 case ID_EDIT_NEW_EXPANDABLESTRINGVALUE
:
960 CreateNewValue(hKeyRoot
, keyPath
, REG_EXPAND_SZ
);
967 case ID_EDIT_FINDNEXT
:
970 case ID_EDIT_COPYKEYNAME
:
971 CopyKeyName(hWnd
, hKeyRoot
, keyPath
);
973 case ID_EDIT_PERMISSIONS
:
974 RegKeyEditPermissions(hWnd
, hKeyRoot
, NULL
, keyPath
);
976 case ID_REGISTRY_PRINTERSETUP
:
979 /*PAGESETUPDLG psd;*/
980 /*PageSetupDlg(&psd);*/
982 case ID_REGISTRY_OPENLOCAL
:
985 case ID_VIEW_REFRESH
:
986 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
987 /*RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); */
989 /*case ID_OPTIONS_TOOLBAR:*/
990 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
992 case ID_EDIT_NEW_KEY
:
993 CreateNewKey(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
));
996 if ((LOWORD(wParam
) >= ID_FAVORITES_MIN
) && (LOWORD(wParam
) <= ID_FAVORITES_MAX
))
1000 TCHAR szFavorite
[512];
1002 hMenu
= GetSubMenu(GetMenu(hWnd
), FAVORITES_MENU_POSITION
);
1004 memset(&mii
, 0, sizeof(mii
));
1005 mii
.cbSize
= sizeof(mii
);
1006 mii
.fMask
= MIIM_TYPE
;
1007 mii
.fType
= MFT_STRING
;
1008 mii
.dwTypeData
= szFavorite
;
1009 mii
.cch
= sizeof(szFavorite
) / sizeof(szFavorite
[0]);
1011 if (GetMenuItemInfo(hMenu
, LOWORD(wParam
) - ID_FAVORITES_MIN
, TRUE
, &mii
))
1013 ChooseFavorite(szFavorite
);
1028 /********************************************************************************
1030 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
1032 * PURPOSE: Processes messages for the main frame window.
1034 * WM_COMMAND - process the application menu
1035 * WM_DESTROY - post a quit message and return
1039 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1043 CreateWindowEx(0, szChildClass
, NULL
, WS_CHILD
| WS_VISIBLE
,
1044 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1045 hWnd
, (HMENU
)0, hInst
, 0);
1048 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
1049 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1053 SetFocus(g_pChildWnd
->hWnd
);
1056 resize_frame_client(hWnd
);
1063 case WM_ENTERMENULOOP
:
1064 OnEnterMenuLoop(hWnd
);
1066 case WM_EXITMENULOOP
:
1067 OnExitMenuLoop(hWnd
);
1070 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
1073 WinHelp(hWnd
, _T("regedit"), HELP_QUIT
, 0);
1076 return DefWindowProc(hWnd
, message
, wParam
, lParam
);