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 BOOL bInMenuLoop = FALSE; /* Tells us if we are in the menu loop */
41 static HWND hChildWnd;
43 /*******************************************************************************
44 * Local module support methods
47 static void resize_frame_rect(HWND hWnd, PRECT prect)
51 if (IsWindowVisible(hToolBar)) {
52 SendMessage(hToolBar, WM_SIZE, 0, 0);
53 GetClientRect(hToolBar, &rt);
54 prect->top = rt.bottom+3;
55 prect->bottom -= rt.bottom+3;
58 if (IsWindowVisible(hStatusBar)) {
59 SetupStatusBar(hWnd, TRUE);
60 GetClientRect(hStatusBar, &rt);
61 prect->bottom -= rt.bottom;
63 MoveWindow(hChildWnd, prect->left, prect->top, prect->right, prect->bottom, TRUE);
66 void resize_frame_client(HWND hWnd)
70 GetClientRect(hWnd, &rect);
71 resize_frame_rect(hWnd, &rect);
74 /********************************************************************************/
76 static void OnEnterMenuLoop(HWND hWnd)
80 /* Update the status bar pane sizes */
82 SendMessage(hStatusBar, SB_SETPARTS, 1, (long)&nParts);
84 SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM)_T(""));
87 static void OnExitMenuLoop(HWND hWnd)
90 /* Update the status bar pane sizes*/
91 SetupStatusBar(hWnd, TRUE);
95 static void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
100 if (nFlags & MF_POPUP) {
101 if (hSysMenu != GetMenu(hWnd)) {
102 if (nItemID == 2) nItemID = 5;
105 if (LoadString(hInst, nItemID, str, 100)) {
106 /* load appropriate string*/
108 /* first newline terminates actual string*/
109 lpsz = _tcschr(lpsz, '\n');
113 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)str);
116 void SetupStatusBar(HWND hWnd, BOOL bResize)
120 GetClientRect(hWnd, &rc);
124 SendMessage(hStatusBar, WM_SIZE, 0, 0);
125 SendMessage(hStatusBar, SB_SETPARTS, 1, (LPARAM)&nParts);
128 void UpdateStatusBar(void)
133 size = sizeof(text)/sizeof(TCHAR);
134 GetComputerName(text, &size);
135 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)text);
138 static void toggle_child(HWND hWnd, UINT cmd, HWND hchild)
140 BOOL vis = IsWindowVisible(hchild);
141 HMENU hMenuView = GetSubMenu(hMenuFrame, ID_VIEW_MENU);
143 CheckMenuItem(hMenuView, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
144 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
145 resize_frame_client(hWnd);
148 static BOOL CheckCommDlgError(HWND hWnd)
150 DWORD dwErrorCode = CommDlgExtendedError();
151 switch (dwErrorCode) {
152 case CDERR_DIALOGFAILURE:
154 case CDERR_FINDRESFAILURE:
156 case CDERR_NOHINSTANCE:
158 case CDERR_INITIALIZATION:
162 case CDERR_LOCKRESFAILURE:
164 case CDERR_NOTEMPLATE:
166 case CDERR_LOADRESFAILURE:
168 case CDERR_STRUCTSIZE:
170 case CDERR_LOADSTRFAILURE:
172 case FNERR_BUFFERTOOSMALL:
174 case CDERR_MEMALLOCFAILURE:
176 case FNERR_INVALIDFILENAME:
178 case CDERR_MEMLOCKFAILURE:
180 case FNERR_SUBCLASSFAILURE:
188 UINT_PTR CALLBACK ImportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
190 OPENFILENAME* pOpenFileName;
195 pOpenFileName = (OPENFILENAME*)lParam;
198 pOfNotify = (OFNOTIFY*)lParam;
199 if (pOfNotify->hdr.code == CDN_INITDONE) {
208 #define MAX_CUSTOM_FILTER_SIZE 50
209 TCHAR CustomFilterBuffer[MAX_CUSTOM_FILTER_SIZE];
210 TCHAR FileNameBuffer[_MAX_PATH];
211 TCHAR FileTitleBuffer[_MAX_PATH];
213 static BOOL InitOpenFileName(HWND hWnd, OPENFILENAME* pofn)
215 memset(pofn, 0, sizeof(OPENFILENAME));
216 pofn->lStructSize = sizeof(OPENFILENAME);
217 pofn->hwndOwner = hWnd;
218 pofn->hInstance = hInst;
220 pofn->lpstrFilter = _T("Registration Files\0*.reg\0Win9x/NT4 Registration Files (REGEDIT4)\0*.reg\0All Files (*.*)\0*.*\0\0");
221 pofn->lpstrCustomFilter = CustomFilterBuffer;
222 pofn->nMaxCustFilter = MAX_CUSTOM_FILTER_SIZE;
223 pofn->nFilterIndex = 0;
224 pofn->lpstrFile = FileNameBuffer;
225 pofn->nMaxFile = _MAX_PATH;
226 pofn->lpstrFileTitle = FileTitleBuffer;
227 pofn->nMaxFileTitle = _MAX_PATH;
228 /* pofn->lpstrInitialDir = _T("");*/
229 /* pofn->lpstrTitle = _T("Import Registry File");*/
230 /* pofn->Flags = OFN_ENABLETEMPLATE + OFN_EXPLORER + OFN_ENABLESIZING;*/
231 pofn->Flags = OFN_HIDEREADONLY;
232 /* pofn->nFileOffset = ;*/
233 /* pofn->nFileExtension = ;*/
234 /* pofn->lpstrDefExt = _T("");*/
235 /* pofn->lCustData = ;*/
236 /* pofn->lpfnHook = ImportRegistryFile_OFNHookProc;*/
237 /* pofn->lpTemplateName = _T("ID_DLG_IMPORT_REGFILE");*/
238 /* pofn->lpTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);*/
239 /* pofn->FlagsEx = ;*/
243 static BOOL ImportRegistryFile(HWND hWnd)
247 InitOpenFileName(hWnd, &ofn);
248 ofn.lpstrTitle = _T("Import Registry File");
249 /* ofn.lCustData = ;*/
250 if (GetOpenFileName(&ofn)) {
251 if (!import_registry_file(ofn.lpstrFile)) {
252 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
256 get_file_name(&s, filename, MAX_PATH);
258 printf("No file name is specified\n%s", usage);
262 while (filename[0]) {
263 if (!import_registry_file(filename)) {
265 printf("Can't open file \"%s\"\n", filename);
269 get_file_name(&s, filename, MAX_PATH);
273 CheckCommDlgError(hWnd);
279 static BOOL ExportRegistryFile(HWND hWnd)
282 TCHAR ExportKeyPath[_MAX_PATH];
284 ExportKeyPath[0] = _T('\0');
285 InitOpenFileName(hWnd, &ofn);
286 ofn.lpstrTitle = _T("Export Registry File");
287 /* ofn.lCustData = ;*/
288 ofn.Flags = OFN_ENABLETEMPLATE + OFN_EXPLORER;
289 ofn.lpfnHook = ImportRegistryFile_OFNHookProc;
290 ofn.lpTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);
291 if (GetSaveFileName(&ofn)) {
293 result = export_registry_key(ofn.lpstrFile, ExportKeyPath);
294 /*result = export_registry_key(ofn.lpstrFile, NULL);*/
295 /*if (!export_registry_key(ofn.lpstrFile, NULL)) {*/
297 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
301 TCHAR filename[MAX_PATH];
303 get_file_name(&s, filename, MAX_PATH);
305 printf("No file name is specified\n%s", usage);
310 TCHAR reg_key_name[KEY_MAX_LEN];
311 get_file_name(&s, reg_key_name, KEY_MAX_LEN);
312 export_registry_key(filename, reg_key_name);
314 export_registry_key(filename, NULL);
318 CheckCommDlgError(hWnd);
323 BOOL PrintRegistryHive(HWND hWnd, LPTSTR path)
328 ZeroMemory(&pd, sizeof(PRINTDLG));
329 pd.lStructSize = sizeof(PRINTDLG);
331 pd.hDevMode = NULL; /* Don't forget to free or store hDevMode*/
332 pd.hDevNames = NULL; /* Don't forget to free or store hDevNames*/
333 pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
335 pd.nFromPage = 0xFFFF;
338 pd.nMaxPage = 0xFFFF;
339 if (PrintDlg(&pd) == TRUE) {
340 /* GDI calls to render output. */
341 DeleteDC(pd.hDC); /* Delete DC when done.*/
347 hResult = PrintDlgEx(&pd);
348 if (hResult == S_OK) {
349 switch (pd.dwResultAction) {
350 case PD_RESULT_APPLY:
351 /*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. */
353 case PD_RESULT_CANCEL:
354 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
356 case PD_RESULT_PRINT:
357 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
365 /*Insufficient memory. */
368 /* One or more arguments are invalid. */
371 /*Invalid pointer. */
377 /*Unspecified error. */
388 BOOL CopyKeyName(HWND hWnd, LPTSTR keyName)
392 result = OpenClipboard(hWnd);
394 result = EmptyClipboard();
397 /*HANDLE hClipData;*/
398 /*hClipData = SetClipboardData(UINT uFormat, HANDLE hMem);*/
401 /* error emptying clipboard*/
402 /* DWORD dwError = GetLastError(); */
405 if (!CloseClipboard()) {
406 /* error closing clipboard*/
407 /* DWORD dwError = GetLastError(); */
411 /* error opening clipboard*/
412 /* DWORD dwError = GetLastError(); */
418 BOOL RefreshView(HWND hWnd)
422 MessageBeep(MB_ICONASTERISK);
423 MessageBeep(MB_ICONEXCLAMATION);
424 MessageBeep(MB_ICONHAND);
425 MessageBeep(MB_ICONQUESTION);
430 /*******************************************************************************
432 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
434 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
437 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
439 switch (LOWORD(wParam)) {
440 /* Parse the menu selections:*/
441 case ID_REGISTRY_IMPORTREGISTRYFILE:
442 ImportRegistryFile(hWnd);
444 case ID_REGISTRY_EXPORTREGISTRYFILE:
445 ExportRegistryFile(hWnd);
447 case ID_REGISTRY_CONNECTNETWORKREGISTRY:
449 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY:
451 case ID_REGISTRY_PRINT:
452 PrintRegistryHive(hWnd, _T(""));
454 case ID_EDIT_COPYKEYNAME:
455 CopyKeyName(hWnd, _T(""));
457 case ID_REGISTRY_PRINTERSETUP:
460 /*PAGESETUPDLG psd;*/
461 /*PageSetupDlg(&psd);*/
463 case ID_REGISTRY_OPENLOCAL:
465 case ID_REGISTRY_EXIT:
468 case ID_VIEW_REFRESH:
471 /* case ID_OPTIONS_TOOLBAR:*/
472 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
474 case ID_VIEW_STATUSBAR:
475 toggle_child(hWnd, LOWORD(wParam), hStatusBar);
477 case ID_HELP_HELPTOPICS:
478 /* WinHelp(hWnd, _T("regedit"), HELP_CONTENTS, 0);*/
479 WinHelp(hWnd, _T("regedit"), HELP_FINDER, 0);
483 /* ShellAbout(hWnd, szTitle, _T(""), LoadIcon(hInst, (LPCTSTR)IDI_REGEDIT));*/
494 /********************************************************************************
496 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
498 * PURPOSE: Processes messages for the main frame window.
500 * WM_COMMAND - process the application menu
501 * WM_DESTROY - post a quit message and return
505 LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
507 static ChildWnd* pChildWnd = NULL;
512 pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
513 _tcsncpy(pChildWnd->szPath, _T("My Computer"), MAX_PATH);
514 hChildWnd = CreateWindowEx(0, szChildClass, _T("regedit child window"),
515 /* WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE|WS_BORDER,*/
516 WS_CHILD|WS_VISIBLE | WS_EX_CLIENTEDGE,
517 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
518 hWnd, (HMENU)0, hInst, pChildWnd);
522 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
523 return DefWindowProc(hWnd, message, wParam, lParam);
527 resize_frame_client(hWnd);
531 case WM_ENTERMENULOOP:
532 OnEnterMenuLoop(hWnd);
534 case WM_EXITMENULOOP:
535 OnExitMenuLoop(hWnd);
538 OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
542 HeapFree(GetProcessHeap(), 0, pChildWnd);
545 WinHelp(hWnd, _T("regedit"), HELP_QUIT, 0);
548 return DefWindowProc(hWnd, message, wParam, lParam);