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 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 TCHAR FileNameBuffer
[_MAX_PATH
];
262 TCHAR FileTitleBuffer
[_MAX_PATH
];
263 TCHAR FilterBuffer
[_MAX_PATH
];
265 static BOOL
InitOpenFileName(HWND hWnd
, OPENFILENAME
*pofn
)
267 memset(pofn
, 0, sizeof(OPENFILENAME
));
268 pofn
->lStructSize
= sizeof(OPENFILENAME
);
269 pofn
->hwndOwner
= hWnd
;
270 pofn
->hInstance
= hInst
;
272 if (FilterBuffer
[0] == 0)
273 LoadString(hInst
, IDS_FILEDIALOG_FILTER
, FilterBuffer
, _MAX_PATH
);
274 pofn
->lpstrFilter
= FilterBuffer
;
275 pofn
->nFilterIndex
= 1;
276 pofn
->lpstrFile
= FileNameBuffer
;
277 pofn
->nMaxFile
= _MAX_PATH
;
278 pofn
->lpstrFileTitle
= FileTitleBuffer
;
279 pofn
->nMaxFileTitle
= _MAX_PATH
;
280 /* pofn->lpstrInitialDir = _T("");*/
281 /* pofn->lpstrTitle = _T("Import Registry File");*/
282 /* pofn->Flags = OFN_ENABLETEMPLATE + OFN_EXPLORER + OFN_ENABLESIZING;*/
283 pofn
->Flags
= OFN_HIDEREADONLY
;
284 /* pofn->nFileOffset = ;*/
285 /* pofn->nFileExtension = ;*/
286 /* pofn->lpstrDefExt = _T("");*/
287 /* pofn->lCustData = ;*/
288 /* pofn->lpfnHook = ImportRegistryFile_OFNHookProc;*/
289 /* pofn->lpTemplateName = _T("ID_DLG_IMPORT_REGFILE");*/
290 /* pofn->lpTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);*/
291 /* pofn->FlagsEx = ;*/
295 static BOOL
ImportRegistryFile(HWND hWnd
)
300 InitOpenFileName(hWnd
, &ofn
);
301 LoadString(hInst
, IDS_FILEDIALOG_IMPORT_TITLE
, title
, COUNT_OF(title
));
302 ofn
.lpstrTitle
= title
;
303 /* ofn.lCustData = ;*/
304 if (GetOpenFileName(&ofn
)) {
305 if (!import_registry_file(ofn
.lpstrFile
)) {
306 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
310 get_file_name(&s
, filename
, MAX_PATH
);
312 printf("No file name is specified\n%s", usage
);
316 while (filename
[0]) {
317 if (!import_registry_file(filename
)) {
319 printf("Can't open file \"%s\"\n", filename
);
323 get_file_name(&s
, filename
, MAX_PATH
);
328 CheckCommDlgError(hWnd
);
334 static BOOL
ExportRegistryFile(HWND hWnd
)
337 TCHAR ExportKeyPath
[_MAX_PATH
];
340 ExportKeyPath
[0] = _T('\0');
341 InitOpenFileName(hWnd
, &ofn
);
342 LoadString(hInst
, IDS_FILEDIALOG_EXPORT_TITLE
, title
, COUNT_OF(title
));
343 ofn
.lpstrTitle
= title
;
344 /* ofn.lCustData = ;*/
345 ofn
.Flags
= OFN_ENABLETEMPLATE
+ OFN_EXPLORER
;
346 ofn
.lpfnHook
= ImportRegistryFile_OFNHookProc
;
347 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_DIALOG1
);
348 if (GetSaveFileName(&ofn
)) {
350 result
= export_registry_key(ofn
.lpstrFile
, ExportKeyPath
);
351 /*result = export_registry_key(ofn.lpstrFile, NULL);*/
352 /*if (!export_registry_key(ofn.lpstrFile, NULL)) {*/
354 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
358 TCHAR filename
[MAX_PATH
];
360 get_file_name(&s
, filename
, MAX_PATH
);
362 printf("No file name is specified\n%s", usage
);
367 TCHAR reg_key_name
[KEY_MAX_LEN
];
368 get_file_name(&s
, reg_key_name
, KEY_MAX_LEN
);
369 export_registry_key(filename
, reg_key_name
);
371 export_registry_key(filename
, NULL
);
376 CheckCommDlgError(hWnd
);
381 static BOOL
PrintRegistryHive(HWND hWnd
, LPCTSTR path
)
386 ZeroMemory(&pd
, sizeof(PRINTDLG
));
387 pd
.lStructSize
= sizeof(PRINTDLG
);
389 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
390 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
391 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
393 pd
.nFromPage
= 0xFFFF;
396 pd
.nMaxPage
= 0xFFFF;
398 /* GDI calls to render output. */
399 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
405 hResult
= PrintDlgEx(&pd
);
406 if (hResult
== S_OK
) {
407 switch (pd
.dwResultAction
) {
408 case PD_RESULT_APPLY
:
409 /*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. */
411 case PD_RESULT_CANCEL
:
412 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
414 case PD_RESULT_PRINT
:
415 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
423 /*Insufficient memory. */
426 /* One or more arguments are invalid. */
429 /*Invalid pointer. */
435 /*Unspecified error. */
446 static BOOL
CopyKeyName(HWND hWnd
, LPCTSTR keyName
)
450 result
= OpenClipboard(hWnd
);
452 result
= EmptyClipboard();
454 int len
= (_tcslen(keyName
)+1)*sizeof(TCHAR
);
455 HANDLE hClipData
= GlobalAlloc(GHND
, len
);
456 LPVOID pLoc
= GlobalLock(hClipData
);
457 _tcscpy(pLoc
, keyName
);
458 GlobalUnlock(hClipData
);
459 hClipData
= SetClipboardData(CF_TEXT
, hClipData
);
462 /* error emptying clipboard*/
463 /* DWORD dwError = GetLastError(); */
466 if (!CloseClipboard()) {
467 /* error closing clipboard*/
468 /* DWORD dwError = GetLastError(); */
472 /* error opening clipboard*/
473 /* DWORD dwError = GetLastError(); */
479 static INT_PTR CALLBACK
find_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
481 HWND hwndValue
= GetDlgItem(hwndDlg
, IDC_VALUE_NAME
);
485 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
486 CheckDlgButton(hwndDlg
, IDC_FIND_KEYS
, searchMask
&SEARCH_KEYS
? BST_CHECKED
: BST_UNCHECKED
);
487 CheckDlgButton(hwndDlg
, IDC_FIND_VALUES
, searchMask
&SEARCH_VALUES
? BST_CHECKED
: BST_UNCHECKED
);
488 CheckDlgButton(hwndDlg
, IDC_FIND_CONTENT
, searchMask
&SEARCH_CONTENT
? BST_CHECKED
: BST_UNCHECKED
);
489 CheckDlgButton(hwndDlg
, IDC_FIND_WHOLE
, searchMask
&SEARCH_WHOLE
? BST_CHECKED
: BST_UNCHECKED
);
490 SendMessage(hwndValue
, EM_SETLIMITTEXT
, 127, 0);
491 SetWindowText(hwndValue
, searchString
);
494 switch(LOWORD(wParam
)) {
496 if (HIWORD(wParam
) == EN_UPDATE
) {
497 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), GetWindowTextLength(hwndValue
)>0);
502 if (GetWindowTextLength(hwndValue
)>0) {
504 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_KEYS
)) mask
|= SEARCH_KEYS
;
505 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_VALUES
)) mask
|= SEARCH_VALUES
;
506 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_CONTENT
)) mask
|= SEARCH_CONTENT
;
507 if (IsDlgButtonChecked(hwndDlg
, IDC_FIND_WHOLE
)) mask
|= SEARCH_WHOLE
;
509 GetWindowText(hwndValue
, searchString
, 128);
510 EndDialog(hwndDlg
, IDOK
);
514 EndDialog(hwndDlg
, IDCANCEL
);
522 static INT_PTR CALLBACK
addtofavorites_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
524 HWND hwndValue
= GetDlgItem(hwndDlg
, IDC_VALUE_NAME
);
528 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
529 SendMessage(hwndValue
, EM_SETLIMITTEXT
, 127, 0);
532 switch(LOWORD(wParam
)) {
534 if (HIWORD(wParam
) == EN_UPDATE
) {
535 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), GetWindowTextLength(hwndValue
)>0);
540 if (GetWindowTextLength(hwndValue
)>0) {
541 GetWindowText(hwndValue
, favoriteName
, 128);
542 EndDialog(hwndDlg
, IDOK
);
546 EndDialog(hwndDlg
, IDCANCEL
);
554 static INT_PTR CALLBACK
removefavorite_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
556 HWND hwndList
= GetDlgItem(hwndDlg
, IDC_NAME_LIST
);
559 case WM_INITDIALOG
: {
562 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), FALSE
);
563 if (RegOpenKeyEx(HKEY_CURRENT_USER
, favoritesKey
,
564 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
565 TCHAR namebuf
[KEY_MAX_LEN
];
567 DWORD ksize
, vsize
, type
;
571 vsize
= sizeof(valuebuf
);
572 error
= RegEnumValue(hKey
, i
, namebuf
, &ksize
, NULL
, &type
, valuebuf
, &vsize
);
573 if (error
!= ERROR_SUCCESS
)
575 if (type
== REG_SZ
) {
576 SendMessage(hwndList
, LB_ADDSTRING
, 0, (LPARAM
)namebuf
);
579 } while(error
== ERROR_SUCCESS
);
584 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), i
!= 0);
585 SendMessage(hwndList
, LB_SETCURSEL
, 0, 0);
589 switch(LOWORD(wParam
)) {
591 if (HIWORD(wParam
) == LBN_SELCHANGE
) {
592 EnableWindow(GetDlgItem(hwndDlg
, IDOK
), lParam
!= -1);
597 int pos
= SendMessage(hwndList
, LB_GETCURSEL
, 0, 0);
598 int len
= SendMessage(hwndList
, LB_GETTEXTLEN
, pos
, 0);
600 LPTSTR lpName
= HeapAlloc(GetProcessHeap(), 0, sizeof(TCHAR
)*(len
+1));
601 SendMessage(hwndList
, LB_GETTEXT
, pos
, (LPARAM
)lpName
);
604 _tcscpy(favoriteName
, lpName
);
605 EndDialog(hwndDlg
, IDOK
);
606 HeapFree(GetProcessHeap(), 0, lpName
);
611 EndDialog(hwndDlg
, IDCANCEL
);
619 /*******************************************************************************
621 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
623 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
626 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
631 TCHAR newKey
[MAX_NEW_KEY_LEN
];
634 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
635 valueName
= GetValueName(g_pChildWnd
->hListWnd
);
637 if (LOWORD(wParam
) >= ID_FAVORITE_FIRST
&& LOWORD(wParam
) <= ID_FAVORITE_LAST
) {
639 if (RegOpenKeyEx(HKEY_CURRENT_USER
, favoritesKey
,
640 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
) {
641 TCHAR namebuf
[KEY_MAX_LEN
];
643 DWORD ksize
= KEY_MAX_LEN
, vsize
= sizeof(valuebuf
), type
= 0;
644 if (RegEnumValue(hKey
, LOWORD(wParam
) - ID_FAVORITE_FIRST
, namebuf
, &ksize
, NULL
,
645 &type
, valuebuf
, &vsize
) == ERROR_SUCCESS
) {
646 SendMessage( g_pChildWnd
->hTreeWnd
, TVM_SELECTITEM
, TVGN_CARET
,
647 (LPARAM
) FindPathInTree(g_pChildWnd
->hTreeWnd
, (TCHAR
*)valuebuf
) );
653 switch (LOWORD(wParam
)) {
654 case ID_REGISTRY_IMPORTREGISTRYFILE
:
655 ImportRegistryFile(hWnd
);
657 case ID_REGISTRY_EXPORTREGISTRYFILE
:
658 ExportRegistryFile(hWnd
);
660 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
662 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
664 case ID_REGISTRY_PRINT
:
665 PrintRegistryHive(hWnd
, _T(""));
668 if (GetFocus() == g_pChildWnd
->hTreeWnd
) {
669 if (keyPath
== 0 || *keyPath
== 0) {
670 MessageBeep(MB_ICONHAND
);
671 } else if (DeleteKey(hWnd
, hKeyRoot
, keyPath
)) {
672 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
674 } else if (GetFocus() == g_pChildWnd
->hListWnd
) {
675 if (DeleteValue(hWnd
, hKeyRoot
, keyPath
, valueName
))
676 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, NULL
);
680 if (ModifyValue(hWnd
, hKeyRoot
, keyPath
, valueName
))
681 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, valueName
);
684 case ID_EDIT_FINDNEXT
:
687 if (LOWORD(wParam
) == ID_EDIT_FIND
&&
688 DialogBox(0, MAKEINTRESOURCE(IDD_FIND
), hWnd
, find_dlgproc
) != IDOK
)
692 hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
694 int row
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
);
695 HCURSOR hcursorOld
= SetCursor(LoadCursor(NULL
, IDC_WAIT
));
696 hItem
= FindNext(g_pChildWnd
->hTreeWnd
, hItem
, searchString
, searchMask
, &row
);
697 SetCursor(hcursorOld
);
699 SendMessage( g_pChildWnd
->hTreeWnd
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
) hItem
);
700 InvalidateRect(g_pChildWnd
->hTreeWnd
, NULL
, TRUE
);
701 UpdateWindow(g_pChildWnd
->hTreeWnd
);
703 ListView_SetItemState(g_pChildWnd
->hListWnd
, -1, 0, LVIS_FOCUSED
|LVIS_SELECTED
);
704 ListView_SetItemState(g_pChildWnd
->hListWnd
, row
, LVIS_FOCUSED
|LVIS_SELECTED
, LVIS_FOCUSED
|LVIS_SELECTED
);
705 SetFocus(g_pChildWnd
->hListWnd
);
707 SetFocus(g_pChildWnd
->hTreeWnd
);
710 error(hWnd
, IDS_NOTFOUND
, searchString
);
715 case ID_EDIT_COPYKEYNAME
:
717 LPTSTR fullPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
719 CopyKeyName(hWnd
, fullPath
);
720 HeapFree(GetProcessHeap(), 0, fullPath
);
724 case ID_EDIT_NEW_KEY
:
725 if (CreateKey(hWnd
, hKeyRoot
, keyPath
, newKey
)) {
726 if (InsertNode(g_pChildWnd
->hTreeWnd
, 0, newKey
))
727 StartKeyRename(g_pChildWnd
->hTreeWnd
);
730 case ID_EDIT_NEW_STRINGVALUE
:
733 case ID_EDIT_NEW_BINARYVALUE
:
734 valueType
= REG_BINARY
;
736 case ID_EDIT_NEW_DWORDVALUE
:
737 valueType
= REG_DWORD
;
740 if (CreateValue(hWnd
, hKeyRoot
, keyPath
, valueType
, newKey
)) {
741 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, newKey
);
742 StartValueRename(g_pChildWnd
->hListWnd
);
743 /* FIXME: start rename */
747 if (keyPath
== 0 || *keyPath
== 0) {
748 MessageBeep(MB_ICONHAND
);
749 } else if (GetFocus() == g_pChildWnd
->hTreeWnd
) {
750 StartKeyRename(g_pChildWnd
->hTreeWnd
);
751 } else if (GetFocus() == g_pChildWnd
->hListWnd
) {
752 StartValueRename(g_pChildWnd
->hListWnd
);
756 case ID_REGISTRY_PRINTERSETUP
:
759 /*PAGESETUPDLG psd;*/
760 /*PageSetupDlg(&psd);*/
762 case ID_REGISTRY_OPENLOCAL
:
764 case ID_REGISTRY_EXIT
:
767 case ID_FAVORITES_ADDTOFAVORITES
:
770 LPTSTR lpKeyPath
= GetItemFullPath(g_pChildWnd
->hTreeWnd
, NULL
, FALSE
);
772 if (DialogBox(0, MAKEINTRESOURCE(IDD_ADDFAVORITE
), hWnd
, addtofavorites_dlgproc
) == IDOK
) {
773 if (RegCreateKeyEx(HKEY_CURRENT_USER
, favoritesKey
,
775 KEY_READ
|KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
) {
776 RegSetValueEx(hKey
, favoriteName
, 0, REG_SZ
, (BYTE
*)lpKeyPath
, (_tcslen(lpKeyPath
)+1)*sizeof(TCHAR
));
780 HeapFree(GetProcessHeap(), 0, lpKeyPath
);
784 case ID_FAVORITES_REMOVEFAVORITE
:
786 if (DialogBox(0, MAKEINTRESOURCE(IDD_DELFAVORITE
), hWnd
, removefavorite_dlgproc
) == IDOK
) {
788 if (RegOpenKeyEx(HKEY_CURRENT_USER
, favoritesKey
,
789 0, KEY_READ
|KEY_WRITE
, &hKey
) == ERROR_SUCCESS
) {
790 RegDeleteValue(hKey
, favoriteName
);
796 case ID_VIEW_REFRESH
:
797 RefreshTreeView(g_pChildWnd
->hTreeWnd
);
798 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
, NULL
);
800 /*case ID_OPTIONS_TOOLBAR:*/
801 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
803 case ID_VIEW_STATUSBAR
:
804 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
806 case ID_HELP_HELPTOPICS
:
807 WinHelp(hWnd
, _T("regedit"), HELP_FINDER
, 0);
812 case ID_VIEW_SPLIT
: {
815 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
816 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
817 pt
.y
= (rt
.bottom
/ 2);
819 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
)) {
820 SetCursorPos(pts
.x
, pts
.y
);
821 SetCursor(LoadCursor(0, IDC_SIZEWE
));
822 SendMessage(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
833 /********************************************************************************
835 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
837 * PURPOSE: Processes messages for the main frame window.
839 * WM_COMMAND - process the application menu
840 * WM_DESTROY - post a quit message and return
844 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
848 CreateWindowEx(0, szChildClass
, _T("regedit child window"), WS_CHILD
| WS_VISIBLE
,
849 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
850 hWnd
, NULL
, hInst
, 0);
853 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
854 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
858 SetFocus(g_pChildWnd
->hWnd
);
861 resize_frame_client(hWnd
);
865 case WM_ENTERMENULOOP
:
866 OnEnterMenuLoop(hWnd
);
868 case WM_EXITMENULOOP
:
869 OnExitMenuLoop(hWnd
);
871 case WM_INITMENUPOPUP
:
873 OnInitMenuPopup(hWnd
, (HMENU
)wParam
, LOWORD(lParam
));
876 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
879 WinHelp(hWnd
, _T("regedit"), HELP_QUIT
, 0);
882 return DefWindowProc(hWnd
, message
, wParam
, lParam
);