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
36 /********************************************************************************
37 * Global and Local Variables:
40 #define FAVORITES_MENU_POSITION 3
42 static TCHAR s_szFavoritesRegKey
[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit\\Favorites");
44 static BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
46 /*******************************************************************************
47 * Local module support methods
50 static void resize_frame_rect(HWND hWnd
, PRECT prect
)
54 if (IsWindowVisible(hToolBar)) {
55 SendMessage(hToolBar, WM_SIZE, 0, 0);
56 GetClientRect(hToolBar, &rt);
57 prect->top = rt.bottom+3;
58 prect->bottom -= rt.bottom+3;
61 if (IsWindowVisible(hStatusBar
)) {
62 SetupStatusBar(hWnd
, TRUE
);
63 GetClientRect(hStatusBar
, &rt
);
64 prect
->bottom
-= rt
.bottom
;
66 MoveWindow(g_pChildWnd
->hWnd
, prect
->left
, prect
->top
, prect
->right
, prect
->bottom
, TRUE
);
69 static void resize_frame_client(HWND hWnd
)
73 GetClientRect(hWnd
, &rect
);
74 resize_frame_rect(hWnd
, &rect
);
77 /********************************************************************************/
79 static void OnInitMenu(HWND hWnd
)
83 DWORD dwIndex
, cbValueName
, cbValueData
, dwType
;
84 TCHAR szValueName
[256];
85 BYTE abValueData
[256];
86 static int s_nFavoriteMenuSubPos
= -1;
88 BOOL bDisplayedAny
= FALSE
;
90 /* Find Favorites menu and clear it out */
91 hMenu
= GetSubMenu(GetMenu(hWnd
), FAVORITES_MENU_POSITION
);
94 if (s_nFavoriteMenuSubPos
< 0)
96 s_nFavoriteMenuSubPos
= GetMenuItemCount(hMenu
);
100 while(RemoveMenu(hMenu
, s_nFavoriteMenuSubPos
, MF_BYPOSITION
))
104 lResult
= RegOpenKey(HKEY_CURRENT_USER
, s_szFavoritesRegKey
, &hKey
);
105 if (lResult
!= ERROR_SUCCESS
)
111 cbValueName
= sizeof(szValueName
) / sizeof(szValueName
[0]);
112 cbValueData
= sizeof(abValueData
);
113 lResult
= RegEnumValue(hKey
, dwIndex
, szValueName
, &cbValueName
, NULL
, &dwType
, abValueData
, &cbValueData
);
114 if ((lResult
== ERROR_SUCCESS
) && (dwType
== REG_SZ
))
118 AppendMenu(hMenu
, MF_SEPARATOR
, 0, NULL
);
119 bDisplayedAny
= TRUE
;
121 AppendMenu(hMenu
, 0, ID_FAVORITES_MIN
+ GetMenuItemCount(hMenu
), szValueName
);
125 while(lResult
== ERROR_SUCCESS
);
132 static void OnEnterMenuLoop(HWND hWnd
)
136 /* Update the status bar pane sizes */
138 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
140 SendMessage(hStatusBar
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)_T(""));
143 static void OnExitMenuLoop(HWND hWnd
)
146 /* Update the status bar pane sizes*/
147 SetupStatusBar(hWnd
, TRUE
);
151 static void OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
155 _tcscpy(str
, _T(""));
156 if (nFlags
& MF_POPUP
) {
157 if (hSysMenu
!= GetMenu(hWnd
)) {
158 if (nItemID
== 2) nItemID
= 5;
161 if (LoadString(hInst
, nItemID
, str
, 100)) {
162 /* load appropriate string*/
164 /* first newline terminates actual string*/
165 lpsz
= _tcschr(lpsz
, '\n');
169 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)str
);
172 void SetupStatusBar(HWND hWnd
, BOOL bResize
)
176 GetClientRect(hWnd
, &rc
);
180 SendMessage(hStatusBar
, WM_SIZE
, 0, 0);
181 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
184 void UpdateStatusBar(void)
189 size
= sizeof(text
)/sizeof(TCHAR
);
190 GetComputerName(text
, &size
);
191 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)text
);
194 static void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
196 BOOL vis
= IsWindowVisible(hchild
);
197 HMENU hMenuView
= GetSubMenu(hMenuFrame
, ID_VIEW_MENU
);
199 CheckMenuItem(hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
200 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
201 resize_frame_client(hWnd
);
204 static BOOL
CheckCommDlgError(HWND hWnd
)
206 DWORD dwErrorCode
= CommDlgExtendedError();
207 switch (dwErrorCode
) {
208 case CDERR_DIALOGFAILURE
:
210 case CDERR_FINDRESFAILURE
:
212 case CDERR_NOHINSTANCE
:
214 case CDERR_INITIALIZATION
:
218 case CDERR_LOCKRESFAILURE
:
220 case CDERR_NOTEMPLATE
:
222 case CDERR_LOADRESFAILURE
:
224 case CDERR_STRUCTSIZE
:
226 case CDERR_LOADSTRFAILURE
:
228 case FNERR_BUFFERTOOSMALL
:
230 case CDERR_MEMALLOCFAILURE
:
232 case FNERR_INVALIDFILENAME
:
234 case CDERR_MEMLOCKFAILURE
:
236 case FNERR_SUBCLASSFAILURE
:
244 #define MAX_CUSTOM_FILTER_SIZE 50
245 TCHAR CustomFilterBuffer
[MAX_CUSTOM_FILTER_SIZE
];
246 TCHAR FileNameBuffer
[_MAX_PATH
];
247 TCHAR FileTitleBuffer
[_MAX_PATH
];
253 } FILTERPAIR
, *PFILTERPAIR
;
256 BuildFilterStrings(TCHAR
*Filter
, PFILTERPAIR Pairs
, int PairCount
)
261 for(i
= 0; i
< PairCount
; i
++)
263 c
+= LoadString(hInst
, Pairs
[i
].DisplayID
, &Filter
[c
], 255 * sizeof(TCHAR
));
265 c
+= LoadString(hInst
, Pairs
[i
].FilterID
, &Filter
[c
], 255 * sizeof(TCHAR
));
271 static BOOL
InitOpenFileName(HWND hWnd
, OPENFILENAME
* pofn
)
273 FILTERPAIR FilterPairs
[3];
274 static TCHAR Filter
[1024];
276 memset(pofn
, 0, sizeof(OPENFILENAME
));
277 pofn
->lStructSize
= sizeof(OPENFILENAME
);
278 pofn
->hwndOwner
= hWnd
;
279 pofn
->hInstance
= hInst
;
281 /* create filter string */
282 FilterPairs
[0].DisplayID
= IDS_FLT_REGFILES
;
283 FilterPairs
[0].FilterID
= IDS_FLT_REGFILES_FLT
;
284 FilterPairs
[1].DisplayID
= IDS_FLT_REGEDIT4
;
285 FilterPairs
[1].FilterID
= IDS_FLT_REGEDIT4_FLT
;
286 FilterPairs
[2].DisplayID
= IDS_FLT_ALLFILES
;
287 FilterPairs
[2].FilterID
= IDS_FLT_ALLFILES_FLT
;
288 BuildFilterStrings(Filter
, FilterPairs
, sizeof(FilterPairs
) / sizeof(FILTERPAIR
));
290 pofn
->lpstrFilter
= Filter
;
291 pofn
->lpstrCustomFilter
= CustomFilterBuffer
;
292 pofn
->nMaxCustFilter
= MAX_CUSTOM_FILTER_SIZE
;
293 pofn
->nFilterIndex
= 0;
294 pofn
->lpstrFile
= FileNameBuffer
;
295 pofn
->nMaxFile
= _MAX_PATH
;
296 pofn
->lpstrFileTitle
= FileTitleBuffer
;
297 pofn
->nMaxFileTitle
= _MAX_PATH
;
298 /* pofn->lpstrInitialDir = _T("");*/
299 /* pofn->lpstrTitle = _T("Import Registry File");*/
300 /* pofn->Flags = OFN_ENABLETEMPLATE + OFN_EXPLORER + OFN_ENABLESIZING;*/
301 pofn
->Flags
= OFN_HIDEREADONLY
;
302 /* pofn->nFileOffset = ;*/
303 /* pofn->nFileExtension = ;*/
304 /* pofn->lpstrDefExt = _T("");*/
305 /* pofn->lCustData = ;*/
306 /* pofn->lpfnHook = ImportRegistryFile_OFNHookProc;*/
307 /* pofn->lpTemplateName = _T("ID_DLG_IMPORT_REGFILE");*/
308 /* pofn->lpTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);*/
309 /* pofn->FlagsEx = ;*/
313 static BOOL
ImportRegistryFile(HWND hWnd
)
318 InitOpenFileName(hWnd
, &ofn
);
319 LoadString(hInst
, IDS_IMPORT_REG_FILE
, Caption
, sizeof(Caption
)/sizeof(TCHAR
));
320 ofn
.lpstrTitle
= Caption
;
321 /* ofn.lCustData = ;*/
322 if (GetOpenFileName(&ofn
)) {
323 /* FIXME - convert to ascii */
324 if (!import_registry_file(ofn
.lpstrFile
)) {
325 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
329 get_file_name(&s
, filename
, MAX_PATH
);
331 printf("No file name is specified\n%s", usage
);
335 while (filename
[0]) {
336 if (!import_registry_file(filename
)) {
338 printf("Can't open file \"%s\"\n", filename
);
342 get_file_name(&s
, filename
, MAX_PATH
);
347 CheckCommDlgError(hWnd
);
353 static UINT_PTR CALLBACK
ExportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
356 HWND hwndExportBranch
;
357 HWND hwndExportBranchText
;
358 UINT_PTR iResult
= 0;
360 LPTSTR pszSelectedKey
;
361 OFNOTIFY
*pOfnNotify
;
365 pOfn
= (OPENFILENAME
*) lParam
;
366 pszSelectedKey
= (LPTSTR
) pOfn
->lCustData
;
368 hwndExportAll
= GetDlgItem(hdlg
, IDC_EXPORT_ALL
);
370 SendMessage(hwndExportAll
, BM_SETCHECK
, pszSelectedKey
[0] ? BST_UNCHECKED
: BST_CHECKED
, 0);
372 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
373 if (hwndExportBranch
)
374 SendMessage(hwndExportBranch
, BM_SETCHECK
, pszSelectedKey
[0] ? BST_CHECKED
: BST_UNCHECKED
, 0);
376 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
377 if (hwndExportBranchText
)
378 SetWindowText(hwndExportBranchText
, pszSelectedKey
);
382 if (((NMHDR
*) lParam
)->code
== CDN_FILEOK
)
384 pOfnNotify
= (OFNOTIFY
*) lParam
;
385 pszSelectedKey
= (LPTSTR
) pOfnNotify
->lpOFN
->lCustData
;
387 hwndExportBranch
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH
);
388 hwndExportBranchText
= GetDlgItem(hdlg
, IDC_EXPORT_BRANCH_TEXT
);
389 if (hwndExportBranch
&& hwndExportBranchText
390 && (SendMessage(hwndExportBranch
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
392 GetWindowText(hwndExportBranchText
, pszSelectedKey
, _MAX_PATH
);
396 pszSelectedKey
[0] = '\0';
404 BOOL
ExportRegistryFile(HWND hWnd
)
407 TCHAR ExportKeyPath
[_MAX_PATH
];
412 /* Figure out which key path we are exporting */
413 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
414 RegKeyGetName(ExportKeyPath
, sizeof(ExportKeyPath
) / sizeof(ExportKeyPath
[0]),
415 hKeyRoot
, pszKeyPath
);
417 InitOpenFileName(hWnd
, &ofn
);
418 LoadString(hInst
, IDS_EXPORT_REG_FILE
, Caption
, sizeof(Caption
)/sizeof(TCHAR
));
419 ofn
.lpstrTitle
= Caption
;
420 ofn
.lCustData
= (LPARAM
) ExportKeyPath
;
421 ofn
.Flags
= OFN_ENABLETEMPLATE
| OFN_EXPLORER
| OFN_ENABLEHOOK
;
422 ofn
.lpfnHook
= ExportRegistryFile_OFNHookProc
;
423 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_EXPORTRANGE
);
424 if (GetSaveFileName(&ofn
)) {
426 LPSTR pszExportKeyPath
;
428 CHAR buffer
[_MAX_PATH
];
430 WideCharToMultiByte(CP_ACP
, 0, ExportKeyPath
, -1, buffer
, sizeof(buffer
), NULL
, NULL
);
431 pszExportKeyPath
= buffer
;
433 pszExportKeyPath
= ExportKeyPath
;
436 result
= export_registry_key(ofn
.lpstrFile
, pszExportKeyPath
);
438 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
442 TCHAR filename
[MAX_PATH
];
444 get_file_name(&s
, filename
, MAX_PATH
);
446 printf("No file name is specified\n%s", usage
);
451 TCHAR reg_key_name
[KEY_MAX_LEN
];
452 get_file_name(&s
, reg_key_name
, KEY_MAX_LEN
);
453 export_registry_key((CHAR
)filename
, reg_key_name
);
455 export_registry_key(filename
, NULL
);
460 CheckCommDlgError(hWnd
);
465 BOOL
PrintRegistryHive(HWND hWnd
, LPTSTR path
)
470 ZeroMemory(&pd
, sizeof(PRINTDLG
));
471 pd
.lStructSize
= sizeof(PRINTDLG
);
473 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
474 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
475 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
477 pd
.nFromPage
= 0xFFFF;
480 pd
.nMaxPage
= 0xFFFF;
482 /* GDI calls to render output. */
483 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
489 hResult
= PrintDlgEx(&pd
);
490 if (hResult
== S_OK
) {
491 switch (pd
.dwResultAction
) {
492 case PD_RESULT_APPLY
:
493 /*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. */
495 case PD_RESULT_CANCEL
:
496 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
498 case PD_RESULT_PRINT
:
499 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
507 /*Insufficient memory. */
510 /* One or more arguments are invalid. */
513 /*Invalid pointer. */
519 /*Unspecified error. */
530 static void ChooseFavorite(LPCTSTR pszFavorite
)
533 TCHAR szFavoritePath
[512];
534 DWORD cbData
, dwType
;
536 if (RegOpenKeyEx(HKEY_CURRENT_USER
, s_szFavoritesRegKey
, 0, KEY_QUERY_VALUE
, &hKey
) != ERROR_SUCCESS
)
539 cbData
= (sizeof(szFavoritePath
) / sizeof(szFavoritePath
[0])) - 1;
540 memset(szFavoritePath
, 0, sizeof(szFavoritePath
));
541 if (RegQueryValueEx(hKey
, pszFavorite
, NULL
, &dwType
, (LPBYTE
) szFavoritePath
, &cbData
) != ERROR_SUCCESS
)
544 if (dwType
== REG_SZ
)
545 SelectNode(g_pChildWnd
->hTreeWnd
, szFavoritePath
);
552 BOOL
CopyKeyName(HWND hWnd
, HKEY hRootKey
, LPCTSTR keyName
)
554 BOOL bClipboardOpened
= FALSE
;
555 BOOL bSuccess
= FALSE
;
560 if (!OpenClipboard(hWnd
))
562 bClipboardOpened
= TRUE
;
564 if (!EmptyClipboard())
567 if (!RegKeyGetName(szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0]), hRootKey
, keyName
))
570 hGlobal
= GlobalAlloc(GMEM_MOVEABLE
, (_tcslen(szBuffer
) + 1) * sizeof(TCHAR
));
574 s
= GlobalLock(hGlobal
);
575 _tcscpy(s
, szBuffer
);
576 GlobalUnlock(hGlobal
);
579 SetClipboardData(CF_UNICODETEXT
, hGlobal
);
581 SetClipboardData(CF_TEXT
, hGlobal
);
586 if (bClipboardOpened
)
591 static BOOL
CreateNewValue(HKEY hRootKey
, LPCTSTR pszKeyPath
, DWORD dwType
)
593 TCHAR szNewValueFormat
[128];
594 TCHAR szNewValue
[128];
597 DWORD dwExistingType
, cbData
;
602 if (RegOpenKey(hRootKey
, pszKeyPath
, &hKey
) != ERROR_SUCCESS
)
605 LoadString(hInst
, IDS_NEW_VALUE
, szNewValueFormat
, sizeof(szNewValueFormat
)
606 / sizeof(szNewValueFormat
[0]));
610 _sntprintf(szNewValue
, sizeof(szNewValue
) / sizeof(szNewValue
[0]),
611 szNewValueFormat
, iIndex
++);
613 cbData
= sizeof(data
);
614 lResult
= RegQueryValueEx(hKey
, szNewValue
, NULL
, &dwExistingType
, data
, &cbData
);
616 while(lResult
== ERROR_SUCCESS
);
620 cbData
= sizeof(DWORD
);
624 cbData
= sizeof(TCHAR
);
627 cbData
= sizeof(TCHAR
) * 2;
630 cbData
= sizeof(DWORD
) * 2;
636 memset(data
, 0, cbData
);
637 lResult
= RegSetValueEx(hKey
, szNewValue
, 0, dwType
, data
, cbData
);
638 if (lResult
!= ERROR_SUCCESS
)
641 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, pszKeyPath
);
643 /* locate the newly added value, and get ready to rename it */
644 memset(&lvfi
, 0, sizeof(lvfi
));
645 lvfi
.flags
= LVFI_STRING
;
646 lvfi
.psz
= szNewValue
;
647 iIndex
= ListView_FindItem(g_pChildWnd
->hListWnd
, -1, &lvfi
);
649 ListView_EditLabel(g_pChildWnd
->hListWnd
, iIndex
);
655 InitializeRemoteRegistryPicker(OUT IDsObjectPicker
**pDsObjectPicker
)
659 *pDsObjectPicker
= NULL
;
661 hRet
= CoCreateInstance(&CLSID_DsObjectPicker
,
663 CLSCTX_INPROC_SERVER
,
664 &IID_IDsObjectPicker
,
665 (LPVOID
*)pDsObjectPicker
);
668 DSOP_INIT_INFO InitInfo
;
669 static DSOP_SCOPE_INIT_INFO Scopes
[] =
672 sizeof(DSOP_SCOPE_INIT_INFO
),
673 DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE
| DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE
|
674 DSOP_SCOPE_TYPE_GLOBAL_CATALOG
| DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN
|
675 DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN
| DSOP_SCOPE_TYPE_WORKGROUP
|
676 DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
| DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN
,
680 DSOP_FILTER_COMPUTERS
,
684 DSOP_DOWNLEVEL_FILTER_COMPUTERS
692 InitInfo
.cbSize
= sizeof(InitInfo
);
693 InitInfo
.pwzTargetComputer
= NULL
;
694 InitInfo
.cDsScopeInfos
= sizeof(Scopes
) / sizeof(Scopes
[0]);
695 InitInfo
.aDsScopeInfos
= Scopes
;
696 InitInfo
.flOptions
= 0;
697 InitInfo
.cAttributesToFetch
= 0;
698 InitInfo
.apwzAttributeNames
= NULL
;
700 hRet
= (*pDsObjectPicker
)->lpVtbl
->Initialize(*pDsObjectPicker
,
705 /* delete the object picker in case initialization failed! */
706 (*pDsObjectPicker
)->lpVtbl
->Release(*pDsObjectPicker
);
714 InvokeRemoteRegistryPickerDialog(IN IDsObjectPicker
*pDsObjectPicker
,
715 IN HWND hwndParent OPTIONAL
,
719 IDataObject
*pdo
= NULL
;
722 hRet
= pDsObjectPicker
->lpVtbl
->InvokeDialog(pDsObjectPicker
,
730 fe
.cfFormat
= RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST
);
732 fe
.dwAspect
= DVASPECT_CONTENT
;
734 fe
.tymed
= TYMED_HGLOBAL
;
736 hRet
= pdo
->lpVtbl
->GetData(pdo
,
741 PDS_SELECTION_LIST SelectionList
= (PDS_SELECTION_LIST
)GlobalLock(stm
.hGlobal
);
742 if (SelectionList
!= NULL
)
744 if (SelectionList
->cItems
== 1)
746 UINT nlen
= wcslen(SelectionList
->aDsSelection
[0].pwzName
);
753 SelectionList
->aDsSelection
[0].pwzName
,
754 nlen
* sizeof(WCHAR
));
756 WideCharToMultiByte(CP_ACP
,
758 SelectionList
->aDsSelection
[0].pwzName
,
765 lpBuffer
[nlen
] = L
'\0';
768 GlobalUnlock(stm
.hGlobal
);
771 ReleaseStgMedium(&stm
);
774 pdo
->lpVtbl
->Release(pdo
);
781 FreeObjectPicker(IN IDsObjectPicker
*pDsObjectPicker
)
783 pDsObjectPicker
->lpVtbl
->Release(pDsObjectPicker
);
786 /*******************************************************************************
788 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
790 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
793 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
795 HKEY hKeyRoot
= 0, hKey
= 0;
799 REGSAM regsam
= KEY_READ
;
803 switch (LOWORD(wParam
)) {
804 case ID_REGISTRY_IMPORTREGISTRYFILE
:
805 ImportRegistryFile(hWnd
);
807 case ID_REGISTRY_EXPORTREGISTRYFILE
:
808 ExportRegistryFile(hWnd
);
810 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
812 IDsObjectPicker
*ObjectPicker
;
813 TCHAR szComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
816 hRet
= CoInitialize(NULL
);
819 hRet
= InitializeRemoteRegistryPicker(&ObjectPicker
);
822 hRet
= InvokeRemoteRegistryPickerDialog(ObjectPicker
,
825 sizeof(szComputerName
) / sizeof(szComputerName
[0]));
828 /* FIXME - connect to the registry */
831 FreeObjectPicker(ObjectPicker
);
839 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
841 case ID_REGISTRY_PRINT
:
842 PrintRegistryHive(hWnd
, _T(""));
844 case ID_REGISTRY_EXIT
:
847 case ID_VIEW_STATUSBAR
:
848 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
850 case ID_HELP_HELPTOPICS
:
851 WinHelp(hWnd
, _T("regedit"), HELP_FINDER
, 0);
860 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
861 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
862 pt
.y
= (rt
.bottom
/ 2);
864 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
))
866 SetCursorPos(pts
.x
, pts
.y
);
867 SetCursor(LoadCursor(0, IDC_SIZEWE
));
868 SendMessage(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
874 case ID_EDIT_MODIFY_BIN
:
880 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
881 valueName
= GetValueName(g_pChildWnd
->hListWnd
, -1);
883 lRet
= RegOpenKeyEx(hKeyRoot
, keyPath
, 0, regsam
, &hKey
);
884 if (lRet
!= ERROR_SUCCESS
) hKey
= 0;
887 switch (LOWORD(wParam
)) {
889 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, FALSE
))
890 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
892 case ID_EDIT_MODIFY_BIN
:
893 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
, TRUE
))
894 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
897 if(ListView_GetSelectedCount(g_pChildWnd
->hListWnd
) == 1)
899 item
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_SELECTED
);
902 ListView_EditLabel(g_pChildWnd
->hListWnd
, item
);
908 if (GetFocus() == g_pChildWnd
->hListWnd
)
910 UINT nSelected
= ListView_GetSelectedCount(g_pChildWnd
->hListWnd
);
913 TCHAR msg
[128], caption
[128];
914 LoadString(hInst
, IDS_QUERY_DELETE_CONFIRM
, caption
, sizeof(caption
)/sizeof(TCHAR
));
915 LoadString(hInst
, (nSelected
== 1 ? IDS_QUERY_DELETE_ONE
: IDS_QUERY_DELETE_MORE
), msg
, sizeof(msg
)/sizeof(TCHAR
));
916 if(MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONQUESTION
| MB_YESNO
) == IDYES
)
922 while((ni
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, item
, LVNI_SELECTED
)) > -1)
924 valueName
= GetValueName(g_pChildWnd
->hListWnd
, item
);
925 if(RegDeleteValue(hKey
, valueName
) != ERROR_SUCCESS
)
932 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
935 LoadString(hInst
, IDS_ERR_DELVAL_CAPTION
, caption
, sizeof(caption
)/sizeof(TCHAR
));
936 LoadString(hInst
, IDS_ERR_DELETEVALUE
, msg
, sizeof(msg
)/sizeof(TCHAR
));
937 MessageBox(g_pChildWnd
->hWnd
, msg
, caption
, MB_ICONSTOP
);
942 if (GetFocus() == g_pChildWnd
->hTreeWnd
)
944 if (keyPath
== 0 || *keyPath
== 0)
946 MessageBeep(MB_ICONHAND
);
948 if (DeleteKey(hWnd
, hKeyRoot
, keyPath
))
949 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
952 case ID_EDIT_NEW_STRINGVALUE
:
953 CreateNewValue(hKeyRoot
, keyPath
, REG_SZ
);
955 case ID_EDIT_NEW_BINARYVALUE
:
956 CreateNewValue(hKeyRoot
, keyPath
, REG_BINARY
);
958 case ID_EDIT_NEW_DWORDVALUE
:
959 CreateNewValue(hKeyRoot
, keyPath
, REG_DWORD
);
961 case ID_EDIT_NEW_MULTISTRINGVALUE
:
962 CreateNewValue(hKeyRoot
, keyPath
, REG_MULTI_SZ
);
964 case ID_EDIT_NEW_EXPANDABLESTRINGVALUE
:
965 CreateNewValue(hKeyRoot
, keyPath
, REG_EXPAND_SZ
);
969 case ID_EDIT_COPYKEYNAME
:
970 CopyKeyName(hWnd
, hKeyRoot
, keyPath
);
972 case ID_EDIT_PERMISSIONS
:
973 if(keyPath
!= NULL
&& _tcslen(keyPath
) > 0)
975 RegKeyEditPermissions(hWnd
, hKey
, NULL
, keyPath
);
979 MessageBeep(MB_ICONASTERISK
);
982 case ID_REGISTRY_PRINTERSETUP
:
985 /*PAGESETUPDLG psd;*/
986 /*PageSetupDlg(&psd);*/
988 case ID_REGISTRY_OPENLOCAL
:
991 case ID_VIEW_REFRESH
:
992 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
993 /*RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); */
995 /*case ID_OPTIONS_TOOLBAR:*/
996 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
998 case ID_EDIT_NEW_KEY
:
999 CreateNewKey(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
));
1002 if ((LOWORD(wParam
) >= ID_FAVORITES_MIN
) && (LOWORD(wParam
) <= ID_FAVORITES_MAX
))
1006 TCHAR szFavorite
[512];
1008 hMenu
= GetSubMenu(GetMenu(hWnd
), FAVORITES_MENU_POSITION
);
1010 memset(&mii
, 0, sizeof(mii
));
1011 mii
.cbSize
= sizeof(mii
);
1012 mii
.fMask
= MIIM_TYPE
;
1013 mii
.fType
= MFT_STRING
;
1014 mii
.dwTypeData
= szFavorite
;
1015 mii
.cch
= sizeof(szFavorite
) / sizeof(szFavorite
[0]);
1017 if (GetMenuItemInfo(hMenu
, LOWORD(wParam
) - ID_FAVORITES_MIN
, TRUE
, &mii
))
1019 ChooseFavorite(szFavorite
);
1034 /********************************************************************************
1036 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
1038 * PURPOSE: Processes messages for the main frame window.
1040 * WM_COMMAND - process the application menu
1041 * WM_DESTROY - post a quit message and return
1045 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1049 CreateWindowEx(0, szChildClass
, NULL
, WS_CHILD
| WS_VISIBLE
,
1050 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1051 hWnd
, (HMENU
)0, hInst
, 0);
1054 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
1055 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1059 SetFocus(g_pChildWnd
->hWnd
);
1062 resize_frame_client(hWnd
);
1069 case WM_ENTERMENULOOP
:
1070 OnEnterMenuLoop(hWnd
);
1072 case WM_EXITMENULOOP
:
1073 OnExitMenuLoop(hWnd
);
1076 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
1079 WinHelp(hWnd
, _T("regedit"), HELP_QUIT
, 0);
1082 return DefWindowProc(hWnd
, message
, wParam
, lParam
);