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 */
35 /********************************************************************************
36 * Global and Local Variables:
39 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};
40 static BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
41 static WCHAR favoriteName
[128];
42 static WCHAR searchString
[128];
43 static int searchMask
= SEARCH_KEYS
| SEARCH_VALUES
| SEARCH_CONTENT
;
45 static TCHAR FileNameBuffer
[_MAX_PATH
];
46 static TCHAR FileTitleBuffer
[_MAX_PATH
];
47 static TCHAR FilterBuffer
[_MAX_PATH
];
49 /*******************************************************************************
50 * Local module support methods
53 static void resize_frame_rect(HWND hWnd
, PRECT prect
)
57 if (IsWindowVisible(hToolBar)) {
58 SendMessage(hToolBar, WM_SIZE, 0, 0);
59 GetClientRect(hToolBar, &rt);
60 prect->top = rt.bottom+3;
61 prect->bottom -= rt.bottom+3;
64 if (IsWindowVisible(hStatusBar
)) {
65 SetupStatusBar(hWnd
, TRUE
);
66 GetClientRect(hStatusBar
, &rt
);
67 prect
->bottom
-= rt
.bottom
;
69 MoveWindow(g_pChildWnd
->hWnd
, prect
->left
, prect
->top
, prect
->right
, prect
->bottom
, TRUE
);
72 static void resize_frame_client(HWND hWnd
)
76 GetClientRect(hWnd
, &rect
);
77 resize_frame_rect(hWnd
, &rect
);
80 /********************************************************************************/
82 static void OnEnterMenuLoop(HWND hWnd
)
86 /* Update the status bar pane sizes */
88 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (long)&nParts
);
90 SendMessage(hStatusBar
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)_T(""));
93 static void OnExitMenuLoop(HWND hWnd
)
96 /* Update the status bar pane sizes*/
97 SetupStatusBar(hWnd
, TRUE
);
101 static void UpdateMenuItems(HMENU hMenu
) {
102 HWND hwndTV
= g_pChildWnd
->hTreeWnd
;
103 BOOL bAllowEdit
= FALSE
;
104 HKEY hRootKey
= NULL
;
106 keyName
= GetItemPath(hwndTV
, TreeView_GetSelection(hwndTV
), &hRootKey
);
107 if (GetFocus() != hwndTV
|| (keyName
&& *keyName
)) { /* can't modify root keys, but allow for their values */
110 EnableMenuItem(hMenu
, ID_EDIT_FIND
, MF_ENABLED
| MF_BYCOMMAND
);
111 EnableMenuItem(hMenu
, ID_EDIT_FINDNEXT
, MF_ENABLED
| MF_BYCOMMAND
);
112 EnableMenuItem(hMenu
, ID_EDIT_MODIFY
, (bAllowEdit
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
113 EnableMenuItem(hMenu
, ID_EDIT_DELETE
, (bAllowEdit
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
114 EnableMenuItem(hMenu
, ID_EDIT_RENAME
, (bAllowEdit
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
115 EnableMenuItem(hMenu
, ID_FAVORITES_ADDTOFAVORITES
, (hRootKey
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
116 EnableMenuItem(hMenu
, ID_FAVORITES_REMOVEFAVORITE
,
117 (GetMenuItemCount(hMenu
)>2 ? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
120 static void OnInitMenuPopup(HWND hWnd
, HMENU hMenu
, short wItem
)
124 while(GetMenuItemCount(hMenu
)>2)
125 DeleteMenu(hMenu
, 2, MF_BYPOSITION
);
126 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
127 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
128 WCHAR namebuf
[KEY_MAX_LEN
];
132 DWORD ksize
, vsize
, type
;
136 vsize
= sizeof(valuebuf
);
137 error
= RegEnumValueW(hKey
, i
, namebuf
, &ksize
, NULL
, &type
, valuebuf
, &vsize
);
138 if (error
!= ERROR_SUCCESS
)
140 if (type
== REG_SZ
) {
142 AppendMenuW(hMenu
, MF_SEPARATOR
, -1, NULL
);
145 AppendMenuW(hMenu
, MF_STRING
, ID_FAVORITE_FIRST
+i
, namebuf
);
148 } while(error
== ERROR_SUCCESS
);
152 UpdateMenuItems(hMenu
);
155 static void OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
159 _tcscpy(str
, _T(""));
160 if (nFlags
& MF_POPUP
) {
161 if (hSysMenu
!= GetMenu(hWnd
)) {
162 if (nItemID
== 2) nItemID
= 5;
165 if (LoadString(hInst
, nItemID
, str
, 100)) {
166 /* load appropriate string*/
168 /* first newline terminates actual string*/
169 lpsz
= _tcschr(lpsz
, '\n');
173 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)str
);
176 void SetupStatusBar(HWND hWnd
, BOOL bResize
)
180 GetClientRect(hWnd
, &rc
);
184 SendMessage(hStatusBar
, WM_SIZE
, 0, 0);
185 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
189 void UpdateStatusBar(void)
191 LPTSTR fullPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, TRUE
);
192 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)fullPath
);
193 HeapFree(GetProcessHeap(), 0, fullPath
);
196 static void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
198 BOOL vis
= IsWindowVisible(hchild
);
199 HMENU hMenuView
= GetSubMenu(hMenuFrame
, ID_VIEW_MENU
);
201 CheckMenuItem(hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
202 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
203 resize_frame_client(hWnd
);
206 static BOOL
CheckCommDlgError(HWND hWnd
)
208 DWORD dwErrorCode
= CommDlgExtendedError();
209 switch (dwErrorCode
) {
210 case CDERR_DIALOGFAILURE
:
212 case CDERR_FINDRESFAILURE
:
214 case CDERR_NOHINSTANCE
:
216 case CDERR_INITIALIZATION
:
220 case CDERR_LOCKRESFAILURE
:
222 case CDERR_NOTEMPLATE
:
224 case CDERR_LOADRESFAILURE
:
226 case CDERR_STRUCTSIZE
:
228 case CDERR_LOADSTRFAILURE
:
230 case FNERR_BUFFERTOOSMALL
:
232 case CDERR_MEMALLOCFAILURE
:
234 case FNERR_INVALIDFILENAME
:
236 case CDERR_MEMLOCKFAILURE
:
238 case FNERR_SUBCLASSFAILURE
:
246 static void ExportRegistryFile_StoreSelection(HWND hdlg
, OPENFILENAME
*pOpenFileName
)
248 if (IsDlgButtonChecked(hdlg
, IDC_EXPORT_SELECTED
))
250 INT len
= SendDlgItemMessage(hdlg
, IDC_EXPORT_PATH
, WM_GETTEXTLENGTH
, 0, 0);
251 pOpenFileName
->lCustData
= (LPARAM
)HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(TCHAR
));
252 SendDlgItemMessage(hdlg
, IDC_EXPORT_PATH
, WM_GETTEXT
, len
+1, pOpenFileName
->lCustData
);
255 pOpenFileName
->lCustData
= (LPARAM
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TCHAR
));
258 static UINT CALLBACK
ExportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
260 static OPENFILENAME
* pOpenFileName
;
266 pOpenFileName
= (OPENFILENAME
*)lParam
;
269 if (LOWORD(wParam
) == IDC_EXPORT_PATH
&& HIWORD(wParam
) == EN_UPDATE
)
270 CheckRadioButton(hdlg
, IDC_EXPORT_ALL
, IDC_EXPORT_SELECTED
, IDC_EXPORT_SELECTED
);
273 pOfNotify
= (OFNOTIFY
*)lParam
;
274 switch (pOfNotify
->hdr
.code
)
277 path
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
278 SendDlgItemMessage(hdlg
, IDC_EXPORT_PATH
, WM_SETTEXT
, 0, (LPARAM
)path
);
279 HeapFree(GetProcessHeap(), 0, path
);
280 CheckRadioButton(hdlg
, IDC_EXPORT_ALL
, IDC_EXPORT_SELECTED
, pOpenFileName
->lCustData
? IDC_EXPORT_SELECTED
: IDC_EXPORT_ALL
);
283 ExportRegistryFile_StoreSelection(hdlg
, pOpenFileName
);
294 static BOOL
InitOpenFileName(HWND hWnd
, OPENFILENAME
*pofn
)
296 memset(pofn
, 0, sizeof(OPENFILENAME
));
297 pofn
->lStructSize
= sizeof(OPENFILENAME
);
298 pofn
->hwndOwner
= hWnd
;
299 pofn
->hInstance
= hInst
;
301 if (FilterBuffer
[0] == 0)
302 LoadString(hInst
, IDS_FILEDIALOG_FILTER
, FilterBuffer
, _MAX_PATH
);
303 pofn
->lpstrFilter
= FilterBuffer
;
304 pofn
->nFilterIndex
= 1;
305 pofn
->lpstrFile
= FileNameBuffer
;
306 pofn
->nMaxFile
= _MAX_PATH
;
307 pofn
->lpstrFileTitle
= FileTitleBuffer
;
308 pofn
->nMaxFileTitle
= _MAX_PATH
;
309 pofn
->Flags
= OFN_HIDEREADONLY
;
310 /* some other fields may be set by the caller */
314 static BOOL
import_registry_filename(LPTSTR filename
)
317 FILE* reg_file
= fopen(filename
, "r");
322 Success
= import_registry_file(reg_file
);
324 if(fclose(reg_file
) != 0)
330 static BOOL
ImportRegistryFile(HWND hWnd
)
335 InitOpenFileName(hWnd
, &ofn
);
336 LoadString(hInst
, IDS_FILEDIALOG_IMPORT_TITLE
, title
, COUNT_OF(title
));
337 ofn
.lpstrTitle
= title
;
338 if (GetOpenFileName(&ofn
)) {
339 if (!import_registry_filename(ofn
.lpstrFile
)) {
340 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
344 CheckCommDlgError(hWnd
);
346 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
351 static BOOL
ExportRegistryFile(HWND hWnd
, BOOL export_branch
)
354 TCHAR ExportKeyPath
[_MAX_PATH
];
357 ExportKeyPath
[0] = _T('\0');
358 InitOpenFileName(hWnd
, &ofn
);
359 LoadString(hInst
, IDS_FILEDIALOG_EXPORT_TITLE
, title
, COUNT_OF(title
));
360 ofn
.lpstrTitle
= title
;
361 ofn
.lCustData
= export_branch
;
362 ofn
.Flags
= OFN_ENABLETEMPLATE
| OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
;
363 ofn
.lpfnHook
= ExportRegistryFile_OFNHookProc
;
364 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_EXPORT_TEMPLATE
);
365 if (GetSaveFileName(&ofn
)) {
367 result
= export_registry_key(ofn
.lpstrFile
, (LPTSTR
)ofn
.lCustData
);
369 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
373 CheckCommDlgError(hWnd
);
378 static BOOL
PrintRegistryHive(HWND hWnd
, LPCWSTR path
)
383 ZeroMemory(&pd
, sizeof(PRINTDLG
));
384 pd
.lStructSize
= sizeof(PRINTDLG
);
386 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
387 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
388 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
390 pd
.nFromPage
= 0xFFFF;
393 pd
.nMaxPage
= 0xFFFF;
394 if (PrintDlgW(&pd
)) {
395 /* GDI calls to render output. */
396 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
402 hResult
= PrintDlgExW(&pd
);
403 if (hResult
== S_OK
) {
404 switch (pd
.dwResultAction
) {
405 case PD_RESULT_APPLY
:
406 /*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. */
408 case PD_RESULT_CANCEL
:
409 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
411 case PD_RESULT_PRINT
:
412 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
420 /*Insufficient memory. */
423 /* One or more arguments are invalid. */
426 /*Invalid pointer. */
432 /*Unspecified error. */
443 static BOOL
CopyKeyName(HWND hWnd
, LPCWSTR keyName
)
447 result
= OpenClipboard(hWnd
);
449 result
= EmptyClipboard();
451 int len
= (lstrlenW(keyName
)+1)*sizeof(WCHAR
);
452 HANDLE hClipData
= GlobalAlloc(GHND
, len
);
453 LPVOID pLoc
= GlobalLock(hClipData
);
454 lstrcpyW(pLoc
, keyName
);
455 GlobalUnlock(hClipData
);
456 hClipData
= SetClipboardData(CF_UNICODETEXT
, hClipData
);
459 /* error emptying clipboard*/
460 /* DWORD dwError = GetLastError(); */
463 if (!CloseClipboard()) {
464 /* error closing clipboard*/
465 /* DWORD dwError = GetLastError(); */
469 /* error opening clipboard*/
470 /* DWORD dwError = GetLastError(); */
476 static INT_PTR CALLBACK
find_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
478 HWND hwndValue
= GetDlgItem(hwndDlg
, IDC_VALUE_NAME
);
482 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
483 CheckDlgButton(hwndDlg
, IDC_FIND_KEYS
, searchMask
&SEARCH_KEYS
? BST_CHECKED
: BST_UNCHECKED
);
484 CheckDlgButton(hwndDlg
, IDC_FIND_VALUES
, searchMask
&SEARCH_VALUES
? BST_CHECKED
: BST_UNCHECKED
);
485 CheckDlgButton(hwndDlg
, IDC_FIND_CONTENT
, searchMask
&SEARCH_CONTENT
? BST_CHECKED
: BST_UNCHECKED
);
486 CheckDlgButton(hwndDlg
, IDC_FIND_WHOLE
, searchMask
&SEARCH_WHOLE
? BST_CHECKED
: BST_UNCHECKED
);
487 SendMessageW(hwndValue
, EM_SETLIMITTEXT
, 127, 0);
488 SetWindowTextW(hwndValue
, searchString
);
491 switch(LOWORD(wParam
)) {
493 if (HIWORD(wParam
) == EN_UPDATE
) {
494 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), GetWindowTextLengthW(hwndValue
)>0);
499 if (GetWindowTextLengthW(hwndValue
)>0) {
501 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_KEYS
)) mask
|= SEARCH_KEYS
;
502 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_VALUES
)) mask
|= SEARCH_VALUES
;
503 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_CONTENT
)) mask
|= SEARCH_CONTENT
;
504 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_WHOLE
)) mask
|= SEARCH_WHOLE
;
506 GetWindowTextW(hwndValue
, searchString
, 128);
507 EndDialog(hwndDlg
, IDOK
);
511 EndDialog(hwndDlg
, IDCANCEL
);
519 static INT_PTR CALLBACK
addtofavorites_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
521 HWND hwndValue
= GetDlgItem(hwndDlg
, IDC_VALUE_NAME
);
526 HKEY hKeyRoot
= NULL
;
527 LPWSTR ItemPath
= GetItemPathW(g_pChildWnd
->hTreeWnd
, NULL
, &hKeyRoot
);
529 if(!ItemPath
|| !*ItemPath
)
530 ItemPath
= GetItemFullPathW(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
531 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
532 SetWindowTextW(hwndValue
, ItemPath
);
533 SendMessageW(hwndValue
, EM_SETLIMITTEXT
, 127, 0);
534 HeapFree(GetProcessHeap(), 0, ItemPath
);
538 switch(LOWORD(wParam
)) {
540 if (HIWORD(wParam
) == EN_UPDATE
) {
541 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), GetWindowTextLength(hwndValue
)>0);
546 if (GetWindowTextLengthW(hwndValue
)>0) {
547 GetWindowTextW(hwndValue
, favoriteName
, 128);
548 EndDialog(hwndDlg
, IDOK
);
552 EndDialog(hwndDlg
, IDCANCEL
);
560 static INT_PTR CALLBACK
removefavorite_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
562 HWND hwndList
= GetDlgItem(hwndDlg
, IDC_NAME_LIST
);
565 case WM_INITDIALOG
: {
568 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
569 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
570 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
571 WCHAR namebuf
[KEY_MAX_LEN
];
573 DWORD ksize
, vsize
, type
;
577 vsize
= sizeof(valuebuf
);
578 error
= RegEnumValueW(hKey
, i
, namebuf
, &ksize
, NULL
, &type
, valuebuf
, &vsize
);
579 if (error
!= ERROR_SUCCESS
)
581 if (type
== REG_SZ
) {
582 SendMessageW(hwndList
, LB_ADDSTRING
, 0, (LPARAM
)namebuf
);
585 } while(error
== ERROR_SUCCESS
);
590 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), i
!= 0);
591 SendMessageW(hwndList
, LB_SETCURSEL
, 0, 0);
595 switch(LOWORD(wParam
)) {
597 if (HIWORD(wParam
) == LBN_SELCHANGE
) {
598 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), lParam
!= -1);
603 int pos
= SendMessage(hwndList
, LB_GETCURSEL
, 0, 0);
604 int len
= SendMessage(hwndList
, LB_GETTEXTLEN
, pos
, 0);
606 LPWSTR lpName
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
607 SendMessageW(hwndList
, LB_GETTEXT
, pos
, (LPARAM
)lpName
);
610 lstrcpyW(favoriteName
, lpName
);
611 EndDialog(hwndDlg
, IDOK
);
612 HeapFree(GetProcessHeap(), 0, lpName
);
617 EndDialog(hwndDlg
, IDCANCEL
);
625 /*******************************************************************************
627 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
629 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
632 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
637 TCHAR newKey
[MAX_NEW_KEY_LEN
];
640 BOOL firstItem
= TRUE
;
642 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
644 if (LOWORD(wParam
) >= ID_FAVORITE_FIRST
&& LOWORD(wParam
) <= ID_FAVORITE_LAST
) {
646 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
647 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
648 WCHAR namebuf
[KEY_MAX_LEN
];
650 DWORD ksize
= KEY_MAX_LEN
, vsize
= sizeof(valuebuf
), type
= 0;
651 if (RegEnumValueW(hKey
, LOWORD(wParam
) - ID_FAVORITE_FIRST
, namebuf
, &ksize
, NULL
,
652 &type
, valuebuf
, &vsize
) == ERROR_SUCCESS
) {
653 SendMessageW( g_pChildWnd
->hTreeWnd
, TVM_SELECTITEM
, TVGN_CARET
,
654 (LPARAM
) FindPathInTree(g_pChildWnd
->hTreeWnd
, (WCHAR
*)valuebuf
) );
660 switch (LOWORD(wParam
)) {
661 case ID_REGISTRY_IMPORTREGISTRYFILE
:
662 ImportRegistryFile(hWnd
);
665 ExportRegistryFile(hWnd
, TRUE
);
667 case ID_REGISTRY_EXPORTREGISTRYFILE
:
668 ExportRegistryFile(hWnd
, FALSE
);
670 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
672 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
674 case ID_REGISTRY_PRINT
:
676 const WCHAR empty
= 0;
677 PrintRegistryHive(hWnd
, &empty
);
681 if (GetFocus() == g_pChildWnd
->hTreeWnd
) {
682 WCHAR
* keyPathW
= GetWideString(keyPath
);
683 if (keyPath
== 0 || *keyPath
== 0) {
684 MessageBeep(MB_ICONHAND
);
685 } else if (DeleteKey(hWnd
, hKeyRoot
, keyPathW
)) {
686 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
688 HeapFree(GetProcessHeap(), 0, keyPathW
);
689 } else if (GetFocus() == g_pChildWnd
->hListWnd
) {
690 curIndex
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_SELECTED
);
691 while(curIndex
!= -1) {
695 valueName
= GetItemText(g_pChildWnd
->hListWnd
, curIndex
);
696 curIndex
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, curIndex
, LVNI_SELECTED
);
697 if(curIndex
!= -1 && firstItem
) {
698 if (MessageBoxW(hWnd
, MAKEINTRESOURCEW(IDS_DELETE_BOX_TEXT_MULTIPLE
),
699 MAKEINTRESOURCEW(IDS_DELETE_BOX_TITLE
),
700 MB_YESNO
| MB_ICONEXCLAMATION
) != IDYES
)
703 valueNameW
= GetWideString(valueName
);
704 keyPathW
= GetWideString(keyPath
);
705 if (!DeleteValue(hWnd
, hKeyRoot
, keyPathW
, valueNameW
, curIndex
==-1 && firstItem
))
707 HeapFree(GetProcessHeap(), 0, valueNameW
);
708 HeapFree(GetProcessHeap(), 0, keyPathW
);
712 HeapFree(GetProcessHeap(), 0, valueNameW
);
713 HeapFree(GetProcessHeap(), 0, keyPathW
);
715 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, NULL
);
719 valueName
= GetValueName(g_pChildWnd
->hListWnd
);
720 if (ModifyValue(hWnd
, hKeyRoot
, keyPath
, valueName
))
721 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, valueName
);
724 case ID_EDIT_FINDNEXT
:
727 if (LOWORD(wParam
) == ID_EDIT_FIND
&&
728 DialogBox(0, MAKEINTRESOURCE(IDD_FIND
), hWnd
, find_dlgproc
) != IDOK
)
732 hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
734 int row
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
);
735 HCURSOR hcursorOld
= SetCursor(LoadCursor(NULL
, IDC_WAIT
));
736 hItem
= FindNext(g_pChildWnd
->hTreeWnd
, hItem
, searchString
, searchMask
, &row
);
737 SetCursor(hcursorOld
);
739 SendMessage( g_pChildWnd
->hTreeWnd
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
) hItem
);
740 InvalidateRect(g_pChildWnd
->hTreeWnd
, NULL
, TRUE
);
741 UpdateWindow(g_pChildWnd
->hTreeWnd
);
743 ListView_SetItemState(g_pChildWnd
->hListWnd
, -1, 0, LVIS_FOCUSED
|LVIS_SELECTED
);
744 ListView_SetItemState(g_pChildWnd
->hListWnd
, row
, LVIS_FOCUSED
|LVIS_SELECTED
, LVIS_FOCUSED
|LVIS_SELECTED
);
745 SetFocus(g_pChildWnd
->hListWnd
);
747 SetFocus(g_pChildWnd
->hTreeWnd
);
750 CHAR
* searchStringA
= GetMultiByteString(searchString
);
751 error(hWnd
, IDS_NOTFOUND
, searchStringA
);
752 HeapFree(GetProcessHeap(), 0, searchStringA
);
757 case ID_EDIT_COPYKEYNAME
:
759 LPWSTR fullPath
= GetItemFullPathW(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
761 CopyKeyName(hWnd
, fullPath
);
762 HeapFree(GetProcessHeap(), 0, fullPath
);
766 case ID_EDIT_NEW_KEY
:
768 WCHAR newKeyW
[MAX_NEW_KEY_LEN
];
769 WCHAR
* keyPathW
= GetWideString(keyPath
);
770 if (CreateKey(hWnd
, hKeyRoot
, keyPathW
, newKeyW
)) {
771 if (InsertNode(g_pChildWnd
->hTreeWnd
, 0, newKeyW
))
772 StartKeyRename(g_pChildWnd
->hTreeWnd
);
774 HeapFree(GetProcessHeap(), 0, keyPathW
);
777 case ID_EDIT_NEW_STRINGVALUE
:
780 case ID_EDIT_NEW_MULTI_STRINGVALUE
:
781 valueType
= REG_MULTI_SZ
;
783 case ID_EDIT_NEW_BINARYVALUE
:
784 valueType
= REG_BINARY
;
786 case ID_EDIT_NEW_DWORDVALUE
:
787 valueType
= REG_DWORD
;
790 if (CreateValue(hWnd
, hKeyRoot
, keyPath
, valueType
, newKey
)) {
791 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, newKey
);
792 StartValueRename(g_pChildWnd
->hListWnd
);
793 /* FIXME: start rename */
797 if (keyPath
== 0 || *keyPath
== 0) {
798 MessageBeep(MB_ICONHAND
);
799 } else if (GetFocus() == g_pChildWnd
->hTreeWnd
) {
800 StartKeyRename(g_pChildWnd
->hTreeWnd
);
801 } else if (GetFocus() == g_pChildWnd
->hListWnd
) {
802 StartValueRename(g_pChildWnd
->hListWnd
);
805 case ID_REGISTRY_PRINTERSETUP
:
808 /*PAGESETUPDLG psd;*/
809 /*PageSetupDlg(&psd);*/
811 case ID_REGISTRY_OPENLOCAL
:
813 case ID_REGISTRY_EXIT
:
816 case ID_FAVORITES_ADDTOFAVORITES
:
819 LPWSTR lpKeyPath
= GetItemFullPathW(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
821 if (DialogBox(0, MAKEINTRESOURCE(IDD_ADDFAVORITE
), hWnd
, addtofavorites_dlgproc
) == IDOK
) {
822 if (RegCreateKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
824 KEY_READ
|KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
) {
825 RegSetValueExW(hKey
, favoriteName
, 0, REG_SZ
, (BYTE
*)lpKeyPath
, (lstrlenW(lpKeyPath
)+1)*sizeof(WCHAR
));
829 HeapFree(GetProcessHeap(), 0, lpKeyPath
);
833 case ID_FAVORITES_REMOVEFAVORITE
:
835 if (DialogBox(0, MAKEINTRESOURCE(IDD_DELFAVORITE
), hWnd
, removefavorite_dlgproc
) == IDOK
) {
837 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
838 0, KEY_READ
|KEY_WRITE
, &hKey
) == ERROR_SUCCESS
) {
839 RegDeleteValueW(hKey
, favoriteName
);
845 case ID_VIEW_REFRESH
:
846 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
847 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, NULL
);
849 /*case ID_OPTIONS_TOOLBAR:*/
850 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
852 case ID_VIEW_STATUSBAR
:
853 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
855 case ID_HELP_HELPTOPICS
:
857 const WCHAR help_regedit
[] = {'r','e','g','e','d','i','t',0};
858 WinHelpW(hWnd
, help_regedit
, HELP_FINDER
, 0);
864 case ID_VIEW_SPLIT
: {
867 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
868 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
869 pt
.y
= (rt
.bottom
/ 2);
871 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
)) {
872 SetCursorPos(pts
.x
, pts
.y
);
873 SetCursor(LoadCursor(0, IDC_SIZEWE
));
874 SendMessage(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
885 /********************************************************************************
887 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
889 * PURPOSE: Processes messages for the main frame window.
891 * WM_COMMAND - process the application menu
892 * WM_DESTROY - post a quit message and return
896 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
900 CreateWindowEx(0, szChildClass
, _T("regedit child window"), WS_CHILD
| WS_VISIBLE
,
901 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
902 hWnd
, NULL
, hInst
, 0);
905 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
906 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
910 SetFocus(g_pChildWnd
->hWnd
);
913 resize_frame_client(hWnd
);
917 case WM_ENTERMENULOOP
:
918 OnEnterMenuLoop(hWnd
);
920 case WM_EXITMENULOOP
:
921 OnExitMenuLoop(hWnd
);
923 case WM_INITMENUPOPUP
:
925 OnInitMenuPopup(hWnd
, (HMENU
)wParam
, LOWORD(lParam
));
928 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
932 const WCHAR help_regedit
[] = {'r','e','g','e','d','i','t',0};
933 WinHelpW(hWnd
, help_regedit
, HELP_QUIT
, 0);
937 return DefWindowProc(hWnd
, message
, wParam
, lParam
);