regedit: Also refresh the listview.
[wine/hacks.git] / programs / regedit / framewnd.c
bloba04b0c04bf9e9f7b26d47c1b43a554f20b4a722c
1 /*
2 * Regedit frame window
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 */
23 #include <windows.h>
24 #include <tchar.h>
25 #include <commctrl.h>
26 #include <commdlg.h>
27 #include <cderr.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <shellapi.h>
32 #include "main.h"
33 #include "regproc.h"
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)
51 RECT rt;
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)
70 RECT rect;
72 GetClientRect(hWnd, &rect);
73 resize_frame_rect(hWnd, &rect);
76 /********************************************************************************/
78 static void OnEnterMenuLoop(HWND hWnd)
80 int nParts;
82 /* Update the status bar pane sizes */
83 nParts = -1;
84 SendMessage(hStatusBar, SB_SETPARTS, 1, (long)&nParts);
85 bInMenuLoop = TRUE;
86 SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM)_T(""));
89 static void OnExitMenuLoop(HWND hWnd)
91 bInMenuLoop = FALSE;
92 /* Update the status bar pane sizes*/
93 SetupStatusBar(hWnd, TRUE);
94 UpdateStatusBar();
97 static void UpdateMenuItems(HMENU hMenu) {
98 HWND hwndTV = g_pChildWnd->hTreeWnd;
99 BOOL bIsKeySelected = FALSE;
100 HKEY hRootKey = NULL;
101 LPCTSTR keyName;
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)
118 if (wItem == 3) {
119 HKEY hKey;
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];
125 BYTE valuebuf[4096];
126 int i = 0;
127 BOOL sep = FALSE;
128 DWORD ksize, vsize, type;
129 LONG error;
130 do {
131 ksize = KEY_MAX_LEN;
132 vsize = sizeof(valuebuf);
133 error = RegEnumValue(hKey, i, namebuf, &ksize, NULL, &type, valuebuf, &vsize);
134 if (error != ERROR_SUCCESS)
135 break;
136 if (type == REG_SZ) {
137 if (!sep) {
138 AppendMenu(hMenu, MF_SEPARATOR, -1, NULL);
139 sep = TRUE;
141 AppendMenu(hMenu, MF_STRING, ID_FAVORITE_FIRST+i, namebuf);
143 i++;
144 } while(error == ERROR_SUCCESS);
145 RegCloseKey(hKey);
148 UpdateMenuItems(hMenu);
151 static void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
153 TCHAR str[100];
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*/
163 LPTSTR lpsz = str;
164 /* first newline terminates actual string*/
165 lpsz = _tcschr(lpsz, '\n');
166 if (lpsz != NULL)
167 *lpsz = '\0';
169 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)str);
172 void SetupStatusBar(HWND hWnd, BOOL bResize)
174 RECT rc;
175 int nParts;
176 GetClientRect(hWnd, &rc);
177 nParts = rc.right;
178 /* nParts = -1;*/
179 if (bResize)
180 SendMessage(hStatusBar, WM_SIZE, 0, 0);
181 SendMessage(hStatusBar, SB_SETPARTS, 1, (LPARAM)&nParts);
182 UpdateStatusBar();
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:
207 break;
208 case CDERR_FINDRESFAILURE:
209 break;
210 case CDERR_NOHINSTANCE:
211 break;
212 case CDERR_INITIALIZATION:
213 break;
214 case CDERR_NOHOOK:
215 break;
216 case CDERR_LOCKRESFAILURE:
217 break;
218 case CDERR_NOTEMPLATE:
219 break;
220 case CDERR_LOADRESFAILURE:
221 break;
222 case CDERR_STRUCTSIZE:
223 break;
224 case CDERR_LOADSTRFAILURE:
225 break;
226 case FNERR_BUFFERTOOSMALL:
227 break;
228 case CDERR_MEMALLOCFAILURE:
229 break;
230 case FNERR_INVALIDFILENAME:
231 break;
232 case CDERR_MEMLOCKFAILURE:
233 break;
234 case FNERR_SUBCLASSFAILURE:
235 break;
236 default:
237 break;
239 return TRUE;
242 static UINT_PTR CALLBACK ImportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
244 OPENFILENAME* pOpenFileName;
245 OFNOTIFY* pOfNotify;
247 switch (uiMsg) {
248 case WM_INITDIALOG:
249 pOpenFileName = (OPENFILENAME*)lParam;
250 break;
251 case WM_NOTIFY:
252 pOfNotify = (OFNOTIFY*)lParam;
253 if (pOfNotify->hdr.code == CDN_INITDONE) {}
254 break;
255 default:
256 break;
258 return 0L;
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 = ;*/
292 return TRUE;
295 static BOOL ImportRegistryFile(HWND hWnd)
297 OPENFILENAME ofn;
298 TCHAR title[128];
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);*/
307 return FALSE;
309 #if 0
310 get_file_name(&s, filename, MAX_PATH);
311 if (!filename[0]) {
312 printf("No file name is specified\n%s", usage);
313 return FALSE;
314 /*exit(1);*/
316 while (filename[0]) {
317 if (!import_registry_file(filename)) {
318 perror("");
319 printf("Can't open file \"%s\"\n", filename);
320 return FALSE;
321 /*exit(1);*/
323 get_file_name(&s, filename, MAX_PATH);
325 #endif
327 } else {
328 CheckCommDlgError(hWnd);
330 return TRUE;
334 static BOOL ExportRegistryFile(HWND hWnd)
336 OPENFILENAME ofn;
337 TCHAR ExportKeyPath[_MAX_PATH];
338 TCHAR title[128];
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)) {
349 BOOL result;
350 result = export_registry_key(ofn.lpstrFile, ExportKeyPath);
351 /*result = export_registry_key(ofn.lpstrFile, NULL);*/
352 /*if (!export_registry_key(ofn.lpstrFile, NULL)) {*/
353 if (!result) {
354 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
355 return FALSE;
357 #if 0
358 TCHAR filename[MAX_PATH];
359 filename[0] = '\0';
360 get_file_name(&s, filename, MAX_PATH);
361 if (!filename[0]) {
362 printf("No file name is specified\n%s", usage);
363 return FALSE;
364 /*exit(1);*/
366 if (s[0]) {
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);
370 } else {
371 export_registry_key(filename, NULL);
373 #endif
375 } else {
376 CheckCommDlgError(hWnd);
378 return TRUE;
381 static BOOL PrintRegistryHive(HWND hWnd, LPCTSTR path)
383 #if 1
384 PRINTDLG pd;
386 ZeroMemory(&pd, sizeof(PRINTDLG));
387 pd.lStructSize = sizeof(PRINTDLG);
388 pd.hwndOwner = hWnd;
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;
392 pd.nCopies = 1;
393 pd.nFromPage = 0xFFFF;
394 pd.nToPage = 0xFFFF;
395 pd.nMinPage = 1;
396 pd.nMaxPage = 0xFFFF;
397 if (PrintDlg(&pd)) {
398 /* GDI calls to render output. */
399 DeleteDC(pd.hDC); /* Delete DC when done.*/
401 #else
402 HRESULT hResult;
403 PRINTDLGEX pd;
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. */
410 break;
411 case PD_RESULT_CANCEL:
412 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
413 break;
414 case PD_RESULT_PRINT:
415 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
416 break;
417 default:
418 break;
420 } else {
421 switch (hResult) {
422 case E_OUTOFMEMORY:
423 /*Insufficient memory. */
424 break;
425 case E_INVALIDARG:
426 /* One or more arguments are invalid. */
427 break;
428 case E_POINTER:
429 /*Invalid pointer. */
430 break;
431 case E_HANDLE:
432 /*Invalid handle. */
433 break;
434 case E_FAIL:
435 /*Unspecified error. */
436 break;
437 default:
438 break;
440 return FALSE;
442 #endif
443 return TRUE;
446 static BOOL CopyKeyName(HWND hWnd, LPCTSTR keyName)
448 BOOL result;
450 result = OpenClipboard(hWnd);
451 if (result) {
452 result = EmptyClipboard();
453 if (result) {
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);
461 } else {
462 /* error emptying clipboard*/
463 /* DWORD dwError = GetLastError(); */
466 if (!CloseClipboard()) {
467 /* error closing clipboard*/
468 /* DWORD dwError = GetLastError(); */
471 } else {
472 /* error opening clipboard*/
473 /* DWORD dwError = GetLastError(); */
476 return result;
479 static INT_PTR CALLBACK find_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
481 HWND hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_NAME);
483 switch(uMsg) {
484 case WM_INITDIALOG:
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);
492 return TRUE;
493 case WM_COMMAND:
494 switch(LOWORD(wParam)) {
495 case IDC_VALUE_NAME:
496 if (HIWORD(wParam) == EN_UPDATE) {
497 EnableWindow(GetDlgItem(hwndDlg, IDOK), GetWindowTextLength(hwndValue)>0);
498 return TRUE;
500 break;
501 case IDOK:
502 if (GetWindowTextLength(hwndValue)>0) {
503 int mask = 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;
508 searchMask = mask;
509 GetWindowText(hwndValue, searchString, 128);
510 EndDialog(hwndDlg, IDOK);
512 return TRUE;
513 case IDCANCEL:
514 EndDialog(hwndDlg, IDCANCEL);
515 return TRUE;
517 break;
519 return FALSE;
522 static INT_PTR CALLBACK addtofavorites_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
524 HWND hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_NAME);
526 switch(uMsg) {
527 case WM_INITDIALOG:
528 EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
529 SendMessage(hwndValue, EM_SETLIMITTEXT, 127, 0);
530 return TRUE;
531 case WM_COMMAND:
532 switch(LOWORD(wParam)) {
533 case IDC_VALUE_NAME:
534 if (HIWORD(wParam) == EN_UPDATE) {
535 EnableWindow(GetDlgItem(hwndDlg, IDOK), GetWindowTextLength(hwndValue)>0);
536 return TRUE;
538 break;
539 case IDOK:
540 if (GetWindowTextLength(hwndValue)>0) {
541 GetWindowText(hwndValue, favoriteName, 128);
542 EndDialog(hwndDlg, IDOK);
544 return TRUE;
545 case IDCANCEL:
546 EndDialog(hwndDlg, IDCANCEL);
547 return TRUE;
549 break;
551 return FALSE;
554 static INT_PTR CALLBACK removefavorite_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
556 HWND hwndList = GetDlgItem(hwndDlg, IDC_NAME_LIST);
558 switch(uMsg) {
559 case WM_INITDIALOG: {
560 HKEY hKey;
561 int i = 0;
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];
566 BYTE valuebuf[4096];
567 DWORD ksize, vsize, type;
568 LONG error;
569 do {
570 ksize = KEY_MAX_LEN;
571 vsize = sizeof(valuebuf);
572 error = RegEnumValue(hKey, i, namebuf, &ksize, NULL, &type, valuebuf, &vsize);
573 if (error != ERROR_SUCCESS)
574 break;
575 if (type == REG_SZ) {
576 SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)namebuf);
578 i++;
579 } while(error == ERROR_SUCCESS);
580 RegCloseKey(hKey);
582 else
583 return FALSE;
584 EnableWindow(GetDlgItem(hwndDlg, IDOK), i != 0);
585 SendMessage(hwndList, LB_SETCURSEL, 0, 0);
586 return TRUE;
588 case WM_COMMAND:
589 switch(LOWORD(wParam)) {
590 case IDC_NAME_LIST:
591 if (HIWORD(wParam) == LBN_SELCHANGE) {
592 EnableWindow(GetDlgItem(hwndDlg, IDOK), lParam != -1);
593 return TRUE;
595 break;
596 case IDOK: {
597 int pos = SendMessage(hwndList, LB_GETCURSEL, 0, 0);
598 int len = SendMessage(hwndList, LB_GETTEXTLEN, pos, 0);
599 if (len>0) {
600 LPTSTR lpName = HeapAlloc(GetProcessHeap(), 0, sizeof(TCHAR)*(len+1));
601 SendMessage(hwndList, LB_GETTEXT, pos, (LPARAM)lpName);
602 if (len>127)
603 lpName[127] = '\0';
604 _tcscpy(favoriteName, lpName);
605 EndDialog(hwndDlg, IDOK);
606 HeapFree(GetProcessHeap(), 0, lpName);
608 return TRUE;
610 case IDCANCEL:
611 EndDialog(hwndDlg, IDCANCEL);
612 return TRUE;
614 break;
616 return FALSE;
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)
628 HKEY hKeyRoot = 0;
629 LPCTSTR keyPath;
630 LPCTSTR valueName;
631 TCHAR newKey[MAX_NEW_KEY_LEN];
632 DWORD valueType;
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) {
638 HKEY hKey;
639 if (RegOpenKeyEx(HKEY_CURRENT_USER, favoritesKey,
640 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
641 TCHAR namebuf[KEY_MAX_LEN];
642 BYTE valuebuf[4096];
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) );
649 RegCloseKey(hKey);
651 return TRUE;
653 switch (LOWORD(wParam)) {
654 case ID_REGISTRY_IMPORTREGISTRYFILE:
655 ImportRegistryFile(hWnd);
656 break;
657 case ID_REGISTRY_EXPORTREGISTRYFILE:
658 ExportRegistryFile(hWnd);
659 break;
660 case ID_REGISTRY_CONNECTNETWORKREGISTRY:
661 break;
662 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY:
663 break;
664 case ID_REGISTRY_PRINT:
665 PrintRegistryHive(hWnd, _T(""));
666 break;
667 case ID_EDIT_DELETE:
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);
678 break;
679 case ID_EDIT_MODIFY:
680 if (ModifyValue(hWnd, hKeyRoot, keyPath, valueName))
681 RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, valueName);
682 break;
683 case ID_EDIT_FIND:
684 case ID_EDIT_FINDNEXT:
686 HTREEITEM hItem;
687 if (LOWORD(wParam) == ID_EDIT_FIND &&
688 DialogBox(0, MAKEINTRESOURCE(IDD_FIND), hWnd, find_dlgproc) != IDOK)
689 break;
690 if (!*searchString)
691 break;
692 hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
693 if (hItem) {
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);
698 if (hItem) {
699 SendMessage( g_pChildWnd->hTreeWnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM) hItem );
700 InvalidateRect(g_pChildWnd->hTreeWnd, NULL, TRUE);
701 UpdateWindow(g_pChildWnd->hTreeWnd);
702 if (row != -1) {
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);
706 } else {
707 SetFocus(g_pChildWnd->hTreeWnd);
709 } else {
710 error(hWnd, IDS_NOTFOUND, searchString);
713 break;
715 case ID_EDIT_COPYKEYNAME:
717 LPTSTR fullPath = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE);
718 if (fullPath) {
719 CopyKeyName(hWnd, fullPath);
720 HeapFree(GetProcessHeap(), 0, fullPath);
722 break;
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);
729 break;
730 case ID_EDIT_NEW_STRINGVALUE:
731 valueType = REG_SZ;
732 goto create_value;
733 case ID_EDIT_NEW_BINARYVALUE:
734 valueType = REG_BINARY;
735 goto create_value;
736 case ID_EDIT_NEW_DWORDVALUE:
737 valueType = REG_DWORD;
738 /* fall through */
739 create_value:
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 */
745 break;
746 case ID_EDIT_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);
754 break;
755 break;
756 case ID_REGISTRY_PRINTERSETUP:
757 /*PRINTDLG pd;*/
758 /*PrintDlg(&pd);*/
759 /*PAGESETUPDLG psd;*/
760 /*PageSetupDlg(&psd);*/
761 break;
762 case ID_REGISTRY_OPENLOCAL:
763 break;
764 case ID_REGISTRY_EXIT:
765 DestroyWindow(hWnd);
766 break;
767 case ID_FAVORITES_ADDTOFAVORITES:
769 HKEY hKey;
770 LPTSTR lpKeyPath = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE);
771 if (lpKeyPath) {
772 if (DialogBox(0, MAKEINTRESOURCE(IDD_ADDFAVORITE), hWnd, addtofavorites_dlgproc) == IDOK) {
773 if (RegCreateKeyEx(HKEY_CURRENT_USER, favoritesKey,
774 0, NULL, 0,
775 KEY_READ|KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {
776 RegSetValueEx(hKey, favoriteName, 0, REG_SZ, (BYTE *)lpKeyPath, (_tcslen(lpKeyPath)+1)*sizeof(TCHAR));
777 RegCloseKey(hKey);
780 HeapFree(GetProcessHeap(), 0, lpKeyPath);
782 break;
784 case ID_FAVORITES_REMOVEFAVORITE:
786 if (DialogBox(0, MAKEINTRESOURCE(IDD_DELFAVORITE), hWnd, removefavorite_dlgproc) == IDOK) {
787 HKEY hKey;
788 if (RegOpenKeyEx(HKEY_CURRENT_USER, favoritesKey,
789 0, KEY_READ|KEY_WRITE, &hKey) == ERROR_SUCCESS) {
790 RegDeleteValue(hKey, favoriteName);
791 RegCloseKey(hKey);
794 break;
796 case ID_VIEW_REFRESH:
797 RefreshTreeView(g_pChildWnd->hTreeWnd);
798 RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL);
799 break;
800 /*case ID_OPTIONS_TOOLBAR:*/
801 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
802 /* break;*/
803 case ID_VIEW_STATUSBAR:
804 toggle_child(hWnd, LOWORD(wParam), hStatusBar);
805 break;
806 case ID_HELP_HELPTOPICS:
807 WinHelp(hWnd, _T("regedit"), HELP_FINDER, 0);
808 break;
809 case ID_HELP_ABOUT:
810 ShowAboutBox(hWnd);
811 break;
812 case ID_VIEW_SPLIT: {
813 RECT rt;
814 POINT pt, pts;
815 GetClientRect(g_pChildWnd->hWnd, &rt);
816 pt.x = rt.left + g_pChildWnd->nSplitPos;
817 pt.y = (rt.bottom / 2);
818 pts = pt;
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));
824 return TRUE;
826 default:
827 return FALSE;
830 return TRUE;
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)
846 switch (message) {
847 case WM_CREATE:
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);
851 break;
852 case WM_COMMAND:
853 if (!_CmdWndProc(hWnd, message, wParam, lParam))
854 return DefWindowProc(hWnd, message, wParam, lParam);
855 break;
856 case WM_ACTIVATE:
857 if (LOWORD(hWnd))
858 SetFocus(g_pChildWnd->hWnd);
859 break;
860 case WM_SIZE:
861 resize_frame_client(hWnd);
862 break;
863 case WM_TIMER:
864 break;
865 case WM_ENTERMENULOOP:
866 OnEnterMenuLoop(hWnd);
867 break;
868 case WM_EXITMENULOOP:
869 OnExitMenuLoop(hWnd);
870 break;
871 case WM_INITMENUPOPUP:
872 if (!HIWORD(lParam))
873 OnInitMenuPopup(hWnd, (HMENU)wParam, LOWORD(lParam));
874 break;
875 case WM_MENUSELECT:
876 OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
877 break;
878 case WM_DESTROY:
879 WinHelp(hWnd, _T("regedit"), HELP_QUIT, 0);
880 PostQuitMessage(0);
881 default:
882 return DefWindowProc(hWnd, message, wParam, lParam);
884 return 0;