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 /*******************************************************************************
42 * Local module support methods
45 static void resize_frame_rect(HWND hWnd
, PRECT prect
)
49 if (IsWindowVisible(hToolBar)) {
50 SendMessage(hToolBar, WM_SIZE, 0, 0);
51 GetClientRect(hToolBar, &rt);
52 prect->top = rt.bottom+3;
53 prect->bottom -= rt.bottom+3;
56 if (IsWindowVisible(hStatusBar
)) {
57 SetupStatusBar(hWnd
, TRUE
);
58 GetClientRect(hStatusBar
, &rt
);
59 prect
->bottom
-= rt
.bottom
;
61 MoveWindow(g_pChildWnd
->hWnd
, prect
->left
, prect
->top
, prect
->right
, prect
->bottom
, TRUE
);
64 void resize_frame_client(HWND hWnd
)
68 GetClientRect(hWnd
, &rect
);
69 resize_frame_rect(hWnd
, &rect
);
72 /********************************************************************************/
74 static void OnEnterMenuLoop(HWND hWnd
)
78 /* Update the status bar pane sizes */
80 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (long)&nParts
);
82 SendMessage(hStatusBar
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)_T(""));
85 static void OnExitMenuLoop(HWND hWnd
)
88 /* Update the status bar pane sizes*/
89 SetupStatusBar(hWnd
, TRUE
);
93 static void OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
98 if (nFlags
& MF_POPUP
) {
99 if (hSysMenu
!= GetMenu(hWnd
)) {
100 if (nItemID
== 2) nItemID
= 5;
103 if (LoadString(hInst
, nItemID
, str
, 100)) {
104 /* load appropriate string*/
106 /* first newline terminates actual string*/
107 lpsz
= _tcschr(lpsz
, '\n');
111 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)str
);
114 void SetupStatusBar(HWND hWnd
, BOOL bResize
)
118 GetClientRect(hWnd
, &rc
);
122 SendMessage(hStatusBar
, WM_SIZE
, 0, 0);
123 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
126 void UpdateStatusBar(void)
131 size
= sizeof(text
)/sizeof(TCHAR
);
132 GetComputerName(text
, &size
);
133 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)text
);
136 static void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
138 BOOL vis
= IsWindowVisible(hchild
);
139 HMENU hMenuView
= GetSubMenu(hMenuFrame
, ID_VIEW_MENU
);
141 CheckMenuItem(hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
142 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
143 resize_frame_client(hWnd
);
146 static BOOL
CheckCommDlgError(HWND hWnd
)
148 DWORD dwErrorCode
= CommDlgExtendedError();
149 switch (dwErrorCode
) {
150 case CDERR_DIALOGFAILURE
:
152 case CDERR_FINDRESFAILURE
:
154 case CDERR_NOHINSTANCE
:
156 case CDERR_INITIALIZATION
:
160 case CDERR_LOCKRESFAILURE
:
162 case CDERR_NOTEMPLATE
:
164 case CDERR_LOADRESFAILURE
:
166 case CDERR_STRUCTSIZE
:
168 case CDERR_LOADSTRFAILURE
:
170 case FNERR_BUFFERTOOSMALL
:
172 case CDERR_MEMALLOCFAILURE
:
174 case FNERR_INVALIDFILENAME
:
176 case CDERR_MEMLOCKFAILURE
:
178 case FNERR_SUBCLASSFAILURE
:
186 UINT_PTR CALLBACK
ImportRegistryFile_OFNHookProc(HWND hdlg
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
)
188 OPENFILENAME
* pOpenFileName
;
193 pOpenFileName
= (OPENFILENAME
*)lParam
;
196 pOfNotify
= (OFNOTIFY
*)lParam
;
197 if (pOfNotify
->hdr
.code
== CDN_INITDONE
) {}
205 #define MAX_CUSTOM_FILTER_SIZE 50
206 TCHAR CustomFilterBuffer
[MAX_CUSTOM_FILTER_SIZE
];
207 TCHAR FileNameBuffer
[_MAX_PATH
];
208 TCHAR FileTitleBuffer
[_MAX_PATH
];
210 static BOOL
InitOpenFileName(HWND hWnd
, OPENFILENAME
* pofn
)
212 memset(pofn
, 0, sizeof(OPENFILENAME
));
213 pofn
->lStructSize
= sizeof(OPENFILENAME
);
214 pofn
->hwndOwner
= hWnd
;
215 pofn
->hInstance
= hInst
;
217 pofn
->lpstrFilter
= _T("Registration Files\0*.reg\0Win9x/NT4 Registration Files (REGEDIT4)\0*.reg\0All Files (*.*)\0*.*\0\0");
218 pofn
->lpstrCustomFilter
= CustomFilterBuffer
;
219 pofn
->nMaxCustFilter
= MAX_CUSTOM_FILTER_SIZE
;
220 pofn
->nFilterIndex
= 0;
221 pofn
->lpstrFile
= FileNameBuffer
;
222 pofn
->nMaxFile
= _MAX_PATH
;
223 pofn
->lpstrFileTitle
= FileTitleBuffer
;
224 pofn
->nMaxFileTitle
= _MAX_PATH
;
225 /* pofn->lpstrInitialDir = _T("");*/
226 /* pofn->lpstrTitle = _T("Import Registry File");*/
227 /* pofn->Flags = OFN_ENABLETEMPLATE + OFN_EXPLORER + OFN_ENABLESIZING;*/
228 pofn
->Flags
= OFN_HIDEREADONLY
;
229 /* pofn->nFileOffset = ;*/
230 /* pofn->nFileExtension = ;*/
231 /* pofn->lpstrDefExt = _T("");*/
232 /* pofn->lCustData = ;*/
233 /* pofn->lpfnHook = ImportRegistryFile_OFNHookProc;*/
234 /* pofn->lpTemplateName = _T("ID_DLG_IMPORT_REGFILE");*/
235 /* pofn->lpTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);*/
236 /* pofn->FlagsEx = ;*/
240 static BOOL
ImportRegistryFile(HWND hWnd
)
244 InitOpenFileName(hWnd
, &ofn
);
245 ofn
.lpstrTitle
= _T("Import Registry File");
246 /* ofn.lCustData = ;*/
247 if (GetOpenFileName(&ofn
)) {
248 /* FIXME - convert to ascii */
249 if (!import_registry_file((LPSTR
)ofn
.lpstrFile
)) {
250 /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
254 get_file_name(&s
, filename
, MAX_PATH
);
256 printf("No file name is specified\n%s", usage
);
260 while (filename
[0]) {
261 if (!import_registry_file(filename
)) {
263 printf("Can't open file \"%s\"\n", filename
);
267 get_file_name(&s
, filename
, MAX_PATH
);
272 CheckCommDlgError(hWnd
);
278 static BOOL
ExportRegistryFile(HWND hWnd
)
281 TCHAR ExportKeyPath
[_MAX_PATH
];
283 ExportKeyPath
[0] = _T('\0');
284 InitOpenFileName(hWnd
, &ofn
);
285 ofn
.lpstrTitle
= _T("Export Registry File");
286 /* ofn.lCustData = ;*/
287 ofn
.Flags
= OFN_ENABLETEMPLATE
+ OFN_EXPLORER
;
288 ofn
.lpfnHook
= ImportRegistryFile_OFNHookProc
;
289 ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_DIALOG1
);
290 if (GetSaveFileName(&ofn
)) {
292 /* FIXME - convert strings to ascii! */
293 result
= export_registry_key((CHAR
*)ofn
.lpstrFile
, (CHAR
*)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((CHAR
)filename
, reg_key_name
);
314 export_registry_key(filename
, NULL
);
319 CheckCommDlgError(hWnd
);
324 BOOL
PrintRegistryHive(HWND hWnd
, LPTSTR path
)
329 ZeroMemory(&pd
, sizeof(PRINTDLG
));
330 pd
.lStructSize
= sizeof(PRINTDLG
);
332 pd
.hDevMode
= NULL
; /* Don't forget to free or store hDevMode*/
333 pd
.hDevNames
= NULL
; /* Don't forget to free or store hDevNames*/
334 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
;
336 pd
.nFromPage
= 0xFFFF;
339 pd
.nMaxPage
= 0xFFFF;
340 if (PrintDlg(&pd
) == TRUE
) {
341 /* GDI calls to render output. */
342 DeleteDC(pd
.hDC
); /* Delete DC when done.*/
348 hResult
= PrintDlgEx(&pd
);
349 if (hResult
== S_OK
) {
350 switch (pd
.dwResultAction
) {
351 case PD_RESULT_APPLY
:
352 /*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. */
354 case PD_RESULT_CANCEL
:
355 /*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
357 case PD_RESULT_PRINT
:
358 /*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
366 /*Insufficient memory. */
369 /* One or more arguments are invalid. */
372 /*Invalid pointer. */
378 /*Unspecified error. */
389 BOOL
CopyKeyName(HWND hWnd
, LPTSTR keyName
)
393 result
= OpenClipboard(hWnd
);
395 result
= EmptyClipboard();
398 /*HANDLE hClipData;*/
399 /*hClipData = SetClipboardData(UINT uFormat, HANDLE hMem);*/
402 /* error emptying clipboard*/
403 /* DWORD dwError = GetLastError(); */
406 if (!CloseClipboard()) {
407 /* error closing clipboard*/
408 /* DWORD dwError = GetLastError(); */
412 /* error opening clipboard*/
413 /* DWORD dwError = GetLastError(); */
419 BOOL
RefreshView(HWND hWnd
)
423 MessageBeep(MB_ICONASTERISK
);
424 MessageBeep(MB_ICONEXCLAMATION
);
425 MessageBeep(MB_ICONHAND
);
426 MessageBeep(MB_ICONQUESTION
);
431 /*******************************************************************************
433 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
435 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
438 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
440 HKEY hKeyRoot
= 0, hKey
= 0;
444 REGSAM regsam
= KEY_READ
;
448 switch (LOWORD(wParam
)) {
449 case ID_REGISTRY_IMPORTREGISTRYFILE
:
450 ImportRegistryFile(hWnd
);
452 case ID_REGISTRY_EXPORTREGISTRYFILE
:
453 ExportRegistryFile(hWnd
);
455 case ID_REGISTRY_CONNECTNETWORKREGISTRY
:
457 case ID_REGISTRY_DISCONNECTNETWORKREGISTRY
:
459 case ID_REGISTRY_PRINT
:
460 PrintRegistryHive(hWnd
, _T(""));
462 case ID_REGISTRY_EXIT
:
465 case ID_VIEW_STATUSBAR
:
466 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
468 case ID_HELP_HELPTOPICS
:
469 WinHelp(hWnd
, _T("regedit"), HELP_FINDER
, 0);
478 GetClientRect(g_pChildWnd
->hWnd
, &rt
);
479 pt
.x
= rt
.left
+ g_pChildWnd
->nSplitPos
;
480 pt
.y
= (rt
.bottom
/ 2);
482 if(ClientToScreen(g_pChildWnd
->hWnd
, &pts
))
484 SetCursorPos(pts
.x
, pts
.y
);
485 SetCursor(LoadCursor(0, IDC_SIZEWE
));
486 SendMessage(g_pChildWnd
->hWnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(pt
.x
, pt
.y
));
496 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
497 valueName
= GetValueName(g_pChildWnd
->hListWnd
);
499 lRet
= RegOpenKeyEx(hKeyRoot
, keyPath
, 0, regsam
, &hKey
);
500 if (lRet
!= ERROR_SUCCESS
) hKey
= 0;
503 switch (LOWORD(wParam
)) {
505 if (valueName
&& ModifyValue(hWnd
, hKey
, valueName
))
506 RefreshListView(g_pChildWnd
->hListWnd
, hKeyRoot
, keyPath
);
509 if(ListView_GetSelectedCount(g_pChildWnd
->hListWnd
) == 1)
511 item
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
| LVNI_SELECTED
);
514 ListView_EditLabel(g_pChildWnd
->hListWnd
, item
);
518 case ID_EDIT_COPYKEYNAME
:
519 CopyKeyName(hWnd
, _T(""));
521 case ID_REGISTRY_PRINTERSETUP
:
524 /*PAGESETUPDLG psd;*/
525 /*PageSetupDlg(&psd);*/
527 case ID_REGISTRY_OPENLOCAL
:
530 case ID_VIEW_REFRESH
:
533 /*case ID_OPTIONS_TOOLBAR:*/
534 /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
545 /********************************************************************************
547 * FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
549 * PURPOSE: Processes messages for the main frame window.
551 * WM_COMMAND - process the application menu
552 * WM_DESTROY - post a quit message and return
556 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
560 CreateWindowEx(0, szChildClass
, _T("regedit child window"), WS_CHILD
| WS_VISIBLE
,
561 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
562 hWnd
, (HMENU
)0, hInst
, 0);
565 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
566 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
569 resize_frame_client(hWnd
);
573 case WM_ENTERMENULOOP
:
574 OnEnterMenuLoop(hWnd
);
576 case WM_EXITMENULOOP
:
577 OnExitMenuLoop(hWnd
);
580 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
583 WinHelp(hWnd
, _T("regedit"), HELP_QUIT
, 0);
586 return DefWindowProc(hWnd
, message
, wParam
, lParam
);