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 */
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(regedit
);
38 /********************************************************************************
39 * Global and Local Variables:
42 static const 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};
43 static BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
44 static WCHAR favoriteName
[128];
45 static WCHAR searchString
[128];
46 static int searchMask
= SEARCH_KEYS
| SEARCH_VALUES
| SEARCH_CONTENT
;
48 static WCHAR FileNameBuffer
[_MAX_PATH
];
49 static WCHAR FileTitleBuffer
[_MAX_PATH
];
50 static WCHAR FilterBuffer
[_MAX_PATH
];
52 /*******************************************************************************
53 * Local module support methods
56 static void resize_frame_rect(HWND hWnd
, PRECT prect
)
60 if (IsWindowVisible(hToolBar)) {
61 SendMessageW(hToolBar, WM_SIZE, 0, 0);
62 GetClientRect(hToolBar, &rt);
63 prect->top = rt.bottom+3;
64 prect->bottom -= rt.bottom+3;
67 if (IsWindowVisible(hStatusBar
)) {
68 SetupStatusBar(hWnd
, TRUE
);
69 GetClientRect(hStatusBar
, &rt
);
70 prect
->bottom
-= rt
.bottom
;
72 MoveWindow(g_pChildWnd
->hWnd
, prect
->left
, prect
->top
, prect
->right
, prect
->bottom
, TRUE
);
75 static void resize_frame_client(HWND hWnd
)
79 GetClientRect(hWnd
, &rect
);
80 resize_frame_rect(hWnd
, &rect
);
83 /********************************************************************************/
85 static void OnEnterMenuLoop(HWND hWnd
)
90 /* Update the status bar pane sizes */
92 SendMessageW(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
94 SendMessageW(hStatusBar
, SB_SETTEXTW
, 0, (LPARAM
)&empty
);
97 static void OnExitMenuLoop(HWND hWnd
)
100 /* Update the status bar pane sizes*/
101 SetupStatusBar(hWnd
, TRUE
);
105 static void UpdateMenuItems(HMENU hMenu
) {
106 HWND hwndTV
= g_pChildWnd
->hTreeWnd
;
107 BOOL bAllowEdit
= FALSE
;
108 HKEY hRootKey
= NULL
;
112 selection
= (HTREEITEM
)SendMessageW(hwndTV
, TVM_GETNEXTITEM
, TVGN_CARET
, 0);
113 keyName
= GetItemPath(hwndTV
, selection
, &hRootKey
);
114 if (GetFocus() != hwndTV
|| (keyName
&& *keyName
)) { /* can't modify root keys, but allow for their values */
117 EnableMenuItem(hMenu
, ID_EDIT_FIND
, MF_ENABLED
| MF_BYCOMMAND
);
118 EnableMenuItem(hMenu
, ID_EDIT_FINDNEXT
, MF_ENABLED
| MF_BYCOMMAND
);
119 EnableMenuItem(hMenu
, ID_EDIT_MODIFY
, (bAllowEdit
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
120 EnableMenuItem(hMenu
, ID_EDIT_DELETE
, (bAllowEdit
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
121 EnableMenuItem(hMenu
, ID_EDIT_RENAME
, (bAllowEdit
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
122 EnableMenuItem(hMenu
, ID_FAVORITES_ADDTOFAVORITES
, (hRootKey
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
123 EnableMenuItem(hMenu
, ID_FAVORITES_REMOVEFAVORITE
,
124 (GetMenuItemCount(hMenu
)>2 ? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
126 HeapFree(GetProcessHeap(), 0, keyName
);
129 static void OnInitMenuPopup(HWND hWnd
, HMENU hMenu
, short wItem
)
133 while(GetMenuItemCount(hMenu
)>2)
134 DeleteMenu(hMenu
, 2, MF_BYPOSITION
);
135 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
136 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
137 WCHAR namebuf
[KEY_MAX_LEN
];
141 DWORD ksize
, vsize
, type
;
145 vsize
= sizeof(valuebuf
);
146 error
= RegEnumValueW(hKey
, i
, namebuf
, &ksize
, NULL
, &type
, valuebuf
, &vsize
);
147 if (error
!= ERROR_SUCCESS
)
149 if (type
== REG_SZ
) {
151 AppendMenuW(hMenu
, MF_SEPARATOR
, -1, NULL
);
154 AppendMenuW(hMenu
, MF_STRING
, ID_FAVORITE_FIRST
+i
, namebuf
);
157 } while(error
== ERROR_SUCCESS
);
161 UpdateMenuItems(hMenu
);
164 static void OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
169 if (nFlags
& MF_POPUP
) {
170 if (hSysMenu
!= GetMenu(hWnd
)) {
171 if (nItemID
== 2) nItemID
= 5;
174 if (LoadStringW(hInst
, nItemID
, str
, 100)) {
175 /* load appropriate string*/
177 /* first newline terminates actual string*/
178 lpsz
= strchrW(lpsz
, '\n');
182 SendMessageW(hStatusBar
, SB_SETTEXTW
, 0, (LPARAM
)str
);
185 void SetupStatusBar(HWND hWnd
, BOOL bResize
)
189 GetClientRect(hWnd
, &rc
);
193 SendMessageW(hStatusBar
, WM_SIZE
, 0, 0);
194 SendMessageW(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
198 void UpdateStatusBar(void)
200 LPWSTR fullPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, TRUE
);
201 SendMessageW(hStatusBar
, SB_SETTEXTW
, 0, (LPARAM
)fullPath
);
202 HeapFree(GetProcessHeap(), 0, fullPath
);
205 static void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
207 BOOL vis
= IsWindowVisible(hchild
);
208 HMENU hMenuView
= GetSubMenu(hMenuFrame
, ID_VIEW_MENU
);
210 CheckMenuItem(hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
211 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
212 resize_frame_client(hWnd
);
215 static BOOL
CheckCommDlgError(HWND hWnd
)
217 DWORD dwErrorCode
= CommDlgExtendedError();
218 switch (dwErrorCode
) {
219 case CDERR_DIALOGFAILURE
:
221 case CDERR_FINDRESFAILURE
:
223 case CDERR_NOHINSTANCE
:
225 case CDERR_INITIALIZATION
:
229 case CDERR_LOCKRESFAILURE
:
231 case CDERR_NOTEMPLATE
:
233 case CDERR_LOADRESFAILURE
:
235 case CDERR_STRUCTSIZE
:
237 case CDERR_LOADSTRFAILURE
:
239 case FNERR_BUFFERTOOSMALL
:
241 case CDERR_MEMALLOCFAILURE
:
243 case FNERR_INVALIDFILENAME
:
245 case CDERR_MEMLOCKFAILURE
:
247 case FNERR_SUBCLASSFAILURE
:
255 static void ExportRegistryFile_StoreSelection(HWND hdlg
, OPENFILENAMEW
*pOpenFileName
)
257 if (IsDlgButtonChecked(hdlg
, IDC_EXPORT_SELECTED
))
259 INT len
= SendDlgItemMessageW(hdlg
, IDC_EXPORT_PATH
, WM_GETTEXTLENGTH
, 0, 0);
260 pOpenFileName
->lCustData
= (LPARAM
)HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(WCHAR
));
261 SendDlgItemMessageW(hdlg
, IDC_EXPORT_PATH
, WM_GETTEXT
, len
+1, pOpenFileName
->lCustData
);
264 pOpenFileName
->lCustData
= (LPARAM
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
));
267 static UINT_PTR CALLBACK
ExportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
269 static OPENFILENAMEW
* pOpenFileName
;
270 OFNOTIFYW
*pOfNotify
;
274 pOpenFileName
= (OPENFILENAMEW
*)lParam
;
277 if (LOWORD(wParam
) == IDC_EXPORT_PATH
&& HIWORD(wParam
) == EN_UPDATE
)
278 CheckRadioButton(hdlg
, IDC_EXPORT_ALL
, IDC_EXPORT_SELECTED
, IDC_EXPORT_SELECTED
);
281 pOfNotify
= (OFNOTIFYW
*)lParam
;
282 switch (pOfNotify
->hdr
.code
)
286 BOOL export_branch
= FALSE
;
287 WCHAR
* path
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
288 SendDlgItemMessageW(hdlg
, IDC_EXPORT_PATH
, WM_SETTEXT
, 0, (LPARAM
)path
);
290 export_branch
= TRUE
;
291 HeapFree(GetProcessHeap(), 0, path
);
292 CheckRadioButton(hdlg
, IDC_EXPORT_ALL
, IDC_EXPORT_SELECTED
, export_branch
? IDC_EXPORT_SELECTED
: IDC_EXPORT_ALL
);
296 ExportRegistryFile_StoreSelection(hdlg
, pOpenFileName
);
307 static BOOL
InitOpenFileName(HWND hWnd
, OPENFILENAMEW
*pofn
)
309 memset(pofn
, 0, sizeof(OPENFILENAMEW
));
310 pofn
->lStructSize
= sizeof(OPENFILENAMEW
);
311 pofn
->hwndOwner
= hWnd
;
312 pofn
->hInstance
= hInst
;
314 if (FilterBuffer
[0] == 0)
316 static const WCHAR filterW
[] = {'%','s','%','c','*','.','r','e','g','%','c','%','s','%','c','*','.','r','e','g','%','c','%','s','%','c','*','.','*','%','c',0};
317 WCHAR filter_reg
[MAX_PATH
], filter_reg4
[MAX_PATH
], filter_all
[MAX_PATH
];
319 LoadStringW(hInst
, IDS_FILEDIALOG_FILTER_REG
, filter_reg
, MAX_PATH
);
320 LoadStringW(hInst
, IDS_FILEDIALOG_FILTER_REG4
, filter_reg4
, MAX_PATH
);
321 LoadStringW(hInst
, IDS_FILEDIALOG_FILTER_ALL
, filter_all
, MAX_PATH
);
322 snprintfW( FilterBuffer
, MAX_PATH
, filterW
, filter_reg
, 0, 0, filter_reg4
, 0, 0, filter_all
, 0, 0 );
324 pofn
->lpstrFilter
= FilterBuffer
;
325 pofn
->nFilterIndex
= 2;
326 pofn
->lpstrFile
= FileNameBuffer
;
327 pofn
->nMaxFile
= _MAX_PATH
;
328 pofn
->lpstrFileTitle
= FileTitleBuffer
;
329 pofn
->nMaxFileTitle
= _MAX_PATH
;
330 pofn
->Flags
= OFN_HIDEREADONLY
;
331 /* some other fields may be set by the caller */
335 static BOOL
import_registry_filename(LPWSTR filename
)
337 static const WCHAR rb_mode
[] = {'r','b',0};
340 FILE* reg_file
= _wfopen(filename
, rb_mode
);
345 Success
= import_registry_file(reg_file
);
347 if(fclose(reg_file
) != 0)
353 static BOOL
ImportRegistryFile(HWND hWnd
)
357 HKEY root_key
= NULL
;
360 InitOpenFileName(hWnd
, &ofn
);
361 ofn
.Flags
|= OFN_ENABLESIZING
;
362 LoadStringW(hInst
, IDS_FILEDIALOG_IMPORT_TITLE
, title
, COUNT_OF(title
));
363 ofn
.lpstrTitle
= title
;
364 if (GetOpenFileNameW(&ofn
)) {
365 if (!import_registry_filename(ofn
.lpstrFile
)) {
366 messagebox(hWnd
, MB_OK
|MB_ICONERROR
, IDS_APP_TITLE
, IDS_IMPORT_FAILED
, ofn
.lpstrFile
);
369 messagebox(hWnd
, MB_OK
|MB_ICONINFORMATION
, IDS_APP_TITLE
,
370 IDS_IMPORT_SUCCESSFUL
, ofn
.lpstrFile
);
373 CheckCommDlgError(hWnd
);
375 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
377 key_path
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &root_key
);
378 RefreshListView(g_pChildWnd
->hListWnd
, root_key
, key_path
, NULL
);
379 HeapFree(GetProcessHeap(), 0, key_path
);
385 static BOOL
ExportRegistryFile(HWND hWnd
)
390 InitOpenFileName(hWnd
, &ofn
);
391 LoadStringW(hInst
, IDS_FILEDIALOG_EXPORT_TITLE
, title
, COUNT_OF(title
));
392 ofn
.lpstrTitle
= title
;
393 ofn
.Flags
= OFN_ENABLETEMPLATE
| OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
;
394 ofn
.lpfnHook
= ExportRegistryFile_OFNHookProc
;
395 ofn
.lpTemplateName
= MAKEINTRESOURCEW(IDD_EXPORT_TEMPLATE
);
396 if (GetSaveFileNameW(&ofn
)) {
398 result
= export_registry_key(ofn
.lpstrFile
, (LPWSTR
)ofn
.lCustData
, ofn
.nFilterIndex
);
400 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
404 CheckCommDlgError(hWnd
);
409 static BOOL
PrintRegistryHive(HWND hWnd
, LPCWSTR path
)
414 ZeroMemory(&pd
, sizeof(PRINTDLGW
));
415 pd
.lStructSize
= sizeof(PRINTDLGW
);
417 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
418 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
419 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
421 pd
.nFromPage
= 0xFFFF;
424 pd
.nMaxPage
= 0xFFFF;
425 if (PrintDlgW(&pd
)) {
426 FIXME("printing is not yet implemented.\n");
427 /* GDI calls to render output. */
428 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
434 hResult
= PrintDlgExW(&pd
);
435 if (hResult
== S_OK
) {
436 switch (pd
.dwResultAction
) {
437 case PD_RESULT_APPLY
:
438 /*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. */
439 FIXME("printing is not yet implemented.\n");
441 case PD_RESULT_CANCEL
:
442 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
444 case PD_RESULT_PRINT
:
445 FIXME("printing is not yet implemented.\n");
446 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
454 /*Insufficient memory. */
457 /* One or more arguments are invalid. */
460 /*Invalid pointer. */
466 /*Unspecified error. */
477 static BOOL
CopyKeyName(HWND hWnd
, LPCWSTR keyName
)
481 result
= OpenClipboard(hWnd
);
483 result
= EmptyClipboard();
485 int len
= (lstrlenW(keyName
)+1)*sizeof(WCHAR
);
486 HANDLE hClipData
= GlobalAlloc(GHND
, len
);
487 LPVOID pLoc
= GlobalLock(hClipData
);
488 lstrcpyW(pLoc
, keyName
);
489 GlobalUnlock(hClipData
);
490 SetClipboardData(CF_UNICODETEXT
, hClipData
);
493 /* error emptying clipboard*/
494 /* DWORD dwError = GetLastError(); */
497 if (!CloseClipboard()) {
498 /* error closing clipboard*/
499 /* DWORD dwError = GetLastError(); */
503 /* error opening clipboard*/
504 /* DWORD dwError = GetLastError(); */
510 static INT_PTR CALLBACK
find_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
512 HWND hwndValue
= GetDlgItem(hwndDlg
, IDC_VALUE_NAME
);
516 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
517 CheckDlgButton(hwndDlg
, IDC_FIND_KEYS
, searchMask
&SEARCH_KEYS
? BST_CHECKED
: BST_UNCHECKED
);
518 CheckDlgButton(hwndDlg
, IDC_FIND_VALUES
, searchMask
&SEARCH_VALUES
? BST_CHECKED
: BST_UNCHECKED
);
519 CheckDlgButton(hwndDlg
, IDC_FIND_CONTENT
, searchMask
&SEARCH_CONTENT
? BST_CHECKED
: BST_UNCHECKED
);
520 CheckDlgButton(hwndDlg
, IDC_FIND_WHOLE
, searchMask
&SEARCH_WHOLE
? BST_CHECKED
: BST_UNCHECKED
);
521 SendMessageW(hwndValue
, EM_SETLIMITTEXT
, 127, 0);
522 SetWindowTextW(hwndValue
, searchString
);
525 switch(LOWORD(wParam
)) {
527 if (HIWORD(wParam
) == EN_UPDATE
) {
528 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), GetWindowTextLengthW(hwndValue
)>0);
533 if (GetWindowTextLengthW(hwndValue
)>0) {
535 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_KEYS
)) mask
|= SEARCH_KEYS
;
536 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_VALUES
)) mask
|= SEARCH_VALUES
;
537 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_CONTENT
)) mask
|= SEARCH_CONTENT
;
538 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_WHOLE
)) mask
|= SEARCH_WHOLE
;
540 GetWindowTextW(hwndValue
, searchString
, 128);
541 EndDialog(hwndDlg
, IDOK
);
545 EndDialog(hwndDlg
, IDCANCEL
);
553 static INT_PTR CALLBACK
addtofavorites_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
555 HWND hwndValue
= GetDlgItem(hwndDlg
, IDC_VALUE_NAME
);
560 HKEY hKeyRoot
= NULL
;
561 LPWSTR ItemPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, NULL
, &hKeyRoot
);
563 if(!ItemPath
|| !*ItemPath
)
564 ItemPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
565 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
566 SetWindowTextW(hwndValue
, ItemPath
);
567 SendMessageW(hwndValue
, EM_SETLIMITTEXT
, 127, 0);
568 HeapFree(GetProcessHeap(), 0, ItemPath
);
572 switch(LOWORD(wParam
)) {
574 if (HIWORD(wParam
) == EN_UPDATE
) {
575 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), GetWindowTextLengthW(hwndValue
) > 0);
580 if (GetWindowTextLengthW(hwndValue
)>0) {
581 GetWindowTextW(hwndValue
, favoriteName
, 128);
582 EndDialog(hwndDlg
, IDOK
);
586 EndDialog(hwndDlg
, IDCANCEL
);
594 static INT_PTR CALLBACK
removefavorite_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
596 HWND hwndList
= GetDlgItem(hwndDlg
, IDC_NAME_LIST
);
599 case WM_INITDIALOG
: {
602 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
603 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
604 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
605 WCHAR namebuf
[KEY_MAX_LEN
];
607 DWORD ksize
, vsize
, type
;
611 vsize
= sizeof(valuebuf
);
612 error
= RegEnumValueW(hKey
, i
, namebuf
, &ksize
, NULL
, &type
, valuebuf
, &vsize
);
613 if (error
!= ERROR_SUCCESS
)
615 if (type
== REG_SZ
) {
616 SendMessageW(hwndList
, LB_ADDSTRING
, 0, (LPARAM
)namebuf
);
619 } while(error
== ERROR_SUCCESS
);
624 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), i
!= 0);
625 SendMessageW(hwndList
, LB_SETCURSEL
, 0, 0);
629 switch(LOWORD(wParam
)) {
631 if (HIWORD(wParam
) == LBN_SELCHANGE
) {
632 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), lParam
!= -1);
637 int pos
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
638 int len
= SendMessageW(hwndList
, LB_GETTEXTLEN
, pos
, 0);
640 LPWSTR lpName
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
641 SendMessageW(hwndList
, LB_GETTEXT
, pos
, (LPARAM
)lpName
);
644 lstrcpyW(favoriteName
, lpName
);
645 EndDialog(hwndDlg
, IDOK
);
646 HeapFree(GetProcessHeap(), 0, lpName
);
651 EndDialog(hwndDlg
, IDCANCEL
);
659 /*******************************************************************************
661 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
663 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
666 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
671 BOOL firstItem
= TRUE
;
673 if (LOWORD(wParam
) >= ID_FAVORITE_FIRST
&& LOWORD(wParam
) <= ID_FAVORITE_LAST
) {
675 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
676 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
677 WCHAR namebuf
[KEY_MAX_LEN
];
679 DWORD ksize
= KEY_MAX_LEN
, vsize
= sizeof(valuebuf
), type
= 0;
680 if (RegEnumValueW(hKey
, LOWORD(wParam
) - ID_FAVORITE_FIRST
, namebuf
, &ksize
, NULL
,
681 &type
, valuebuf
, &vsize
) == ERROR_SUCCESS
) {
682 SendMessageW( g_pChildWnd
->hTreeWnd
, TVM_SELECTITEM
, TVGN_CARET
,
683 (LPARAM
) FindPathInTree(g_pChildWnd
->hTreeWnd
, (WCHAR
*)valuebuf
) );
689 switch (LOWORD(wParam
)) {
690 case ID_REGISTRY_IMPORTREGISTRYFILE
:
691 ImportRegistryFile(hWnd
);
694 case ID_REGISTRY_EXPORTREGISTRYFILE
:
695 ExportRegistryFile(hWnd
);
697 case ID_REGISTRY_PRINT
:
699 const WCHAR empty
= 0;
700 PrintRegistryHive(hWnd
, &empty
);
705 HWND hWndDelete
= GetFocus();
706 if (hWndDelete
== g_pChildWnd
->hTreeWnd
) {
707 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
708 if (keyPath
== 0 || *keyPath
== 0) {
709 MessageBeep(MB_ICONHAND
);
710 } else if (DeleteKey(hWnd
, hKeyRoot
, keyPath
)) {
711 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
713 HeapFree(GetProcessHeap(), 0, keyPath
);
714 } else if (hWndDelete
== g_pChildWnd
->hListWnd
) {
715 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
716 curIndex
= SendMessageW(g_pChildWnd
->hListWnd
, LVM_GETNEXTITEM
, -1, MAKELPARAM(LVNI_SELECTED
, 0));
717 while(curIndex
!= -1) {
718 WCHAR
* valueName
= GetItemText(g_pChildWnd
->hListWnd
, curIndex
);
720 curIndex
= SendMessageW(g_pChildWnd
->hListWnd
, LVM_GETNEXTITEM
, curIndex
, MAKELPARAM(LVNI_SELECTED
, 0));
721 if(curIndex
!= -1 && firstItem
) {
722 if (MessageBoxW(hWnd
, MAKEINTRESOURCEW(IDS_DELETE_BOX_TEXT_MULTIPLE
),
723 MAKEINTRESOURCEW(IDS_DELETE_BOX_TITLE
),
724 MB_YESNO
| MB_ICONEXCLAMATION
) != IDYES
)
728 if (!DeleteValue(hWnd
, hKeyRoot
, keyPath
, valueName
, curIndex
==-1 && firstItem
))
730 HeapFree(GetProcessHeap(), 0, valueName
);
734 HeapFree(GetProcessHeap(), 0, valueName
);
736 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, NULL
);
737 HeapFree(GetProcessHeap(), 0, keyPath
);
738 } else if (IsChild(g_pChildWnd
->hTreeWnd
, hWndDelete
) ||
739 IsChild(g_pChildWnd
->hListWnd
, hWndDelete
)) {
740 SendMessageW(hWndDelete
, WM_KEYDOWN
, VK_DELETE
, 0);
745 case ID_EDIT_MODIFY_BIN
:
747 LPCWSTR valueName
= GetValueName(g_pChildWnd
->hListWnd
);
748 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
749 if (ModifyValue(hWnd
, hKeyRoot
, keyPath
, valueName
))
750 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, valueName
);
751 HeapFree(GetProcessHeap(), 0, keyPath
);
755 case ID_EDIT_FINDNEXT
:
758 if (LOWORD(wParam
) == ID_EDIT_FIND
&&
759 DialogBoxW(0, MAKEINTRESOURCEW(IDD_FIND
), hWnd
, find_dlgproc
) != IDOK
)
763 hItem
= (HTREEITEM
)SendMessageW(g_pChildWnd
->hTreeWnd
, TVM_GETNEXTITEM
, TVGN_CARET
, 0);
765 int row
= SendMessageW(g_pChildWnd
->hListWnd
, LVM_GETNEXTITEM
, -1, MAKELPARAM(LVNI_FOCUSED
, 0));
766 HCURSOR hcursorOld
= SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_WAIT
));
767 hItem
= FindNext(g_pChildWnd
->hTreeWnd
, hItem
, searchString
, searchMask
, &row
);
768 SetCursor(hcursorOld
);
770 SendMessageW( g_pChildWnd
->hTreeWnd
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
) hItem
);
771 InvalidateRect(g_pChildWnd
->hTreeWnd
, NULL
, TRUE
);
772 UpdateWindow(g_pChildWnd
->hTreeWnd
);
777 item
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
778 SendMessageW(g_pChildWnd
->hListWnd
, LVM_SETITEMSTATE
, (UINT
)-1, (LPARAM
)&item
);
780 item
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
781 item
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
782 SendMessageW(g_pChildWnd
->hListWnd
, LVM_SETITEMSTATE
, row
, (LPARAM
)&item
);
783 SetFocus(g_pChildWnd
->hListWnd
);
785 SetFocus(g_pChildWnd
->hTreeWnd
);
788 messagebox(hWnd
, MB_OK
|MB_ICONINFORMATION
, IDS_APP_TITLE
, IDS_NOTFOUND
, searchString
);
793 case ID_EDIT_COPYKEYNAME
:
795 LPWSTR fullPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
797 CopyKeyName(hWnd
, fullPath
);
798 HeapFree(GetProcessHeap(), 0, fullPath
);
802 case ID_EDIT_NEW_KEY
:
804 WCHAR newKeyW
[MAX_NEW_KEY_LEN
];
805 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
806 if (CreateKey(hWnd
, hKeyRoot
, keyPath
, newKeyW
)) {
807 if (InsertNode(g_pChildWnd
->hTreeWnd
, 0, newKeyW
))
808 StartKeyRename(g_pChildWnd
->hTreeWnd
);
810 HeapFree(GetProcessHeap(), 0, keyPath
);
813 case ID_EDIT_NEW_STRINGVALUE
:
816 case ID_EDIT_NEW_EXPANDVALUE
:
817 valueType
= REG_EXPAND_SZ
;
819 case ID_EDIT_NEW_MULTI_STRINGVALUE
:
820 valueType
= REG_MULTI_SZ
;
822 case ID_EDIT_NEW_BINARYVALUE
:
823 valueType
= REG_BINARY
;
825 case ID_EDIT_NEW_DWORDVALUE
:
826 valueType
= REG_DWORD
;
830 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
831 WCHAR newKey
[MAX_NEW_KEY_LEN
];
832 if (CreateValue(hWnd
, hKeyRoot
, keyPath
, valueType
, newKey
)) {
833 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, newKey
);
834 StartValueRename(g_pChildWnd
->hListWnd
);
836 HeapFree(GetProcessHeap(), 0, keyPath
);
841 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
842 if (keyPath
== 0 || *keyPath
== 0) {
843 MessageBeep(MB_ICONHAND
);
844 } else if (GetFocus() == g_pChildWnd
->hTreeWnd
) {
845 StartKeyRename(g_pChildWnd
->hTreeWnd
);
846 } else if (GetFocus() == g_pChildWnd
->hListWnd
) {
847 StartValueRename(g_pChildWnd
->hListWnd
);
849 HeapFree(GetProcessHeap(), 0, keyPath
);
852 case ID_REGISTRY_PRINTERSETUP
:
855 /*PAGESETUPDLG psd;*/
856 /*PageSetupDlg(&psd);*/
858 case ID_REGISTRY_OPENLOCAL
:
860 case ID_REGISTRY_EXIT
:
863 case ID_FAVORITES_ADDTOFAVORITES
:
866 LPWSTR lpKeyPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
868 if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_ADDFAVORITE
), hWnd
, addtofavorites_dlgproc
) == IDOK
) {
869 if (RegCreateKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
871 KEY_READ
|KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
) {
872 RegSetValueExW(hKey
, favoriteName
, 0, REG_SZ
, (BYTE
*)lpKeyPath
, (lstrlenW(lpKeyPath
)+1)*sizeof(WCHAR
));
876 HeapFree(GetProcessHeap(), 0, lpKeyPath
);
880 case ID_FAVORITES_REMOVEFAVORITE
:
882 if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_DELFAVORITE
), hWnd
, removefavorite_dlgproc
) == IDOK
) {
884 if (RegOpenKeyExW(HKEY_CURRENT_USER
, favoritesKey
,
885 0, KEY_READ
|KEY_WRITE
, &hKey
) == ERROR_SUCCESS
) {
886 RegDeleteValueW(hKey
, favoriteName
);
892 case ID_VIEW_REFRESH
:
894 WCHAR
* keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
895 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
896 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, NULL
);
897 HeapFree(GetProcessHeap(), 0, keyPath
);
900 /*case ID_OPTIONS_TOOLBAR:*/
901 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
903 case ID_VIEW_STATUSBAR
:
904 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
906 case ID_HELP_HELPTOPICS
:
908 const WCHAR help_regedit
[] = {'r','e','g','e','d','i','t',0};
909 WinHelpW(hWnd
, help_regedit
, HELP_FINDER
, 0);
915 case ID_VIEW_SPLIT
: {
918 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
919 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
920 pt
.y
= (rt
.bottom
/ 2);
922 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
)) {
923 SetCursorPos(pts
.x
, pts
.y
);
924 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_SIZEWE
));
925 SendMessageW(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
936 /********************************************************************************
938 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
940 * PURPOSE: Processes messages for the main frame window.
942 * WM_COMMAND - process the application menu
943 * WM_DESTROY - post a quit message and return
947 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
949 static const WCHAR captionW
[] = {'r','e','g','e','d','i','t',' ','c','h','i','l','d',' ','w','i','n','d','o','w',0};
953 CreateWindowExW(0, szChildClass
, captionW
, WS_CHILD
| WS_VISIBLE
,
954 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
955 hWnd
, NULL
, hInst
, 0);
958 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
959 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
963 SetFocus(g_pChildWnd
->hWnd
);
966 resize_frame_client(hWnd
);
970 case WM_ENTERMENULOOP
:
971 OnEnterMenuLoop(hWnd
);
973 case WM_EXITMENULOOP
:
974 OnExitMenuLoop(hWnd
);
976 case WM_INITMENUPOPUP
:
978 OnInitMenuPopup(hWnd
, (HMENU
)wParam
, LOWORD(lParam
));
981 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
985 const WCHAR help_regedit
[] = {'r','e','g','e','d','i','t',0};
986 WinHelpW(hWnd
, help_regedit
, HELP_QUIT
, 0);
990 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);