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
21 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
35 /********************************************************************************
36 * Global and Local Variables:
39 static TCHAR favoritesKey
[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\RegEdit\\Favorites");
40 static BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
41 static TCHAR favoriteName
[128];
42 static TCHAR searchString
[128];
43 static int searchMask
= SEARCH_KEYS
| SEARCH_VALUES
| SEARCH_CONTENT
;
45 /*******************************************************************************
46 * Local module support methods
49 static void resize_frame_rect(HWND hWnd
, PRECT prect
)
53 if (IsWindowVisible(hToolBar)) {
54 SendMessage(hToolBar, WM_SIZE, 0, 0);
55 GetClientRect(hToolBar, &rt);
56 prect->top = rt.bottom+3;
57 prect->bottom -= rt.bottom+3;
60 if (IsWindowVisible(hStatusBar
)) {
61 SetupStatusBar(hWnd
, TRUE
);
62 GetClientRect(hStatusBar
, &rt
);
63 prect
->bottom
-= rt
.bottom
;
65 MoveWindow(g_pChildWnd
->hWnd
, prect
->left
, prect
->top
, prect
->right
, prect
->bottom
, TRUE
);
68 static void resize_frame_client(HWND hWnd
)
72 GetClientRect(hWnd
, &rect
);
73 resize_frame_rect(hWnd
, &rect
);
76 /********************************************************************************/
78 static void OnEnterMenuLoop(HWND hWnd
)
82 /* Update the status bar pane sizes */
84 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (long)&nParts
);
86 SendMessage(hStatusBar
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)_T(""));
89 static void OnExitMenuLoop(HWND hWnd
)
92 /* Update the status bar pane sizes*/
93 SetupStatusBar(hWnd
, TRUE
);
97 static void UpdateMenuItems(HMENU hMenu
) {
98 HWND hwndTV
= g_pChildWnd
->hTreeWnd
;
99 BOOL bIsKeySelected
= FALSE
;
100 HKEY hRootKey
= NULL
;
102 keyName
= GetItemPath(hwndTV
, TreeView_GetSelection(hwndTV
), &hRootKey
);
103 if (keyName
&& *keyName
) { /* can't modify root keys */
104 bIsKeySelected
= TRUE
;
106 EnableMenuItem(hMenu
, ID_EDIT_FIND
, MF_ENABLED
| MF_BYCOMMAND
);
107 EnableMenuItem(hMenu
, ID_EDIT_FINDNEXT
, MF_ENABLED
| MF_BYCOMMAND
);
108 EnableMenuItem(hMenu
, ID_EDIT_MODIFY
, (bIsKeySelected
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
109 EnableMenuItem(hMenu
, ID_EDIT_DELETE
, (bIsKeySelected
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
110 EnableMenuItem(hMenu
, ID_EDIT_RENAME
, (bIsKeySelected
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
111 EnableMenuItem(hMenu
, ID_FAVORITES_ADDTOFAVORITES
, (hRootKey
? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
112 EnableMenuItem(hMenu
, ID_FAVORITES_REMOVEFAVORITE
,
113 (GetMenuItemCount(hMenu
)>2 ? MF_ENABLED
: MF_GRAYED
) | MF_BYCOMMAND
);
116 static void OnInitMenuPopup(HWND hWnd
, HMENU hMenu
, short wItem
)
120 while(GetMenuItemCount(hMenu
)>2)
121 DeleteMenu(hMenu
, 2, MF_BYPOSITION
);
122 if (RegOpenKeyEx(HKEY_CURRENT_USER
, favoritesKey
,
123 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
124 TCHAR namebuf
[KEY_MAX_LEN
];
128 DWORD ksize
, vsize
, type
;
132 vsize
= sizeof(valuebuf
);
133 error
= RegEnumValue(hKey
, i
, namebuf
, &ksize
, NULL
, &type
, valuebuf
, &vsize
);
134 if (error
!= ERROR_SUCCESS
)
136 if (type
== REG_SZ
) {
138 AppendMenu(hMenu
, MF_SEPARATOR
, -1, NULL
);
141 AppendMenu(hMenu
, MF_STRING
, ID_FAVORITE_FIRST
+i
, namebuf
);
144 } while(error
== ERROR_SUCCESS
);
148 UpdateMenuItems(hMenu
);
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
);
185 void UpdateStatusBar(void)
187 LPTSTR fullPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, TRUE
);
188 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)fullPath
);
189 HeapFree(GetProcessHeap(), 0, fullPath
);
192 static void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
194 BOOL vis
= IsWindowVisible(hchild
);
195 HMENU hMenuView
= GetSubMenu(hMenuFrame
, ID_VIEW_MENU
);
197 CheckMenuItem(hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
198 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
199 resize_frame_client(hWnd
);
202 static BOOL
CheckCommDlgError(HWND hWnd
)
204 DWORD dwErrorCode
= CommDlgExtendedError();
205 switch (dwErrorCode
) {
206 case CDERR_DIALOGFAILURE
:
208 case CDERR_FINDRESFAILURE
:
210 case CDERR_NOHINSTANCE
:
212 case CDERR_INITIALIZATION
:
216 case CDERR_LOCKRESFAILURE
:
218 case CDERR_NOTEMPLATE
:
220 case CDERR_LOADRESFAILURE
:
222 case CDERR_STRUCTSIZE
:
224 case CDERR_LOADSTRFAILURE
:
226 case FNERR_BUFFERTOOSMALL
:
228 case CDERR_MEMALLOCFAILURE
:
230 case FNERR_INVALIDFILENAME
:
232 case CDERR_MEMLOCKFAILURE
:
234 case FNERR_SUBCLASSFAILURE
:
242 static UINT_PTR CALLBACK
ImportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
244 OPENFILENAME
* pOpenFileName
;
249 pOpenFileName
= (OPENFILENAME
*)lParam
;
252 pOfNotify
= (OFNOTIFY
*)lParam
;
253 if (pOfNotify
->hdr
.code
== CDN_INITDONE
) {}
261 #define MAX_CUSTOM_FILTER_SIZE 50
262 TCHAR CustomFilterBuffer
[MAX_CUSTOM_FILTER_SIZE
];
263 TCHAR FileNameBuffer
[_MAX_PATH
];
264 TCHAR FileTitleBuffer
[_MAX_PATH
];
266 static BOOL
InitOpenFileName(HWND hWnd
, OPENFILENAME
* pofn
)
268 memset(pofn
, 0, sizeof(OPENFILENAME
));
269 pofn
->lStructSize
= sizeof(OPENFILENAME
);
270 pofn
->hwndOwner
= hWnd
;
271 pofn
->hInstance
= hInst
;
273 pofn
->lpstrFilter
= _T("Registration Files\0*.reg\0Win9x/NT4 Registration Files (REGEDIT4)\0*.reg\0All Files (*.*)\0*.*\0\0");
274 pofn
->lpstrCustomFilter
= CustomFilterBuffer
;
275 pofn
->nMaxCustFilter
= MAX_CUSTOM_FILTER_SIZE
;
276 pofn
->nFilterIndex
= 0;
277 pofn
->lpstrFile
= FileNameBuffer
;
278 pofn
->nMaxFile
= _MAX_PATH
;
279 pofn
->lpstrFileTitle
= FileTitleBuffer
;
280 pofn
->nMaxFileTitle
= _MAX_PATH
;
281 /* pofn->lpstrInitialDir = _T("");*/
282 /* pofn->lpstrTitle = _T("Import Registry File");*/
283 /* pofn->Flags = OFN_ENABLETEMPLATE + OFN_EXPLORER + OFN_ENABLESIZING;*/
284 pofn
->Flags
= OFN_HIDEREADONLY
;
285 /* pofn->nFileOffset = ;*/
286 /* pofn->nFileExtension = ;*/
287 /* pofn->lpstrDefExt = _T("");*/
288 /* pofn->lCustData = ;*/
289 /* pofn->lpfnHook = ImportRegistryFile_OFNHookProc;*/
290 /* pofn->lpTemplateName = _T("ID_DLG_IMPORT_REGFILE");*/
291 /* pofn->lpTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);*/
292 /* pofn->FlagsEx = ;*/
296 static BOOL
ImportRegistryFile(HWND hWnd
)
300 InitOpenFileName(hWnd
, &ofn
);
301 ofn
.lpstrTitle
= _T("Import Registry File");
302 /* ofn.lCustData = ;*/
303 if (GetOpenFileName(&ofn
)) {
304 if (!import_registry_file(ofn
.lpstrFile
)) {
305 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
309 get_file_name(&s
, filename
, MAX_PATH
);
311 printf("No file name is specified\n%s", usage
);
315 while (filename
[0]) {
316 if (!import_registry_file(filename
)) {
318 printf("Can't open file \"%s\"\n", filename
);
322 get_file_name(&s
, filename
, MAX_PATH
);
327 CheckCommDlgError(hWnd
);
333 static BOOL
ExportRegistryFile(HWND hWnd
)
336 TCHAR ExportKeyPath
[_MAX_PATH
];
338 ExportKeyPath
[0] = _T('\0');
339 InitOpenFileName(hWnd
, &ofn
);
340 ofn
.lpstrTitle
= _T("Export Registry File");
341 /* ofn.lCustData = ;*/
342 ofn
.Flags
= OFN_ENABLETEMPLATE
+ OFN_EXPLORER
;
343 ofn
.lpfnHook
= ImportRegistryFile_OFNHookProc
;
344 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_DIALOG1
);
345 if (GetSaveFileName(&ofn
)) {
347 result
= export_registry_key(ofn
.lpstrFile
, ExportKeyPath
);
348 /*result = export_registry_key(ofn.lpstrFile, NULL);*/
349 /*if (!export_registry_key(ofn.lpstrFile, NULL)) {*/
351 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
355 TCHAR filename
[MAX_PATH
];
357 get_file_name(&s
, filename
, MAX_PATH
);
359 printf("No file name is specified\n%s", usage
);
364 TCHAR reg_key_name
[KEY_MAX_LEN
];
365 get_file_name(&s
, reg_key_name
, KEY_MAX_LEN
);
366 export_registry_key(filename
, reg_key_name
);
368 export_registry_key(filename
, NULL
);
373 CheckCommDlgError(hWnd
);
378 static BOOL
PrintRegistryHive(HWND hWnd
, LPCTSTR 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;
395 /* GDI calls to render output. */
396 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
402 hResult
= PrintDlgEx(&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
, LPCTSTR keyName
)
447 result
= OpenClipboard(hWnd
);
449 result
= EmptyClipboard();
451 int len
= (_tcslen(keyName
)+1)*sizeof(TCHAR
);
452 HANDLE hClipData
= GlobalAlloc(GHND
, len
);
453 LPVOID pLoc
= GlobalLock(hClipData
);
454 _tcscpy(pLoc
, keyName
);
455 GlobalUnlock(hClipData
);
456 hClipData
= SetClipboardData(CF_TEXT
, 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 SendMessage(hwndValue
, EM_SETLIMITTEXT
, 127, 0);
488 SetWindowText(hwndValue
, searchString
);
491 switch(LOWORD(wParam
)) {
493 if (HIWORD(wParam
) == EN_UPDATE
) {
494 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), GetWindowTextLength(hwndValue
)>0);
499 if (GetWindowTextLength(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 GetWindowText(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
);
525 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
526 SendMessage(hwndValue
, EM_SETLIMITTEXT
, 127, 0);
529 switch(LOWORD(wParam
)) {
531 if (HIWORD(wParam
) == EN_UPDATE
) {
532 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), GetWindowTextLength(hwndValue
)>0);
537 if (GetWindowTextLength(hwndValue
)>0) {
538 GetWindowText(hwndValue
, favoriteName
, 128);
539 EndDialog(hwndDlg
, IDOK
);
543 EndDialog(hwndDlg
, IDCANCEL
);
551 static INT_PTR CALLBACK
removefavorite_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
553 HWND hwndList
= GetDlgItem(hwndDlg
, IDC_NAME_LIST
);
556 case WM_INITDIALOG
: {
559 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
560 if (RegOpenKeyEx(HKEY_CURRENT_USER
, favoritesKey
,
561 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
562 TCHAR namebuf
[KEY_MAX_LEN
];
564 DWORD ksize
, vsize
, type
;
568 vsize
= sizeof(valuebuf
);
569 error
= RegEnumValue(hKey
, i
, namebuf
, &ksize
, NULL
, &type
, valuebuf
, &vsize
);
570 if (error
!= ERROR_SUCCESS
)
572 if (type
== REG_SZ
) {
573 SendMessage(hwndList
, LB_ADDSTRING
, 0, (LPARAM
)namebuf
);
576 } while(error
== ERROR_SUCCESS
);
581 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), i
!= 0);
582 SendMessage(hwndList
, LB_SETCURSEL
, 0, 0);
586 switch(LOWORD(wParam
)) {
588 if (HIWORD(wParam
) == LBN_SELCHANGE
) {
589 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), lParam
!= -1);
594 int pos
= SendMessage(hwndList
, LB_GETCURSEL
, 0, 0);
595 int len
= SendMessage(hwndList
, LB_GETTEXTLEN
, pos
, 0);
597 LPTSTR lpName
= HeapAlloc(GetProcessHeap(), 0, sizeof(TCHAR
)*(len
+1));
598 SendMessage(hwndList
, LB_GETTEXT
, pos
, (LPARAM
)lpName
);
601 _tcscpy(favoriteName
, lpName
);
602 EndDialog(hwndDlg
, IDOK
);
603 HeapFree(GetProcessHeap(), 0, lpName
);
608 EndDialog(hwndDlg
, IDCANCEL
);
616 /*******************************************************************************
618 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
620 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
623 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
628 TCHAR newKey
[MAX_NEW_KEY_LEN
];
631 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
632 valueName
= GetValueName(g_pChildWnd
->hListWnd
);
634 if (LOWORD(wParam
) >= ID_FAVORITE_FIRST
&& LOWORD(wParam
) <= ID_FAVORITE_LAST
) {
636 if (RegOpenKeyEx(HKEY_CURRENT_USER
, favoritesKey
,
637 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
638 TCHAR namebuf
[KEY_MAX_LEN
];
640 DWORD ksize
= KEY_MAX_LEN
, vsize
= sizeof(valuebuf
), type
= 0;
641 if (RegEnumValue(hKey
, LOWORD(wParam
) - ID_FAVORITE_FIRST
, namebuf
, &ksize
, NULL
,
642 &type
, valuebuf
, &vsize
) == ERROR_SUCCESS
) {
643 SendMessage( g_pChildWnd
->hTreeWnd
, TVM_SELECTITEM
, TVGN_CARET
,
644 (LPARAM
) FindPathInTree(g_pChildWnd
->hTreeWnd
, (TCHAR
*)valuebuf
) );
650 switch (LOWORD(wParam
)) {
651 case ID_REGISTRY_IMPORTREGISTRYFILE
:
652 ImportRegistryFile(hWnd
);
654 case ID_REGISTRY_EXPORTREGISTRYFILE
:
655 ExportRegistryFile(hWnd
);
657 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
659 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
661 case ID_REGISTRY_PRINT
:
662 PrintRegistryHive(hWnd
, _T(""));
665 if (GetFocus() == g_pChildWnd
->hTreeWnd
) {
666 if (keyPath
== 0 || *keyPath
== 0) {
667 MessageBeep(MB_ICONHAND
);
668 } else if (DeleteKey(hWnd
, hKeyRoot
, keyPath
)) {
669 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
671 } else if (GetFocus() == g_pChildWnd
->hListWnd
) {
672 if (DeleteValue(hWnd
, hKeyRoot
, keyPath
, valueName
))
673 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, NULL
);
677 if (ModifyValue(hWnd
, hKeyRoot
, keyPath
, valueName
))
678 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, valueName
);
681 case ID_EDIT_FINDNEXT
:
684 if (LOWORD(wParam
) == ID_EDIT_FIND
&&
685 DialogBox(0, MAKEINTRESOURCE(IDD_FIND
), hWnd
, find_dlgproc
) != IDOK
)
689 hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
691 int row
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
);
692 HCURSOR hcursorOld
= SetCursor(LoadCursor(NULL
, IDC_WAIT
));
693 hItem
= FindNext(g_pChildWnd
->hTreeWnd
, hItem
, searchString
, searchMask
, &row
);
694 SetCursor(hcursorOld
);
696 SendMessage( g_pChildWnd
->hTreeWnd
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
) hItem
);
697 InvalidateRect(g_pChildWnd
->hTreeWnd
, NULL
, TRUE
);
698 UpdateWindow(g_pChildWnd
->hTreeWnd
);
700 ListView_SetItemState(g_pChildWnd
->hListWnd
, -1, 0, LVIS_FOCUSED
|LVIS_SELECTED
);
701 ListView_SetItemState(g_pChildWnd
->hListWnd
, row
, LVIS_FOCUSED
|LVIS_SELECTED
, LVIS_FOCUSED
|LVIS_SELECTED
);
702 SetFocus(g_pChildWnd
->hListWnd
);
704 SetFocus(g_pChildWnd
->hTreeWnd
);
707 error(hWnd
, IDS_NOTFOUND
, searchString
);
712 case ID_EDIT_COPYKEYNAME
:
714 LPTSTR fullPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
716 CopyKeyName(hWnd
, fullPath
);
717 HeapFree(GetProcessHeap(), 0, fullPath
);
721 case ID_EDIT_NEW_KEY
:
722 if (CreateKey(hWnd
, hKeyRoot
, keyPath
, newKey
)) {
723 if (InsertNode(g_pChildWnd
->hTreeWnd
, 0, newKey
))
724 StartKeyRename(g_pChildWnd
->hTreeWnd
);
727 case ID_EDIT_NEW_STRINGVALUE
:
730 case ID_EDIT_NEW_BINARYVALUE
:
731 valueType
= REG_BINARY
;
733 case ID_EDIT_NEW_DWORDVALUE
:
734 valueType
= REG_DWORD
;
737 if (CreateValue(hWnd
, hKeyRoot
, keyPath
, valueType
, newKey
)) {
738 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, newKey
);
739 StartValueRename(g_pChildWnd
->hListWnd
);
740 /* FIXME: start rename */
744 if (keyPath
== 0 || *keyPath
== 0) {
745 MessageBeep(MB_ICONHAND
);
746 } else if (GetFocus() == g_pChildWnd
->hTreeWnd
) {
747 StartKeyRename(g_pChildWnd
->hTreeWnd
);
748 } else if (GetFocus() == g_pChildWnd
->hListWnd
) {
749 StartValueRename(g_pChildWnd
->hListWnd
);
753 case ID_REGISTRY_PRINTERSETUP
:
756 /*PAGESETUPDLG psd;*/
757 /*PageSetupDlg(&psd);*/
759 case ID_REGISTRY_OPENLOCAL
:
761 case ID_REGISTRY_EXIT
:
764 case ID_FAVORITES_ADDTOFAVORITES
:
767 LPTSTR lpKeyPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
769 if (DialogBox(0, MAKEINTRESOURCE(IDD_ADDFAVORITE
), hWnd
, addtofavorites_dlgproc
) == IDOK
) {
770 if (RegCreateKeyEx(HKEY_CURRENT_USER
, favoritesKey
,
772 KEY_READ
|KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
) {
773 RegSetValueEx(hKey
, favoriteName
, 0, REG_SZ
, (BYTE
*)lpKeyPath
, (_tcslen(lpKeyPath
)+1)*sizeof(TCHAR
));
777 HeapFree(GetProcessHeap(), 0, lpKeyPath
);
781 case ID_FAVORITES_REMOVEFAVORITE
:
783 if (DialogBox(0, MAKEINTRESOURCE(IDD_DELFAVORITE
), hWnd
, removefavorite_dlgproc
) == IDOK
) {
785 if (RegOpenKeyEx(HKEY_CURRENT_USER
, favoritesKey
,
786 0, KEY_READ
|KEY_WRITE
, &hKey
) == ERROR_SUCCESS
) {
787 RegDeleteValue(hKey
, favoriteName
);
793 case ID_VIEW_REFRESH
:
794 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
795 /*RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); */
797 /*case ID_OPTIONS_TOOLBAR:*/
798 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
800 case ID_VIEW_STATUSBAR
:
801 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
803 case ID_HELP_HELPTOPICS
:
804 WinHelp(hWnd
, _T("regedit"), HELP_FINDER
, 0);
809 case ID_VIEW_SPLIT
: {
812 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
813 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
814 pt
.y
= (rt
.bottom
/ 2);
816 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
)) {
817 SetCursorPos(pts
.x
, pts
.y
);
818 SetCursor(LoadCursor(0, IDC_SIZEWE
));
819 SendMessage(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
830 /********************************************************************************
832 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
834 * PURPOSE: Processes messages for the main frame window.
836 * WM_COMMAND - process the application menu
837 * WM_DESTROY - post a quit message and return
841 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
845 CreateWindowEx(0, szChildClass
, _T("regedit child window"), WS_CHILD
| WS_VISIBLE
,
846 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
847 hWnd
, NULL
, hInst
, 0);
850 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
851 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
855 SetFocus(g_pChildWnd
->hWnd
);
858 resize_frame_client(hWnd
);
862 case WM_ENTERMENULOOP
:
863 OnEnterMenuLoop(hWnd
);
865 case WM_EXITMENULOOP
:
866 OnExitMenuLoop(hWnd
);
868 case WM_INITMENUPOPUP
:
870 OnInitMenuPopup(hWnd
, (HMENU
)wParam
, LOWORD(lParam
));
873 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
876 WinHelp(hWnd
, _T("regedit"), HELP_QUIT
, 0);
879 return DefWindowProc(hWnd
, message
, wParam
, lParam
);