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 St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
34 #include "wine/unicode.h"
36 /********************************************************************************
37 * Global and Local Variables:
40 static WCHAR favoritesKey
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','A','p','p','l','e','t','s','\\','R','e','g','E','d','i','t','\\','F','a','v','o','r','i','t','e','s',0};
41 static BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
42 static WCHAR favoriteName
[128];
43 static WCHAR searchString
[128];
44 static int searchMask
= SEARCH_KEYS
| SEARCH_VALUES
| SEARCH_CONTENT
;
46 static TCHAR FileNameBuffer
[_MAX_PATH
];
47 static TCHAR FileTitleBuffer
[_MAX_PATH
];
48 static TCHAR FilterBuffer
[_MAX_PATH
];
50 /*******************************************************************************
51 * Local module support methods
54 static void resize_frame_rect(HWND hWnd
, PRECT prect
)
58 if (IsWindowVisible(hToolBar)) {
59 SendMessageW(hToolBar, WM_SIZE, 0, 0);
60 GetClientRect(hToolBar, &rt);
61 prect->top = rt.bottom+3;
62 prect->bottom -= rt.bottom+3;
65 if (IsWindowVisible(hStatusBar
)) {
66 SetupStatusBar(hWnd
, TRUE
);
67 GetClientRect(hStatusBar
, &rt
);
68 prect
->bottom
-= rt
.bottom
;
70 MoveWindow(g_pChildWnd
->hWnd
, prect
->left
, prect
->top
, prect
->right
, prect
->bottom
, TRUE
);
73 static void resize_frame_client(HWND hWnd
)
77 GetClientRect(hWnd
, &rect
);
78 resize_frame_rect(hWnd
, &rect
);
81 /********************************************************************************/
83 static void OnEnterMenuLoop(HWND hWnd
)
88 /* Update the status bar pane sizes */
90 SendMessageW(hStatusBar
, SB_SETPARTS
, 1, (long)&nParts
);
92 SendMessageW(hStatusBar
, SB_SETTEXTW
, (WPARAM
)0, (LPARAM
)&empty
);
95 static void OnExitMenuLoop(HWND hWnd
)
98 /* Update the status bar pane sizes*/
99 SetupStatusBar(hWnd
, TRUE
);
103 static void UpdateMenuItems(HMENU hMenu
) {
104 HWND hwndTV
= g_pChildWnd
->hTreeWnd
;
105 BOOL bAllowEdit
= FALSE
;
106 HKEY hRootKey
= NULL
;
108 keyName
= GetItemPath(hwndTV
, TreeView_GetSelection(hwndTV
), &hRootKey
);
109 if (GetFocus() != hwndTV
|| (keyName
&& *keyName
)) { /* can't modify root keys, but allow for their values */
112 EnableMenuItem(hMenu
, ID_EDIT_FIND
, MF_ENABLED
| MF_BYCOMMAND
);
113 EnableMenuItem(hMenu
, ID_EDIT_FINDNEXT
, MF_ENABLED
| MF_BYCOMMAND
);
114 EnableMenuItem(hMenu
, ID_EDIT_MODIFY
, (bAllowEdit
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
115 EnableMenuItem(hMenu
, ID_EDIT_DELETE
, (bAllowEdit
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
116 EnableMenuItem(hMenu
, ID_EDIT_RENAME
, (bAllowEdit
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
117 EnableMenuItem(hMenu
, ID_FAVORITES_ADDTOFAVORITES
, (hRootKey
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
118 EnableMenuItem(hMenu
, ID_FAVORITES_REMOVEFAVORITE
,
119 (GetMenuItemCount(hMenu
)>2 ? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
121 HeapFree(GetProcessHeap(), 0, keyName
);
124 static void OnInitMenuPopup(HWND hWnd
, HMENU hMenu
, short wItem
)
128 while(GetMenuItemCount(hMenu
)>2)
129 DeleteMenu(hMenu
, 2, MF_BYPOSITION
);
130 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
131 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
132 WCHAR namebuf
[KEY_MAX_LEN
];
136 DWORD ksize
, vsize
, type
;
140 vsize
= sizeof(valuebuf
);
141 error
= RegEnumValueW(hKey
, i
, namebuf
, &ksize
, NULL
, &type
, valuebuf
, &vsize
);
142 if (error
!= ERROR_SUCCESS
)
144 if (type
== REG_SZ
) {
146 AppendMenuW(hMenu
, MF_SEPARATOR
, -1, NULL
);
149 AppendMenuW(hMenu
, MF_STRING
, ID_FAVORITE_FIRST
+i
, namebuf
);
152 } while(error
== ERROR_SUCCESS
);
156 UpdateMenuItems(hMenu
);
159 static void OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
164 if (nFlags
& MF_POPUP
) {
165 if (hSysMenu
!= GetMenu(hWnd
)) {
166 if (nItemID
== 2) nItemID
= 5;
169 if (LoadStringW(hInst
, nItemID
, str
, 100)) {
170 /* load appropriate string*/
172 /* first newline terminates actual string*/
173 lpsz
= strchrW(lpsz
, '\n');
177 SendMessageW(hStatusBar
, SB_SETTEXTW
, 0, (LPARAM
)str
);
180 void SetupStatusBar(HWND hWnd
, BOOL bResize
)
184 GetClientRect(hWnd
, &rc
);
188 SendMessageW(hStatusBar
, WM_SIZE
, 0, 0);
189 SendMessageW(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
193 void UpdateStatusBar(void)
195 LPWSTR fullPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, TRUE
);
196 SendMessageW(hStatusBar
, SB_SETTEXTW
, 0, (LPARAM
)fullPath
);
197 HeapFree(GetProcessHeap(), 0, fullPath
);
200 static void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
202 BOOL vis
= IsWindowVisible(hchild
);
203 HMENU hMenuView
= GetSubMenu(hMenuFrame
, ID_VIEW_MENU
);
205 CheckMenuItem(hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
206 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
207 resize_frame_client(hWnd
);
210 static BOOL
CheckCommDlgError(HWND hWnd
)
212 DWORD dwErrorCode
= CommDlgExtendedError();
213 switch (dwErrorCode
) {
214 case CDERR_DIALOGFAILURE
:
216 case CDERR_FINDRESFAILURE
:
218 case CDERR_NOHINSTANCE
:
220 case CDERR_INITIALIZATION
:
224 case CDERR_LOCKRESFAILURE
:
226 case CDERR_NOTEMPLATE
:
228 case CDERR_LOADRESFAILURE
:
230 case CDERR_STRUCTSIZE
:
232 case CDERR_LOADSTRFAILURE
:
234 case FNERR_BUFFERTOOSMALL
:
236 case CDERR_MEMALLOCFAILURE
:
238 case FNERR_INVALIDFILENAME
:
240 case CDERR_MEMLOCKFAILURE
:
242 case FNERR_SUBCLASSFAILURE
:
250 static void ExportRegistryFile_StoreSelection(HWND hdlg
, OPENFILENAME
*pOpenFileName
)
252 if (IsDlgButtonChecked(hdlg
, IDC_EXPORT_SELECTED
))
254 INT len
= SendDlgItemMessage(hdlg
, IDC_EXPORT_PATH
, WM_GETTEXTLENGTH
, 0, 0);
255 pOpenFileName
->lCustData
= (LPARAM
)HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(TCHAR
));
256 SendDlgItemMessage(hdlg
, IDC_EXPORT_PATH
, WM_GETTEXT
, len
+1, pOpenFileName
->lCustData
);
259 pOpenFileName
->lCustData
= (LPARAM
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TCHAR
));
262 static UINT CALLBACK
ExportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
264 static OPENFILENAME
* pOpenFileName
;
269 pOpenFileName
= (OPENFILENAME
*)lParam
;
272 if (LOWORD(wParam
) == IDC_EXPORT_PATH
&& HIWORD(wParam
) == EN_UPDATE
)
273 CheckRadioButton(hdlg
, IDC_EXPORT_ALL
, IDC_EXPORT_SELECTED
, IDC_EXPORT_SELECTED
);
276 pOfNotify
= (OFNOTIFY
*)lParam
;
277 switch (pOfNotify
->hdr
.code
)
281 WCHAR
* pathW
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
282 CHAR
* pathA
= GetMultiByteString(pathW
);
283 SendDlgItemMessage(hdlg
, IDC_EXPORT_PATH
, WM_SETTEXT
, 0, (LPARAM
)pathA
);
284 HeapFree(GetProcessHeap(), 0, pathW
);
285 HeapFree(GetProcessHeap(), 0, pathA
);
286 CheckRadioButton(hdlg
, IDC_EXPORT_ALL
, IDC_EXPORT_SELECTED
, pOpenFileName
->lCustData
? IDC_EXPORT_SELECTED
: IDC_EXPORT_ALL
);
290 ExportRegistryFile_StoreSelection(hdlg
, pOpenFileName
);
301 static BOOL
InitOpenFileName(HWND hWnd
, OPENFILENAME
*pofn
)
303 memset(pofn
, 0, sizeof(OPENFILENAME
));
304 pofn
->lStructSize
= sizeof(OPENFILENAME
);
305 pofn
->hwndOwner
= hWnd
;
306 pofn
->hInstance
= hInst
;
308 if (FilterBuffer
[0] == 0)
309 LoadString(hInst
, IDS_FILEDIALOG_FILTER
, FilterBuffer
, _MAX_PATH
);
310 pofn
->lpstrFilter
= FilterBuffer
;
311 pofn
->nFilterIndex
= 1;
312 pofn
->lpstrFile
= FileNameBuffer
;
313 pofn
->nMaxFile
= _MAX_PATH
;
314 pofn
->lpstrFileTitle
= FileTitleBuffer
;
315 pofn
->nMaxFileTitle
= _MAX_PATH
;
316 pofn
->Flags
= OFN_HIDEREADONLY
;
317 /* some other fields may be set by the caller */
321 static BOOL
import_registry_filename(LPTSTR filename
)
324 FILE* reg_file
= fopen(filename
, "r");
329 Success
= import_registry_file(reg_file
);
331 if(fclose(reg_file
) != 0)
337 static BOOL
ImportRegistryFile(HWND hWnd
)
342 InitOpenFileName(hWnd
, &ofn
);
343 LoadString(hInst
, IDS_FILEDIALOG_IMPORT_TITLE
, title
, COUNT_OF(title
));
344 ofn
.lpstrTitle
= title
;
345 if (GetOpenFileName(&ofn
)) {
346 if (!import_registry_filename(ofn
.lpstrFile
)) {
347 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
351 CheckCommDlgError(hWnd
);
353 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
358 static BOOL
ExportRegistryFile(HWND hWnd
, BOOL export_branch
)
361 TCHAR ExportKeyPath
[_MAX_PATH
];
364 ExportKeyPath
[0] = _T('\0');
365 InitOpenFileName(hWnd
, &ofn
);
366 LoadString(hInst
, IDS_FILEDIALOG_EXPORT_TITLE
, title
, COUNT_OF(title
));
367 ofn
.lpstrTitle
= title
;
368 ofn
.lCustData
= export_branch
;
369 ofn
.Flags
= OFN_ENABLETEMPLATE
| OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
;
370 ofn
.lpfnHook
= ExportRegistryFile_OFNHookProc
;
371 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_EXPORT_TEMPLATE
);
372 if (GetSaveFileName(&ofn
)) {
374 result
= export_registry_key(ofn
.lpstrFile
, (LPTSTR
)ofn
.lCustData
);
376 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
380 CheckCommDlgError(hWnd
);
385 static BOOL
PrintRegistryHive(HWND hWnd
, LPCWSTR path
)
390 ZeroMemory(&pd
, sizeof(PRINTDLG
));
391 pd
.lStructSize
= sizeof(PRINTDLG
);
393 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
394 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
395 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
397 pd
.nFromPage
= 0xFFFF;
400 pd
.nMaxPage
= 0xFFFF;
401 if (PrintDlgW(&pd
)) {
402 /* GDI calls to render output. */
403 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
409 hResult
= PrintDlgExW(&pd
);
410 if (hResult
== S_OK
) {
411 switch (pd
.dwResultAction
) {
412 case PD_RESULT_APPLY
:
413 /*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. */
415 case PD_RESULT_CANCEL
:
416 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
418 case PD_RESULT_PRINT
:
419 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
427 /*Insufficient memory. */
430 /* One or more arguments are invalid. */
433 /*Invalid pointer. */
439 /*Unspecified error. */
450 static BOOL
CopyKeyName(HWND hWnd
, LPCWSTR keyName
)
454 result
= OpenClipboard(hWnd
);
456 result
= EmptyClipboard();
458 int len
= (lstrlenW(keyName
)+1)*sizeof(WCHAR
);
459 HANDLE hClipData
= GlobalAlloc(GHND
, len
);
460 LPVOID pLoc
= GlobalLock(hClipData
);
461 lstrcpyW(pLoc
, keyName
);
462 GlobalUnlock(hClipData
);
463 hClipData
= SetClipboardData(CF_UNICODETEXT
, hClipData
);
466 /* error emptying clipboard*/
467 /* DWORD dwError = GetLastError(); */
470 if (!CloseClipboard()) {
471 /* error closing clipboard*/
472 /* DWORD dwError = GetLastError(); */
476 /* error opening clipboard*/
477 /* DWORD dwError = GetLastError(); */
483 static INT_PTR CALLBACK
find_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
485 HWND hwndValue
= GetDlgItem(hwndDlg
, IDC_VALUE_NAME
);
489 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
490 CheckDlgButton(hwndDlg
, IDC_FIND_KEYS
, searchMask
&SEARCH_KEYS
? BST_CHECKED
: BST_UNCHECKED
);
491 CheckDlgButton(hwndDlg
, IDC_FIND_VALUES
, searchMask
&SEARCH_VALUES
? BST_CHECKED
: BST_UNCHECKED
);
492 CheckDlgButton(hwndDlg
, IDC_FIND_CONTENT
, searchMask
&SEARCH_CONTENT
? BST_CHECKED
: BST_UNCHECKED
);
493 CheckDlgButton(hwndDlg
, IDC_FIND_WHOLE
, searchMask
&SEARCH_WHOLE
? BST_CHECKED
: BST_UNCHECKED
);
494 SendMessageW(hwndValue
, EM_SETLIMITTEXT
, 127, 0);
495 SetWindowTextW(hwndValue
, searchString
);
498 switch(LOWORD(wParam
)) {
500 if (HIWORD(wParam
) == EN_UPDATE
) {
501 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), GetWindowTextLengthW(hwndValue
)>0);
506 if (GetWindowTextLengthW(hwndValue
)>0) {
508 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_KEYS
)) mask
|= SEARCH_KEYS
;
509 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_VALUES
)) mask
|= SEARCH_VALUES
;
510 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_CONTENT
)) mask
|= SEARCH_CONTENT
;
511 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_WHOLE
)) mask
|= SEARCH_WHOLE
;
513 GetWindowTextW(hwndValue
, searchString
, 128);
514 EndDialog(hwndDlg
, IDOK
);
518 EndDialog(hwndDlg
, IDCANCEL
);
526 static INT_PTR CALLBACK
addtofavorites_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
528 HWND hwndValue
= GetDlgItem(hwndDlg
, IDC_VALUE_NAME
);
533 HKEY hKeyRoot
= NULL
;
534 LPWSTR ItemPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, NULL
, &hKeyRoot
);
536 if(!ItemPath
|| !*ItemPath
)
537 ItemPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
538 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
539 SetWindowTextW(hwndValue
, ItemPath
);
540 SendMessageW(hwndValue
, EM_SETLIMITTEXT
, 127, 0);
541 HeapFree(GetProcessHeap(), 0, ItemPath
);
545 switch(LOWORD(wParam
)) {
547 if (HIWORD(wParam
) == EN_UPDATE
) {
548 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), GetWindowTextLength(hwndValue
)>0);
553 if (GetWindowTextLengthW(hwndValue
)>0) {
554 GetWindowTextW(hwndValue
, favoriteName
, 128);
555 EndDialog(hwndDlg
, IDOK
);
559 EndDialog(hwndDlg
, IDCANCEL
);
567 static INT_PTR CALLBACK
removefavorite_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
569 HWND hwndList
= GetDlgItem(hwndDlg
, IDC_NAME_LIST
);
572 case WM_INITDIALOG
: {
575 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
576 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
577 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
578 WCHAR namebuf
[KEY_MAX_LEN
];
580 DWORD ksize
, vsize
, type
;
584 vsize
= sizeof(valuebuf
);
585 error
= RegEnumValueW(hKey
, i
, namebuf
, &ksize
, NULL
, &type
, valuebuf
, &vsize
);
586 if (error
!= ERROR_SUCCESS
)
588 if (type
== REG_SZ
) {
589 SendMessageW(hwndList
, LB_ADDSTRING
, 0, (LPARAM
)namebuf
);
592 } while(error
== ERROR_SUCCESS
);
597 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), i
!= 0);
598 SendMessageW(hwndList
, LB_SETCURSEL
, 0, 0);
602 switch(LOWORD(wParam
)) {
604 if (HIWORD(wParam
) == LBN_SELCHANGE
) {
605 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), lParam
!= -1);
610 int pos
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
611 int len
= SendMessageW(hwndList
, LB_GETTEXTLEN
, pos
, 0);
613 LPWSTR lpName
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
614 SendMessageW(hwndList
, LB_GETTEXT
, pos
, (LPARAM
)lpName
);
617 lstrcpyW(favoriteName
, lpName
);
618 EndDialog(hwndDlg
, IDOK
);
619 HeapFree(GetProcessHeap(), 0, lpName
);
624 EndDialog(hwndDlg
, IDCANCEL
);
632 /*******************************************************************************
634 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
636 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
639 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
644 BOOL firstItem
= TRUE
;
646 if (LOWORD(wParam
) >= ID_FAVORITE_FIRST
&& LOWORD(wParam
) <= ID_FAVORITE_LAST
) {
648 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
649 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
650 WCHAR namebuf
[KEY_MAX_LEN
];
652 DWORD ksize
= KEY_MAX_LEN
, vsize
= sizeof(valuebuf
), type
= 0;
653 if (RegEnumValueW(hKey
, LOWORD(wParam
) - ID_FAVORITE_FIRST
, namebuf
, &ksize
, NULL
,
654 &type
, valuebuf
, &vsize
) == ERROR_SUCCESS
) {
655 SendMessageW( g_pChildWnd
->hTreeWnd
, TVM_SELECTITEM
, TVGN_CARET
,
656 (LPARAM
) FindPathInTree(g_pChildWnd
->hTreeWnd
, (WCHAR
*)valuebuf
) );
662 switch (LOWORD(wParam
)) {
663 case ID_REGISTRY_IMPORTREGISTRYFILE
:
664 ImportRegistryFile(hWnd
);
667 ExportRegistryFile(hWnd
, TRUE
);
669 case ID_REGISTRY_EXPORTREGISTRYFILE
:
670 ExportRegistryFile(hWnd
, FALSE
);
672 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
674 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
676 case ID_REGISTRY_PRINT
:
678 const WCHAR empty
= 0;
679 PrintRegistryHive(hWnd
, &empty
);
683 if (GetFocus() == g_pChildWnd
->hTreeWnd
) {
684 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
685 if (keyPath
== 0 || *keyPath
== 0) {
686 MessageBeep(MB_ICONHAND
);
687 } else if (DeleteKey(hWnd
, hKeyRoot
, keyPath
)) {
688 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
690 HeapFree(GetProcessHeap(), 0, keyPath
);
691 } else if (GetFocus() == g_pChildWnd
->hListWnd
) {
692 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
693 curIndex
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_SELECTED
);
694 while(curIndex
!= -1) {
695 WCHAR
* valueName
= GetItemText(g_pChildWnd
->hListWnd
, curIndex
);
697 curIndex
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, curIndex
, LVNI_SELECTED
);
698 if(curIndex
!= -1 && firstItem
) {
699 if (MessageBoxW(hWnd
, MAKEINTRESOURCEW(IDS_DELETE_BOX_TEXT_MULTIPLE
),
700 MAKEINTRESOURCEW(IDS_DELETE_BOX_TITLE
),
701 MB_YESNO
| MB_ICONEXCLAMATION
) != IDYES
)
705 if (!DeleteValue(hWnd
, hKeyRoot
, keyPath
, valueName
, curIndex
==-1 && firstItem
))
707 HeapFree(GetProcessHeap(), 0, valueName
);
711 HeapFree(GetProcessHeap(), 0, valueName
);
713 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, NULL
);
714 HeapFree(GetProcessHeap(), 0, keyPath
);
719 LPCWSTR valueName
= GetValueName(g_pChildWnd
->hListWnd
);
720 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
721 if (ModifyValue(hWnd
, hKeyRoot
, keyPath
, valueName
))
722 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, valueName
);
723 HeapFree(GetProcessHeap(), 0, keyPath
);
727 case ID_EDIT_FINDNEXT
:
730 if (LOWORD(wParam
) == ID_EDIT_FIND
&&
731 DialogBox(0, MAKEINTRESOURCE(IDD_FIND
), hWnd
, find_dlgproc
) != IDOK
)
735 hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
737 int row
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
);
738 HCURSOR hcursorOld
= SetCursor(LoadCursor(NULL
, IDC_WAIT
));
739 hItem
= FindNext(g_pChildWnd
->hTreeWnd
, hItem
, searchString
, searchMask
, &row
);
740 SetCursor(hcursorOld
);
742 SendMessageW( g_pChildWnd
->hTreeWnd
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
) hItem
);
743 InvalidateRect(g_pChildWnd
->hTreeWnd
, NULL
, TRUE
);
744 UpdateWindow(g_pChildWnd
->hTreeWnd
);
746 ListView_SetItemState(g_pChildWnd
->hListWnd
, -1, 0, LVIS_FOCUSED
|LVIS_SELECTED
);
747 ListView_SetItemState(g_pChildWnd
->hListWnd
, row
, LVIS_FOCUSED
|LVIS_SELECTED
, LVIS_FOCUSED
|LVIS_SELECTED
);
748 SetFocus(g_pChildWnd
->hListWnd
);
750 SetFocus(g_pChildWnd
->hTreeWnd
);
753 CHAR
* searchStringA
= GetMultiByteString(searchString
);
754 error(hWnd
, IDS_NOTFOUND
, searchStringA
);
755 HeapFree(GetProcessHeap(), 0, searchStringA
);
760 case ID_EDIT_COPYKEYNAME
:
762 LPWSTR fullPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
764 CopyKeyName(hWnd
, fullPath
);
765 HeapFree(GetProcessHeap(), 0, fullPath
);
769 case ID_EDIT_NEW_KEY
:
771 WCHAR newKeyW
[MAX_NEW_KEY_LEN
];
772 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
773 if (CreateKey(hWnd
, hKeyRoot
, keyPath
, newKeyW
)) {
774 if (InsertNode(g_pChildWnd
->hTreeWnd
, 0, newKeyW
))
775 StartKeyRename(g_pChildWnd
->hTreeWnd
);
777 HeapFree(GetProcessHeap(), 0, keyPath
);
780 case ID_EDIT_NEW_STRINGVALUE
:
783 case ID_EDIT_NEW_MULTI_STRINGVALUE
:
784 valueType
= REG_MULTI_SZ
;
786 case ID_EDIT_NEW_BINARYVALUE
:
787 valueType
= REG_BINARY
;
789 case ID_EDIT_NEW_DWORDVALUE
:
790 valueType
= REG_DWORD
;
794 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
795 WCHAR newKey
[MAX_NEW_KEY_LEN
];
796 if (CreateValue(hWnd
, hKeyRoot
, keyPath
, valueType
, newKey
)) {
797 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, newKey
);
798 StartValueRename(g_pChildWnd
->hListWnd
);
800 HeapFree(GetProcessHeap(), 0, keyPath
);
805 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
806 if (keyPath
== 0 || *keyPath
== 0) {
807 MessageBeep(MB_ICONHAND
);
808 } else if (GetFocus() == g_pChildWnd
->hTreeWnd
) {
809 StartKeyRename(g_pChildWnd
->hTreeWnd
);
810 } else if (GetFocus() == g_pChildWnd
->hListWnd
) {
811 StartValueRename(g_pChildWnd
->hListWnd
);
813 HeapFree(GetProcessHeap(), 0, keyPath
);
816 case ID_REGISTRY_PRINTERSETUP
:
819 /*PAGESETUPDLG psd;*/
820 /*PageSetupDlg(&psd);*/
822 case ID_REGISTRY_OPENLOCAL
:
824 case ID_REGISTRY_EXIT
:
827 case ID_FAVORITES_ADDTOFAVORITES
:
830 LPWSTR lpKeyPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
832 if (DialogBox(0, MAKEINTRESOURCE(IDD_ADDFAVORITE
), hWnd
, addtofavorites_dlgproc
) == IDOK
) {
833 if (RegCreateKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
835 KEY_READ
|KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
) {
836 RegSetValueExW(hKey
, favoriteName
, 0, REG_SZ
, (BYTE
*)lpKeyPath
, (lstrlenW(lpKeyPath
)+1)*sizeof(WCHAR
));
840 HeapFree(GetProcessHeap(), 0, lpKeyPath
);
844 case ID_FAVORITES_REMOVEFAVORITE
:
846 if (DialogBox(0, MAKEINTRESOURCE(IDD_DELFAVORITE
), hWnd
, removefavorite_dlgproc
) == IDOK
) {
848 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
849 0, KEY_READ
|KEY_WRITE
, &hKey
) == ERROR_SUCCESS
) {
850 RegDeleteValueW(hKey
, favoriteName
);
856 case ID_VIEW_REFRESH
:
858 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
859 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
860 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, NULL
);
861 HeapFree(GetProcessHeap(), 0, keyPath
);
864 /*case ID_OPTIONS_TOOLBAR:*/
865 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
867 case ID_VIEW_STATUSBAR
:
868 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
870 case ID_HELP_HELPTOPICS
:
872 const WCHAR help_regedit
[] = {'r','e','g','e','d','i','t',0};
873 WinHelpW(hWnd
, help_regedit
, HELP_FINDER
, 0);
879 case ID_VIEW_SPLIT
: {
882 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
883 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
884 pt
.y
= (rt
.bottom
/ 2);
886 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
)) {
887 SetCursorPos(pts
.x
, pts
.y
);
888 SetCursor(LoadCursor(0, IDC_SIZEWE
));
889 SendMessageW(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
900 /********************************************************************************
902 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
904 * PURPOSE: Processes messages for the main frame window.
906 * WM_COMMAND - process the application menu
907 * WM_DESTROY - post a quit message and return
911 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
915 CreateWindowEx(0, szChildClass
, _T("regedit child window"), WS_CHILD
| WS_VISIBLE
,
916 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
917 hWnd
, NULL
, hInst
, 0);
920 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
921 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
925 SetFocus(g_pChildWnd
->hWnd
);
928 resize_frame_client(hWnd
);
932 case WM_ENTERMENULOOP
:
933 OnEnterMenuLoop(hWnd
);
935 case WM_EXITMENULOOP
:
936 OnExitMenuLoop(hWnd
);
938 case WM_INITMENUPOPUP
:
940 OnInitMenuPopup(hWnd
, (HMENU
)wParam
, LOWORD(lParam
));
943 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
947 const WCHAR help_regedit
[] = {'r','e','g','e','d','i','t',0};
948 WinHelpW(hWnd
, help_regedit
, HELP_QUIT
, 0);
952 return DefWindowProc(hWnd
, message
, wParam
, lParam
);