~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/programs/regedit/framewnd.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Regedit frame window
  3  *
  4  * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
  5  *
  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.
 10  *
 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.
 15  *
 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
 19  */
 20 
 21 #define WIN32_LEAN_AND_MEAN     /* Exclude rarely-used stuff from Windows headers */
 22 
 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>
 31 
 32 #include "main.h"
 33 #include "regproc.h"
 34 
 35 /********************************************************************************
 36  * Global and Local Variables:
 37  */
 38 
 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;
 44 
 45 static TCHAR FileNameBuffer[_MAX_PATH];
 46 static TCHAR FileTitleBuffer[_MAX_PATH];
 47 static TCHAR FilterBuffer[_MAX_PATH];
 48 
 49 /*******************************************************************************
 50  * Local module support methods
 51  */
 52 
 53 static void resize_frame_rect(HWND hWnd, PRECT prect)
 54 {
 55     RECT rt;
 56     /*
 57         if (IsWindowVisible(hToolBar)) {
 58                 SendMessage(hToolBar, WM_SIZE, 0, 0);
 59                 GetClientRect(hToolBar, &rt);
 60                 prect->top = rt.bottom+3;
 61                 prect->bottom -= rt.bottom+3;
 62         }
 63      */
 64     if (IsWindowVisible(hStatusBar)) {
 65         SetupStatusBar(hWnd, TRUE);
 66         GetClientRect(hStatusBar, &rt);
 67         prect->bottom -= rt.bottom;
 68     }
 69     MoveWindow(g_pChildWnd->hWnd, prect->left, prect->top, prect->right, prect->bottom, TRUE);
 70 }
 71 
 72 static void resize_frame_client(HWND hWnd)
 73 {
 74     RECT rect;
 75 
 76     GetClientRect(hWnd, &rect);
 77     resize_frame_rect(hWnd, &rect);
 78 }
 79 
 80 /********************************************************************************/
 81 
 82 static void OnEnterMenuLoop(HWND hWnd)
 83 {
 84     int nParts;
 85 
 86     /* Update the status bar pane sizes */
 87     nParts = -1;
 88     SendMessage(hStatusBar, SB_SETPARTS, 1, (long)&nParts);
 89     bInMenuLoop = TRUE;
 90     SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM)_T(""));
 91 }
 92 
 93 static void OnExitMenuLoop(HWND hWnd)
 94 {
 95     bInMenuLoop = FALSE;
 96     /* Update the status bar pane sizes*/
 97     SetupStatusBar(hWnd, TRUE);
 98     UpdateStatusBar();
 99 }
100 
101 static void UpdateMenuItems(HMENU hMenu) {
102     HWND hwndTV = g_pChildWnd->hTreeWnd;
103     BOOL bAllowEdit = FALSE;
104     HKEY hRootKey = NULL;
105     LPCTSTR keyName;
106     keyName = GetItemPath(hwndTV, TreeView_GetSelection(hwndTV), &hRootKey);
107     if (GetFocus() != hwndTV || (keyName && *keyName)) { /* can't modify root keys, but allow for their values */
108         bAllowEdit = TRUE;
109     }
110     EnableMenuItem(hMenu, ID_EDIT_FIND, MF_ENABLED | MF_BYCOMMAND);
111     EnableMenuItem(hMenu, ID_EDIT_FINDNEXT, MF_ENABLED | MF_BYCOMMAND);
112     EnableMenuItem(hMenu, ID_EDIT_MODIFY, (bAllowEdit ? MF_ENABLED : MF_GRAYED) | MF_BYCOMMAND);
113     EnableMenuItem(hMenu, ID_EDIT_DELETE, (bAllowEdit ? MF_ENABLED : MF_GRAYED) | MF_BYCOMMAND);
114     EnableMenuItem(hMenu, ID_EDIT_RENAME, (bAllowEdit ? MF_ENABLED : MF_GRAYED) | MF_BYCOMMAND);
115     EnableMenuItem(hMenu, ID_FAVORITES_ADDTOFAVORITES, (hRootKey ? MF_ENABLED : MF_GRAYED) | MF_BYCOMMAND);
116     EnableMenuItem(hMenu, ID_FAVORITES_REMOVEFAVORITE, 
117         (GetMenuItemCount(hMenu)>2 ? MF_ENABLED : MF_GRAYED) | MF_BYCOMMAND);
118 }
119 
120 static void OnInitMenuPopup(HWND hWnd, HMENU hMenu, short wItem)
121 {
122     if (wItem == 3) {
123         HKEY hKey;
124         while(GetMenuItemCount(hMenu)>2)
125             DeleteMenu(hMenu, 2, MF_BYPOSITION);
126         if (RegOpenKeyEx(HKEY_CURRENT_USER, favoritesKey, 
127             0, KEY_READ, &hKey) == ERROR_SUCCESS) {
128             TCHAR namebuf[KEY_MAX_LEN];
129             BYTE valuebuf[4096];
130             int i = 0;
131             BOOL sep = FALSE;
132             DWORD ksize, vsize, type;
133             LONG error;
134             do {
135                 ksize = KEY_MAX_LEN;
136                 vsize = sizeof(valuebuf);
137                 error = RegEnumValue(hKey, i, namebuf, &ksize, NULL, &type, valuebuf, &vsize);
138                 if (error != ERROR_SUCCESS)
139                     break;
140                 if (type == REG_SZ) {
141                     if (!sep) {
142                         AppendMenu(hMenu, MF_SEPARATOR, -1, NULL);
143                         sep = TRUE;
144                     }
145                     AppendMenu(hMenu, MF_STRING, ID_FAVORITE_FIRST+i, namebuf);
146                 }
147                 i++;
148             } while(error == ERROR_SUCCESS);
149             RegCloseKey(hKey);
150         }
151     }
152     UpdateMenuItems(hMenu);
153 }
154 
155 static void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
156 {
157     TCHAR str[100];
158 
159     _tcscpy(str, _T(""));
160     if (nFlags & MF_POPUP) {
161         if (hSysMenu != GetMenu(hWnd)) {
162             if (nItemID == 2) nItemID = 5;
163         }
164     }
165     if (LoadString(hInst, nItemID, str, 100)) {
166         /* load appropriate string*/
167         LPTSTR lpsz = str;
168         /* first newline terminates actual string*/
169         lpsz = _tcschr(lpsz, '\n');
170         if (lpsz != NULL)
171             *lpsz = '\0';
172     }
173     SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)str);
174 }
175 
176 void SetupStatusBar(HWND hWnd, BOOL bResize)
177 {
178     RECT  rc;
179     int nParts;
180     GetClientRect(hWnd, &rc);
181     nParts = rc.right;
182     /*    nParts = -1;*/
183     if (bResize)
184         SendMessage(hStatusBar, WM_SIZE, 0, 0);
185     SendMessage(hStatusBar, SB_SETPARTS, 1, (LPARAM)&nParts);
186     UpdateStatusBar();
187 }
188 
189 void UpdateStatusBar(void)
190 {
191     LPTSTR fullPath = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, TRUE);
192     SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath);
193     HeapFree(GetProcessHeap(), 0, fullPath);
194 }
195 
196 static void toggle_child(HWND hWnd, UINT cmd, HWND hchild)
197 {
198     BOOL vis = IsWindowVisible(hchild);
199     HMENU hMenuView = GetSubMenu(hMenuFrame, ID_VIEW_MENU);
200 
201     CheckMenuItem(hMenuView, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
202     ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
203     resize_frame_client(hWnd);
204 }
205 
206 static BOOL CheckCommDlgError(HWND hWnd)
207 {
208     DWORD dwErrorCode = CommDlgExtendedError();
209     switch (dwErrorCode) {
210     case CDERR_DIALOGFAILURE:
211         break;
212     case CDERR_FINDRESFAILURE:
213         break;
214     case CDERR_NOHINSTANCE:
215         break;
216     case CDERR_INITIALIZATION:
217         break;
218     case CDERR_NOHOOK:
219         break;
220     case CDERR_LOCKRESFAILURE:
221         break;
222     case CDERR_NOTEMPLATE:
223         break;
224     case CDERR_LOADRESFAILURE:
225         break;
226     case CDERR_STRUCTSIZE:
227         break;
228     case CDERR_LOADSTRFAILURE:
229         break;
230     case FNERR_BUFFERTOOSMALL:
231         break;
232     case CDERR_MEMALLOCFAILURE:
233         break;
234     case FNERR_INVALIDFILENAME:
235         break;
236     case CDERR_MEMLOCKFAILURE:
237         break;
238     case FNERR_SUBCLASSFAILURE:
239         break;
240     default:
241         break;
242     }
243     return TRUE;
244 }
245 
246 static void ExportRegistryFile_StoreSelection(HWND hdlg, OPENFILENAME *pOpenFileName)
247 {
248     if (IsDlgButtonChecked(hdlg, IDC_EXPORT_SELECTED))
249     {
250         INT len = SendDlgItemMessage(hdlg, IDC_EXPORT_PATH, WM_GETTEXTLENGTH, 0, 0);
251         pOpenFileName->lCustData = (LPARAM)HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(TCHAR));
252         SendDlgItemMessage(hdlg, IDC_EXPORT_PATH, WM_GETTEXT, len+1, pOpenFileName->lCustData);
253     }
254     else
255         pOpenFileName->lCustData = (LPARAM)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TCHAR));
256 }
257 
258 static UINT CALLBACK ExportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
259 {
260     static OPENFILENAME* pOpenFileName;
261     OFNOTIFY *pOfNotify;
262     LPTSTR path;
263 
264     switch (uiMsg) {
265     case WM_INITDIALOG:
266         pOpenFileName = (OPENFILENAME*)lParam;
267         break;
268     case WM_COMMAND:
269         if (LOWORD(wParam) == IDC_EXPORT_PATH && HIWORD(wParam) == EN_UPDATE)
270             CheckRadioButton(hdlg, IDC_EXPORT_ALL, IDC_EXPORT_SELECTED, IDC_EXPORT_SELECTED);
271         break;
272     case WM_NOTIFY:
273         pOfNotify = (OFNOTIFY*)lParam;
274         switch (pOfNotify->hdr.code)
275         {
276             case CDN_INITDONE:
277                 path = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE);
278                 SendDlgItemMessage(hdlg, IDC_EXPORT_PATH, WM_SETTEXT, 0, (LPARAM)path);
279                 HeapFree(GetProcessHeap(), 0, path);
280                 CheckRadioButton(hdlg, IDC_EXPORT_ALL, IDC_EXPORT_SELECTED, pOpenFileName->lCustData ? IDC_EXPORT_SELECTED : IDC_EXPORT_ALL);
281                 break;
282             case CDN_FILEOK:
283                 ExportRegistryFile_StoreSelection(hdlg, pOpenFileName);
284                 break;
285         }
286         break;
287     default:
288         break;
289     }
290     return 0L;
291 }
292 
293 
294 static BOOL InitOpenFileName(HWND hWnd, OPENFILENAME *pofn)
295 {
296     memset(pofn, 0, sizeof(OPENFILENAME));
297     pofn->lStructSize = sizeof(OPENFILENAME);
298     pofn->hwndOwner = hWnd;
299     pofn->hInstance = hInst;
300 
301     if (FilterBuffer[0] == 0)
302         LoadString(hInst, IDS_FILEDIALOG_FILTER, FilterBuffer, _MAX_PATH);
303     pofn->lpstrFilter = FilterBuffer;
304     pofn->nFilterIndex = 1;
305     pofn->lpstrFile = FileNameBuffer;
306     pofn->nMaxFile = _MAX_PATH;
307     pofn->lpstrFileTitle = FileTitleBuffer;
308     pofn->nMaxFileTitle = _MAX_PATH;
309     pofn->Flags = OFN_HIDEREADONLY;
310     /* some other fields may be set by the caller */
311     return TRUE;
312 }
313 
314 static BOOL import_registry_filename(LPTSTR filename)
315 {
316     BOOL Success;
317     FILE* reg_file = fopen(filename, "r");
318 
319     if(!reg_file)
320         return FALSE;
321 
322     Success = import_registry_file(reg_file);
323 
324     if(fclose(reg_file) != 0)
325         Success = FALSE;
326 
327     return Success;
328 }
329 
330 static BOOL ImportRegistryFile(HWND hWnd)
331 {
332     OPENFILENAME ofn;
333     TCHAR title[128];
334 
335     InitOpenFileName(hWnd, &ofn);
336     LoadString(hInst, IDS_FILEDIALOG_IMPORT_TITLE, title, COUNT_OF(title));
337     ofn.lpstrTitle = title;
338     if (GetOpenFileName(&ofn)) {
339         if (!import_registry_filename(ofn.lpstrFile)) {
340             /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
341             return FALSE;
342         }
343     } else {
344         CheckCommDlgError(hWnd);
345     }
346     RefreshTreeView(g_pChildWnd->hTreeWnd);
347     return TRUE;
348 }
349 
350 
351 static BOOL ExportRegistryFile(HWND hWnd, BOOL export_branch)
352 {
353     OPENFILENAME ofn;
354     TCHAR ExportKeyPath[_MAX_PATH];
355     TCHAR title[128];
356 
357     ExportKeyPath[0] = _T('\0');
358     InitOpenFileName(hWnd, &ofn);
359     LoadString(hInst, IDS_FILEDIALOG_EXPORT_TITLE, title, COUNT_OF(title));
360     ofn.lpstrTitle = title;
361     ofn.lCustData = export_branch;
362     ofn.Flags = OFN_ENABLETEMPLATE | OFN_ENABLEHOOK | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
363     ofn.lpfnHook = ExportRegistryFile_OFNHookProc;
364     ofn.lpTemplateName = MAKEINTRESOURCE(IDD_EXPORT_TEMPLATE);
365     if (GetSaveFileName(&ofn)) {
366         BOOL result;
367         result = export_registry_key(ofn.lpstrFile, (LPTSTR)ofn.lCustData);
368         if (!result) {
369             /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
370             return FALSE;
371         }
372     } else {
373         CheckCommDlgError(hWnd);
374     }
375     return TRUE;
376 }
377 
378 static BOOL PrintRegistryHive(HWND hWnd, LPCWSTR path)
379 {
380 #if 1
381     PRINTDLGW pd;
382 
383     ZeroMemory(&pd, sizeof(PRINTDLG));
384     pd.lStructSize = sizeof(PRINTDLG);
385     pd.hwndOwner   = hWnd;
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;
389     pd.nCopies     = 1;
390     pd.nFromPage   = 0xFFFF;
391     pd.nToPage     = 0xFFFF;
392     pd.nMinPage    = 1;
393     pd.nMaxPage    = 0xFFFF;
394     if (PrintDlgW(&pd)) {
395         /* GDI calls to render output. */
396         DeleteDC(pd.hDC); /* Delete DC when done.*/
397     }
398 #else
399     HRESULT hResult;
400     PRINTDLGEXW pd;
401 
402     hResult = PrintDlgExW(&pd);
403     if (hResult == S_OK) {
404         switch (pd.dwResultAction) {
405         case PD_RESULT_APPLY:
406             /*The user clicked the Apply button and later clicked the Cancel button. This indicates that the user wants to apply the changes made in the property sheet, but does not yet want to print. The PRINTDLGEX structure contains the information specified by the user at the time the Apply button was clicked. */
407             break;
408         case PD_RESULT_CANCEL:
409             /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
410             break;
411         case PD_RESULT_PRINT:
412             /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
413             break;
414         default:
415             break;
416         }
417     } else {
418         switch (hResult) {
419         case E_OUTOFMEMORY:
420             /*Insufficient memory. */
421             break;
422         case E_INVALIDARG:
423             /* One or more arguments are invalid. */
424             break;
425         case E_POINTER:
426             /*Invalid pointer. */
427             break;
428         case E_HANDLE:
429             /*Invalid handle. */
430             break;
431         case E_FAIL:
432             /*Unspecified error. */
433             break;
434         default:
435             break;
436         }
437         return FALSE;
438     }
439 #endif
440     return TRUE;
441 }
442 
443 static BOOL CopyKeyName(HWND hWnd, LPCWSTR keyName)
444 {
445     BOOL result;
446 
447     result = OpenClipboard(hWnd);
448     if (result) {
449         result = EmptyClipboard();
450         if (result) {
451             int len = (lstrlenW(keyName)+1)*sizeof(WCHAR);
452             HANDLE hClipData = GlobalAlloc(GHND, len);
453             LPVOID pLoc = GlobalLock(hClipData);
454             lstrcpyW(pLoc, keyName);
455             GlobalUnlock(hClipData);
456             hClipData = SetClipboardData(CF_UNICODETEXT, hClipData);
457 
458         } else {
459             /* error emptying clipboard*/
460             /* DWORD dwError = GetLastError(); */
461             ;
462         }
463         if (!CloseClipboard()) {
464             /* error closing clipboard*/
465             /* DWORD dwError = GetLastError(); */
466             ;
467         }
468     } else {
469         /* error opening clipboard*/
470         /* DWORD dwError = GetLastError(); */
471         ;
472     }
473     return result;
474 }
475 
476 static INT_PTR CALLBACK find_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
477 {
478     HWND hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_NAME);
479             
480     switch(uMsg) {
481         case WM_INITDIALOG:
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);
489             return TRUE;
490         case WM_COMMAND:
491             switch(LOWORD(wParam)) {
492             case IDC_VALUE_NAME:
493                 if (HIWORD(wParam) == EN_UPDATE) {
494                     EnableWindow(GetDlgItem(hwndDlg, IDOK),  GetWindowTextLength(hwndValue)>0);
495                     return TRUE;
496                 }
497                 break;
498             case IDOK:
499                 if (GetWindowTextLength(hwndValue)>0) {
500                     int mask = 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;
505                     searchMask = mask;
506                     GetWindowText(hwndValue, searchString, 128);
507                     EndDialog(hwndDlg, IDOK);
508                 }
509                 return TRUE;
510             case IDCANCEL:
511                 EndDialog(hwndDlg, IDCANCEL);
512                 return TRUE;
513             }
514             break;
515     }
516     return FALSE;
517 }
518                     
519 static INT_PTR CALLBACK addtofavorites_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
520 {
521     HWND hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_NAME);
522             
523     switch(uMsg) {
524         case WM_INITDIALOG:
525         {
526             HKEY hKeyRoot = NULL;
527             LPSTR ItemPath = GetItemPath(g_pChildWnd->hTreeWnd, NULL, &hKeyRoot);
528 
529             if(!ItemPath || !*ItemPath)
530                 ItemPath = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE);
531             EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
532             SetWindowText(hwndValue, ItemPath);
533             SendMessage(hwndValue, EM_SETLIMITTEXT, 127, 0);
534             return TRUE;
535         }
536         case WM_COMMAND:
537             switch(LOWORD(wParam)) {
538             case IDC_VALUE_NAME:
539                 if (HIWORD(wParam) == EN_UPDATE) {
540                     EnableWindow(GetDlgItem(hwndDlg, IDOK),  GetWindowTextLength(hwndValue)>0);
541                     return TRUE;
542                 }
543                 break;
544             case IDOK:
545                 if (GetWindowTextLength(hwndValue)>0) {
546                     GetWindowText(hwndValue, favoriteName, 128);
547                     EndDialog(hwndDlg, IDOK);
548                 }
549                 return TRUE;
550             case IDCANCEL:
551                 EndDialog(hwndDlg, IDCANCEL);
552                 return TRUE;
553             }
554             break;
555     }
556     return FALSE;
557 }
558                     
559 static INT_PTR CALLBACK removefavorite_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
560 {
561     HWND hwndList = GetDlgItem(hwndDlg, IDC_NAME_LIST);
562             
563     switch(uMsg) {
564         case WM_INITDIALOG: {
565             HKEY hKey;
566             int i = 0;
567             EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
568             if (RegOpenKeyEx(HKEY_CURRENT_USER, favoritesKey, 
569                 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
570                 TCHAR namebuf[KEY_MAX_LEN];
571                 BYTE valuebuf[4096];
572                 DWORD ksize, vsize, type;
573                 LONG error;
574                 do {
575                     ksize = KEY_MAX_LEN;
576                     vsize = sizeof(valuebuf);
577                     error = RegEnumValue(hKey, i, namebuf, &ksize, NULL, &type, valuebuf, &vsize);
578                     if (error != ERROR_SUCCESS)
579                         break;
580                     if (type == REG_SZ) {
581                         SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)namebuf);
582                     }
583                     i++;
584                 } while(error == ERROR_SUCCESS);
585                 RegCloseKey(hKey);
586             }
587             else
588                 return FALSE;
589             EnableWindow(GetDlgItem(hwndDlg, IDOK), i != 0);
590             SendMessage(hwndList, LB_SETCURSEL, 0, 0);
591             return TRUE;
592         }
593         case WM_COMMAND:
594             switch(LOWORD(wParam)) {
595             case IDC_NAME_LIST:
596                 if (HIWORD(wParam) == LBN_SELCHANGE) {
597                     EnableWindow(GetDlgItem(hwndDlg, IDOK),  lParam != -1);
598                     return TRUE;
599                 }
600                 break;
601             case IDOK: {
602                 int pos = SendMessage(hwndList, LB_GETCURSEL, 0, 0);
603                 int len = SendMessage(hwndList, LB_GETTEXTLEN, pos, 0);
604                 if (len>0) {
605                     LPTSTR lpName = HeapAlloc(GetProcessHeap(), 0, sizeof(TCHAR)*(len+1));
606                     SendMessage(hwndList, LB_GETTEXT, pos, (LPARAM)lpName);
607                     if (len>127)
608                         lpName[127] = '\0';
609                     _tcscpy(favoriteName, lpName);
610                     EndDialog(hwndDlg, IDOK);
611                     HeapFree(GetProcessHeap(), 0, lpName);
612                 }
613                 return TRUE;
614             }
615             case IDCANCEL:
616                 EndDialog(hwndDlg, IDCANCEL);
617                 return TRUE;
618             }
619             break;
620     }
621     return FALSE;
622 }
623                     
624 /*******************************************************************************
625  *
626  *  FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
627  *
628  *  PURPOSE:  Processes WM_COMMAND messages for the main frame window.
629  *
630  */
631 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
632 {
633     HKEY hKeyRoot = 0;
634     LPCTSTR keyPath;
635     LPCTSTR valueName;
636     TCHAR newKey[MAX_NEW_KEY_LEN];
637     DWORD valueType;
638     int curIndex;
639     BOOL firstItem = TRUE;
640 
641     keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
642 
643     if (LOWORD(wParam) >= ID_FAVORITE_FIRST && LOWORD(wParam) <= ID_FAVORITE_LAST) {
644         HKEY hKey;
645         if (RegOpenKeyEx(HKEY_CURRENT_USER, favoritesKey, 
646             0, KEY_READ, &hKey) == ERROR_SUCCESS) {
647             TCHAR namebuf[KEY_MAX_LEN];
648             BYTE valuebuf[4096];
649             DWORD ksize = KEY_MAX_LEN, vsize = sizeof(valuebuf), type = 0;
650             if (RegEnumValue(hKey, LOWORD(wParam) - ID_FAVORITE_FIRST, namebuf, &ksize, NULL, 
651                 &type, valuebuf, &vsize) == ERROR_SUCCESS) {
652                 SendMessage( g_pChildWnd->hTreeWnd, TVM_SELECTITEM, TVGN_CARET,
653                              (LPARAM) FindPathInTree(g_pChildWnd->hTreeWnd, (TCHAR *)valuebuf) );
654             }
655             RegCloseKey(hKey);
656         }
657         return TRUE;
658     }
659     switch (LOWORD(wParam)) {
660     case ID_REGISTRY_IMPORTREGISTRYFILE:
661         ImportRegistryFile(hWnd);
662         break;
663     case ID_EDIT_EXPORT:
664         ExportRegistryFile(hWnd, TRUE);
665         break;
666     case ID_REGISTRY_EXPORTREGISTRYFILE:
667         ExportRegistryFile(hWnd, FALSE);
668         break;
669     case ID_REGISTRY_CONNECTNETWORKREGISTRY:
670         break;
671     case ID_REGISTRY_DISCONNECTNETWORKREGISTRY:
672         break;
673     case ID_REGISTRY_PRINT:
674     {
675         const WCHAR empty = 0;
676         PrintRegistryHive(hWnd, &empty);
677         break;
678     }
679     case ID_EDIT_DELETE:
680         if (GetFocus() == g_pChildWnd->hTreeWnd) {
681             WCHAR* keyPathW = GetWideString(keyPath);
682             if (keyPath == 0 || *keyPath == 0) {
683                 MessageBeep(MB_ICONHAND); 
684             } else if (DeleteKey(hWnd, hKeyRoot, keyPathW)) {
685                 DeleteNode(g_pChildWnd->hTreeWnd, 0);
686             }
687             HeapFree(GetProcessHeap(), 0, keyPathW);
688         } else if (GetFocus() == g_pChildWnd->hListWnd) {
689         curIndex = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED);
690         while(curIndex != -1) {
691             WCHAR* valueNameW;
692             WCHAR* keyPathW;
693 
694             valueName = GetItemText(g_pChildWnd->hListWnd, curIndex);
695             curIndex = ListView_GetNextItem(g_pChildWnd->hListWnd, curIndex, LVNI_SELECTED);
696             if(curIndex != -1 && firstItem) {
697                 if (MessageBoxW(hWnd, MAKEINTRESOURCEW(IDS_DELETE_BOX_TEXT_MULTIPLE),
698                                 MAKEINTRESOURCEW(IDS_DELETE_BOX_TITLE),
699                                 MB_YESNO | MB_ICONEXCLAMATION) != IDYES)
700                     break;
701             }
702             valueNameW = GetWideString(valueName);
703             keyPathW = GetWideString(keyPath);
704             if (!DeleteValue(hWnd, hKeyRoot, keyPathW, valueNameW, curIndex==-1 && firstItem))
705             {
706                 HeapFree(GetProcessHeap(), 0, valueNameW);
707                 HeapFree(GetProcessHeap(), 0, keyPathW);
708                 break;
709             }
710             firstItem = FALSE;
711             HeapFree(GetProcessHeap(), 0, valueNameW);
712             HeapFree(GetProcessHeap(), 0, keyPathW);
713         }
714                 RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL);
715         }
716         break;
717     case ID_EDIT_MODIFY:
718         valueName = GetValueName(g_pChildWnd->hListWnd);
719         if (ModifyValue(hWnd, hKeyRoot, keyPath, valueName))
720             RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, valueName);
721         break;
722     case ID_EDIT_FIND:
723     case ID_EDIT_FINDNEXT:
724     {
725         HTREEITEM hItem;
726         if (LOWORD(wParam) == ID_EDIT_FIND &&
727             DialogBox(0, MAKEINTRESOURCE(IDD_FIND), hWnd, find_dlgproc) != IDOK)
728             break;
729         if (!*searchString)
730             break;
731         hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
732         if (hItem) {
733             int row = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_FOCUSED);
734             HCURSOR hcursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
735             hItem = FindNext(g_pChildWnd->hTreeWnd, hItem, searchString, searchMask, &row);
736             SetCursor(hcursorOld);
737             if (hItem) {
738                 SendMessage( g_pChildWnd->hTreeWnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM) hItem );
739                 InvalidateRect(g_pChildWnd->hTreeWnd, NULL, TRUE);
740                 UpdateWindow(g_pChildWnd->hTreeWnd);
741                 if (row != -1) {
742                     ListView_SetItemState(g_pChildWnd->hListWnd, -1, 0, LVIS_FOCUSED|LVIS_SELECTED);
743                     ListView_SetItemState(g_pChildWnd->hListWnd, row, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED);
744                     SetFocus(g_pChildWnd->hListWnd);
745                 } else {
746                     SetFocus(g_pChildWnd->hTreeWnd);
747                 }
748             } else {
749                 error(hWnd, IDS_NOTFOUND, searchString);
750             }
751         }
752         break;
753     }
754     case ID_EDIT_COPYKEYNAME:
755     {
756         LPWSTR fullPath = GetItemFullPathW(g_pChildWnd->hTreeWnd, NULL, FALSE);
757         if (fullPath) {
758             CopyKeyName(hWnd, fullPath);
759             HeapFree(GetProcessHeap(), 0, fullPath);
760         }
761         break;
762     }
763     case ID_EDIT_NEW_KEY:
764     {
765         WCHAR newKeyW[MAX_NEW_KEY_LEN];
766         WCHAR* keyPathW = GetWideString(keyPath);
767         if (CreateKey(hWnd, hKeyRoot, keyPathW, newKeyW)) {
768             if (InsertNode(g_pChildWnd->hTreeWnd, 0, newKeyW))
769                 StartKeyRename(g_pChildWnd->hTreeWnd);
770         }
771         HeapFree(GetProcessHeap(), 0, keyPathW);
772     }
773         break;
774     case ID_EDIT_NEW_STRINGVALUE:
775         valueType = REG_SZ;
776         goto create_value;
777     case ID_EDIT_NEW_MULTI_STRINGVALUE:
778         valueType = REG_MULTI_SZ;
779         goto create_value;
780     case ID_EDIT_NEW_BINARYVALUE:
781         valueType = REG_BINARY;
782         goto create_value;
783     case ID_EDIT_NEW_DWORDVALUE:
784         valueType = REG_DWORD;
785         /* fall through */
786     create_value:
787         if (CreateValue(hWnd, hKeyRoot, keyPath, valueType, newKey)) {
788             RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, newKey);
789             StartValueRename(g_pChildWnd->hListWnd);
790             /* FIXME: start rename */
791         }
792         break;
793     case ID_EDIT_RENAME:
794         if (keyPath == 0 || *keyPath == 0) {
795             MessageBeep(MB_ICONHAND); 
796         } else if (GetFocus() == g_pChildWnd->hTreeWnd) {
797             StartKeyRename(g_pChildWnd->hTreeWnd);
798         } else if (GetFocus() == g_pChildWnd->hListWnd) {
799             StartValueRename(g_pChildWnd->hListWnd);
800         }
801         break;
802     case ID_REGISTRY_PRINTERSETUP:
803         /*PRINTDLG pd;*/
804         /*PrintDlg(&pd);*/
805         /*PAGESETUPDLG psd;*/
806         /*PageSetupDlg(&psd);*/
807         break;
808     case ID_REGISTRY_OPENLOCAL:
809         break;
810     case ID_REGISTRY_EXIT:
811         DestroyWindow(hWnd);
812         break;
813     case ID_FAVORITES_ADDTOFAVORITES:
814     {
815         HKEY hKey;
816         LPTSTR lpKeyPath = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE);
817         if (lpKeyPath) {
818             if (DialogBox(0, MAKEINTRESOURCE(IDD_ADDFAVORITE), hWnd, addtofavorites_dlgproc) == IDOK) {
819                 if (RegCreateKeyEx(HKEY_CURRENT_USER, favoritesKey, 
820                     0, NULL, 0, 
821                     KEY_READ|KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {
822                     RegSetValueEx(hKey, favoriteName, 0, REG_SZ, (BYTE *)lpKeyPath, (_tcslen(lpKeyPath)+1)*sizeof(TCHAR));
823                     RegCloseKey(hKey);
824                 }
825             }
826             HeapFree(GetProcessHeap(), 0, lpKeyPath);
827         }
828         break;
829     }
830     case ID_FAVORITES_REMOVEFAVORITE:
831     {
832         if (DialogBox(0, MAKEINTRESOURCE(IDD_DELFAVORITE), hWnd, removefavorite_dlgproc) == IDOK) {
833             HKEY hKey;
834             if (RegOpenKeyEx(HKEY_CURRENT_USER, favoritesKey, 
835                 0, KEY_READ|KEY_WRITE, &hKey) == ERROR_SUCCESS) {
836                 RegDeleteValue(hKey, favoriteName); 
837                 RegCloseKey(hKey);
838             }
839         }
840         break;
841     }
842     case ID_VIEW_REFRESH:
843         RefreshTreeView(g_pChildWnd->hTreeWnd);
844         RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL);
845         break;
846    /*case ID_OPTIONS_TOOLBAR:*/
847    /*   toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
848    /*    break;*/
849     case ID_VIEW_STATUSBAR:
850         toggle_child(hWnd, LOWORD(wParam), hStatusBar);
851         break;
852     case ID_HELP_HELPTOPICS:
853     {
854         const WCHAR help_regedit[] = {'r','e','g','e','d','i','t',0};
855         WinHelpW(hWnd, help_regedit, HELP_FINDER, 0);
856         break;
857     }
858     case ID_HELP_ABOUT:
859         ShowAboutBox(hWnd);
860         break;
861     case ID_VIEW_SPLIT: {
862         RECT rt;
863         POINT pt, pts;
864         GetClientRect(g_pChildWnd->hWnd, &rt);
865         pt.x = rt.left + g_pChildWnd->nSplitPos;
866         pt.y = (rt.bottom / 2);
867         pts = pt;
868         if(ClientToScreen(g_pChildWnd->hWnd, &pts)) {
869             SetCursorPos(pts.x, pts.y);
870             SetCursor(LoadCursor(0, IDC_SIZEWE));
871             SendMessage(g_pChildWnd->hWnd, WM_LBUTTONDOWN, 0, MAKELPARAM(pt.x, pt.y));
872         }
873         return TRUE;
874     }
875     default:
876         return FALSE;
877     }
878 
879     return TRUE;
880 }
881 
882 /********************************************************************************
883  *
884  *  FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
885  *
886  *  PURPOSE:  Processes messages for the main frame window.
887  *
888  *  WM_COMMAND  - process the application menu
889  *  WM_DESTROY  - post a quit message and return
890  *
891  */
892 
893 LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
894 {
895     switch (message) {
896     case WM_CREATE:
897         CreateWindowEx(0, szChildClass, _T("regedit child window"), WS_CHILD | WS_VISIBLE,
898                        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
899                        hWnd, NULL, hInst, 0);
900         break;
901     case WM_COMMAND:
902         if (!_CmdWndProc(hWnd, message, wParam, lParam))
903             return DefWindowProc(hWnd, message, wParam, lParam);
904         break;
905     case WM_ACTIVATE:
906         if (LOWORD(hWnd)) 
907             SetFocus(g_pChildWnd->hWnd);
908         break;
909     case WM_SIZE:
910         resize_frame_client(hWnd);
911         break;
912     case WM_TIMER:
913         break;
914     case WM_ENTERMENULOOP:
915         OnEnterMenuLoop(hWnd);
916         break;
917     case WM_EXITMENULOOP:
918         OnExitMenuLoop(hWnd);
919         break;
920     case WM_INITMENUPOPUP:
921         if (!HIWORD(lParam))
922             OnInitMenuPopup(hWnd, (HMENU)wParam, LOWORD(lParam));
923         break;
924     case WM_MENUSELECT:
925         OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
926         break;
927     case WM_DESTROY:
928     {
929         const WCHAR help_regedit[] = {'r','e','g','e','d','i','t',0};
930         WinHelpW(hWnd, help_regedit, HELP_QUIT, 0);
931         PostQuitMessage(0);
932     }
933     default:
934         return DefWindowProc(hWnd, message, wParam, lParam);
935     }
936     return 0;
937 }
938 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.