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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 static const TCHAR szMMCMainFrame
[] = TEXT("MMCMainFrame");
23 static const TCHAR szMMCChildFrm
[] = TEXT("MMCChildFrm");
25 static LONG MainFrameWndCount
= 0;
26 static ULONG NewConsoleCount
= 0;
29 CreateNewConsoleTitle(VOID
)
33 if (LoadAndFormatString(hAppInstance
,
36 ++NewConsoleCount
) == 0)
44 typedef struct _CONSOLE_MAINFRAME_WND
47 LPCTSTR lpConsoleTitle
;
48 HMENU hMenuConsoleRoot
;
54 DWORD AppAuthorMode
: 1;
57 } CONSOLE_MAINFRAME_WND
, *PCONSOLE_MAINFRAME_WND
;
59 static LRESULT CALLBACK
60 ConsoleMainFrameWndProc(IN HWND hwnd
,
65 PCONSOLE_MAINFRAME_WND Info
;
68 Info
= (PCONSOLE_MAINFRAME_WND
)GetWindowLongPtr(hwnd
,
71 if (Info
!= NULL
|| uMsg
== WM_NCCREATE
)
77 switch (LOWORD(wParam
))
93 Info
= HeapAlloc(hAppHeap
,
103 SetWindowLongPtr(hwnd
,
107 Info
->hMenuConsoleRoot
= LoadMenu(hAppInstance
,
108 MAKEINTRESOURCE(IDM_CONSOLEROOT
));
116 LPCTSTR lpFileName
= (LPCTSTR
)(((LPCREATESTRUCT
)lParam
)->lpCreateParams
);
118 if (lpFileName
!= NULL
)
124 Info
->AppAuthorMode
= TRUE
;
125 Info
->lpConsoleTitle
= CreateNewConsoleTitle();
128 SetWindowText(Info
->hwnd
,
129 Info
->lpConsoleTitle
);
137 if (Info
->hMenuConsoleRoot
!= NULL
)
139 DestroyMenu(Info
->hMenuConsoleRoot
);
140 Info
->hMenuConsoleRoot
= NULL
;
147 if (--MainFrameWndCount
== 0)
157 goto HandleDefaultMsg
;
163 Ret
= DefWindowProc(hwnd
,
172 typedef struct _CONSOLE_CHILDFRM_WND
175 PCONSOLE_MAINFRAME_WND MainFrame
;
176 } CONSOLE_CHILDFRM_WND
, *PCONSOLE_CHILDFRM_WND
;
178 static LRESULT CALLBACK
179 ConsoleChildFrmProc(IN HWND hwnd
,
184 PCONSOLE_CHILDFRM_WND Info
;
187 Info
= (PCONSOLE_CHILDFRM_WND
)GetWindowLongPtr(hwnd
,
190 if (Info
!= NULL
|| uMsg
== WM_NCCREATE
)
195 Info
= HeapAlloc(hAppHeap
,
205 SetWindowLongPtr(hwnd
,
221 goto HandleDefaultMsg
;
227 Ret
= DefWindowProc(hwnd
,
238 RegisterMMCWndClasses(VOID
)
243 /* Register the MMCMainFrame window class */
245 wc
.lpfnWndProc
= ConsoleMainFrameWndProc
;
247 wc
.cbWndExtra
= sizeof(PCONSOLE_MAINFRAME_WND
);
248 wc
.hInstance
= hAppInstance
;
249 wc
.hIcon
= LoadIcon(hAppInstance
,
250 MAKEINTRESOURCE(IDI_MAINAPP
));
251 wc
.hCursor
= LoadCursor(NULL
,
252 MAKEINTRESOURCE(IDC_ARROW
));
253 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
254 wc
.lpszMenuName
= NULL
;
255 wc
.lpszClassName
= szMMCMainFrame
;
257 Ret
= (RegisterClass(&wc
) != (ATOM
)0);
260 /* Register the MMCChildFrm window class */
261 wc
.lpfnWndProc
= ConsoleChildFrmProc
;
262 wc
.cbWndExtra
= sizeof(PCONSOLE_CHILDFRM_WND
);
263 wc
.lpszClassName
= szMMCChildFrm
;
265 Ret
= (RegisterClass(&wc
) != (ATOM
)0);
268 UnregisterClass(szMMCMainFrame
,
277 UnregisterMMCWndClasses(VOID
)
279 UnregisterClass(szMMCChildFrm
,
281 UnregisterClass(szMMCMainFrame
,
286 CreateConsoleWindow(IN LPCTSTR lpFileName OPTIONAL
)
289 LONG_PTR FileName
= (LONG_PTR
)lpFileName
;
291 hWndConsole
= CreateWindowEx(WS_EX_WINDOWEDGE
,
294 WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
,
304 if (hWndConsole
!= NULL
)
306 ShowWindow(hWndConsole
,