2 * ReactOS Management Console
3 * Copyright (C) 2006 - 2007 Thomas Weidenmueller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 typedef struct _CONSOLE_MAINFRAME_WND
32 HMENU hMenuConsoleSmall
;
33 HMENU hMenuConsoleLarge
;
40 DWORD AppAuthorMode
: 1;
43 } CONSOLE_MAINFRAME_WND
, *PCONSOLE_MAINFRAME_WND
;
45 typedef struct _CONSOLE_CHILDFRM_WND
48 PCONSOLE_MAINFRAME_WND MainFrame
;
50 } CONSOLE_CHILDFRM_WND
, *PCONSOLE_CHILDFRM_WND
;
52 static const TCHAR szMMCMainFrame
[] = TEXT("MMCMainFrame");
53 static const TCHAR szMMCChildFrm
[] = TEXT("MMCChildFrm");
55 static ULONG NewConsoleCount
= 0;
58 GetActiveChildInfo(VOID
)
62 hWndMDIChild
= (HWND
)SendMessageW(hwndMDIClient
, WM_MDIGETACTIVE
, 0, 0);
63 if (hWndMDIChild
== NULL
)
66 return (PCONSOLE_CHILDFRM_WND
)GetWindowLongPtr(hWndMDIChild
, 0);
71 CreateNewConsoleTitle(VOID
)
75 if (LoadAndFormatString(hAppInstance
,
78 ++NewConsoleCount
) == 0)
87 CreateNewMDIChild(PCONSOLE_MAINFRAME_WND Info
,
93 mcs
.szTitle
= CreateNewConsoleTitle();
94 mcs
.szClass
= szMMCChildFrm
;
95 mcs
.hOwner
= GetModuleHandle(NULL
);
96 mcs
.x
= mcs
.cx
= CW_USEDEFAULT
;
97 mcs
.y
= mcs
.cy
= CW_USEDEFAULT
;
98 mcs
.style
= MDIS_ALLCHILDSTYLES
;
100 hChild
= (HWND
)SendMessage(hwndMDIClient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
103 Info
->nConsoleCount
++;
111 FrameOnCreate(HWND hwnd
,
114 PCONSOLE_MAINFRAME_WND Info
;
115 CLIENTCREATESTRUCT ccs
;
116 LPCTSTR lpFileName
= (LPCTSTR
)(((LPCREATESTRUCT
)lParam
)->lpCreateParams
);
118 Info
= HeapAlloc(hAppHeap
,
120 sizeof(CONSOLE_MAINFRAME_WND
));
126 SetWindowLongPtr(hwnd
,
130 Info
->hMenuConsoleSmall
= LoadMenu(hAppInstance
,
131 MAKEINTRESOURCE(IDM_CONSOLE_SMALL
));
133 Info
->hMenuConsoleLarge
= LoadMenu(hAppInstance
,
134 MAKEINTRESOURCE(IDM_CONSOLE_LARGE
));
136 if (lpFileName
== NULL
)
139 Info
->AppAuthorMode
= TRUE
;
140 // Info->lpConsoleTitle = TEXT("ReactOS Management Console");
144 Info
->AppAuthorMode
= TRUE
;
145 // Info->lpConsoleTitle = CreateNewConsoleTitle();
149 Info
->hMenuConsoleSmall
);
151 SetWindowText(Info
->hwnd
, TEXT("ReactOS Management Console"));
153 ccs
.hWindowMenu
= GetSubMenu(Info
->hMenuConsoleLarge
, 1);
154 ccs
.idFirstChild
= IDM_MDI_FIRSTCHILD
;
156 /* Create the MDI client window */
157 hwndMDIClient
= CreateWindowEx(WS_EX_CLIENTEDGE
,
160 WS_CHILD
| WS_CLIPCHILDREN
| WS_VSCROLL
| WS_HSCROLL
| WS_VISIBLE
| WS_BORDER
,
170 ShowWindow(Info
->hwndMDIClient
, SW_SHOW
);
178 PCONSOLE_CHILDFRM_WND Info
,
181 DPRINT1("SetFileName(&p \'%S\')\n", Info
, pFileName
);
183 if (Info
->pFileName
!= NULL
)
185 HeapFree(GetProcessHeap(), 0, Info
->pFileName
);
186 Info
->pFileName
= NULL
;
189 if (pFileName
!= NULL
)
191 Info
->pFileName
= HeapAlloc(GetProcessHeap(),
193 (_tcslen(pFileName
) + 1) * sizeof(TCHAR
));
194 if (Info
->pFileName
!= NULL
)
195 _tcscpy(Info
->pFileName
, pFileName
);
202 PCONSOLE_CHILDFRM_WND pChildInfo
);
207 PCONSOLE_CHILDFRM_WND pChildInfo
)
209 DPRINT1("pChildInfo %p\n", pChildInfo
);
211 DPRINT1("FileName %S\n", pChildInfo
->pFileName
);
213 if (pChildInfo
->pFileName
== NULL
)
214 return DoSaveFileAs(hWnd
, pChildInfo
);
216 /* FIXME: Save the console here! */
224 PCONSOLE_CHILDFRM_WND pChildInfo
)
227 TCHAR szPath
[MAX_PATH
];
229 DPRINT1("pChildInfo %p\n", pChildInfo
);
230 DPRINT1("FileName %S\n", pChildInfo
->pFileName
);
232 ZeroMemory(&saveas
, sizeof(saveas
));
234 if (pChildInfo
->pFileName
!= NULL
)
236 _tcscpy(szPath
, pChildInfo
->pFileName
);
240 GetWindowText(pChildInfo
->hwnd
, szPath
, MAX_PATH
);
241 _tcscat(szPath
, TEXT(".msc"));
244 saveas
.lStructSize
= sizeof(OPENFILENAME
);
245 saveas
.hwndOwner
= hWnd
;
246 saveas
.hInstance
= hAppInstance
;
247 saveas
.lpstrFilter
= L
"MSC Files\0*.msc\0";
248 saveas
.lpstrFile
= szPath
;
249 saveas
.nMaxFile
= MAX_PATH
;
250 saveas
.Flags
= OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
;
251 saveas
.lpstrDefExt
= L
"msc";
253 if (GetSaveFileName(&saveas
))
255 /* HACK: Because in ROS, Save-As boxes don't check the validity
256 * of file names and thus, here, szPath can be invalid !! We only
257 * see its validity when we call DoSaveFile()... */
258 SetFileName(pChildInfo
, szPath
);
260 if (DoSaveFile(hWnd
, pChildInfo
))
262 // UpdateWindowCaption();
267 SetFileName(pChildInfo
, NULL
);
281 PCONSOLE_CHILDFRM_WND pChildInfo
;
283 pChildInfo
= GetActiveChildInfo();
284 if (pChildInfo
== NULL
)
287 return DoSaveFile(hWnd
, pChildInfo
);
295 PCONSOLE_CHILDFRM_WND pChildInfo
;
297 pChildInfo
= GetActiveChildInfo();
298 if (pChildInfo
== NULL
)
301 return DoSaveFileAs(hWnd
, pChildInfo
);
305 FrameOnCommand(HWND hwnd
,
310 PCONSOLE_MAINFRAME_WND Info
;
313 Info
= (PCONSOLE_MAINFRAME_WND
)GetWindowLongPtr(hwnd
, 0);
315 switch (LOWORD(wParam
))
318 CreateNewMDIChild(Info
, hwndMDIClient
);
320 Info
->hMenuConsoleLarge
);
327 case IDM_FILE_SAVEAS
:
332 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
336 if (LOWORD(wParam
) >= IDM_MDI_FIRSTCHILD
)
338 DefFrameProc(hwnd
, hwndMDIClient
, uMsg
, wParam
, lParam
);
342 hChild
= (HWND
)SendMessage(hwndMDIClient
, WM_MDIGETACTIVE
, 0, 0);
345 SendMessage(hChild
, WM_COMMAND
, wParam
, lParam
);
354 FrameOnSize(HWND hMainWnd
,
358 RECT rcClient
; //, rcTool, rcStatus;
359 // int lvHeight, iToolHeight, iStatusHeight;
361 /* Size toolbar and get height */
362 // SendMessage(Info->hTool, TB_AUTOSIZE, 0, 0);
363 // GetWindowRect(Info->hTool, &rcTool);
364 // iToolHeight = rcTool.bottom - rcTool.top;
366 /* Size status bar and get height */
367 // SendMessage(Info->hStatus, WM_SIZE, 0, 0);
368 // GetWindowRect(Info->hStatus, &rcStatus);
369 // iStatusHeight = rcStatus.bottom - rcStatus.top;
371 /* Calculate remaining height and size list view */
372 GetClientRect(hMainWnd
, &rcClient
);
373 // lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;
374 SetWindowPos(hwndMDIClient
, //Info->hTreeView,
379 rcClient
.bottom
, //lvHeight,
384 static LRESULT CALLBACK
385 ConsoleMainFrameWndProc(IN HWND hwnd
,
390 PCONSOLE_MAINFRAME_WND Info
;
392 Info
= (PCONSOLE_MAINFRAME_WND
)GetWindowLongPtr(hwnd
,
398 return FrameOnCreate(hwnd
,
424 if (Info
->hMenuConsoleSmall
!= NULL
)
426 DestroyMenu(Info
->hMenuConsoleSmall
);
427 Info
->hMenuConsoleSmall
= NULL
;
430 if (Info
->hMenuConsoleLarge
!= NULL
)
432 DestroyMenu(Info
->hMenuConsoleLarge
);
433 Info
->hMenuConsoleLarge
= NULL
;
444 case WM_USER_CLOSE_CHILD
:
445 Info
->nConsoleCount
--;
446 if (Info
->nConsoleCount
== 0)
449 Info
->hMenuConsoleSmall
);
454 return DefFrameProc(hwnd
,
465 static LRESULT CALLBACK
466 ConsoleChildFrmProc(IN HWND hwnd
,
471 PCONSOLE_CHILDFRM_WND Info
;
473 Info
= (PCONSOLE_CHILDFRM_WND
)GetWindowLongPtr(hwnd
,
479 Info
= HeapAlloc(hAppHeap
,
481 sizeof(CONSOLE_CHILDFRM_WND
));
486 SetWindowLongPtr(hwnd
,
496 HeapFree(hAppHeap
, 0, Info
->pFileName
);
498 HeapFree(hAppHeap
, 0, Info
);
501 PostMessage(hwndMainConsole
, WM_USER_CLOSE_CHILD
, 0, 0);
505 return DefMDIChildProc(hwnd
, uMsg
, wParam
, lParam
);
513 RegisterMMCWndClasses(VOID
)
518 /* Register the MMCMainFrame window class */
519 wc
.cbSize
= sizeof(WNDCLASSEX
);
521 wc
.lpfnWndProc
= ConsoleMainFrameWndProc
;
523 wc
.cbWndExtra
= sizeof(PCONSOLE_MAINFRAME_WND
);
524 wc
.hInstance
= hAppInstance
;
525 wc
.hIcon
= LoadIcon(hAppInstance
,
526 MAKEINTRESOURCE(IDI_MAINAPP
));
527 wc
.hCursor
= LoadCursor(NULL
,
528 MAKEINTRESOURCE(IDC_ARROW
));
529 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
530 wc
.lpszMenuName
= NULL
;
531 wc
.lpszClassName
= szMMCMainFrame
;
533 Ret
= (RegisterClassEx(&wc
) != (ATOM
)0);
537 /* Register the MMCChildFrm window class */
538 wc
.cbSize
= sizeof(WNDCLASSEX
);
539 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
540 wc
.lpfnWndProc
= ConsoleChildFrmProc
;
542 wc
.cbWndExtra
= sizeof(PCONSOLE_CHILDFRM_WND
);
543 wc
.hInstance
= hAppInstance
;
544 wc
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
545 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
546 wc
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+1);
547 wc
.lpszMenuName
= NULL
;
548 wc
.lpszClassName
= szMMCChildFrm
;
549 wc
.hIconSm
= LoadIcon(NULL
, IDI_APPLICATION
);
551 Ret
= (RegisterClassEx(&wc
) != (ATOM
)0);
554 UnregisterClass(szMMCMainFrame
,
563 UnregisterMMCWndClasses(VOID
)
565 UnregisterClass(szMMCChildFrm
,
567 UnregisterClass(szMMCMainFrame
,
572 CreateConsoleWindow(IN LPCTSTR lpFileName OPTIONAL
,
576 LONG_PTR FileName
= (LONG_PTR
)lpFileName
;
578 hWndConsole
= CreateWindowEx(WS_EX_WINDOWEDGE
,
581 WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
591 if (hWndConsole
!= NULL
)
593 ShowWindow(hWndConsole
, nCmdShow
);