ReactOS 0.4.17-dev-784-g3812a95
CMainWnd.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Management Console
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Main window class
5 * COPYRIGHT: Copyright 2006-2007 Thomas Weidenmueller
6 * Copyright 2017 Mark Jansen (mark.jansen@reactos.org)
7 * Copyright 2026 Eric Kohl (eric.kohl@reactos.org)
8 */
9
10#include "precomp.h"
11
13 : m_NewConsoleCount(0)
14 , m_nConsoleCount(0)
15 , m_AppAuthorMode(false)
16 , m_hSnapinImageList(NULL)
17{
19 m_pfnSuperWindowProc = m_FrameThunk.GetWNDPROC();
21 m_hMenuConsoleSmall = LoadMenu(_AtlBaseModule.GetModuleInstance(), MAKEINTRESOURCE(IDM_CONSOLE_SMALL));
22 m_hMenuConsoleLarge = LoadMenu(_AtlBaseModule.GetModuleInstance(), MAKEINTRESOURCE(IDM_CONSOLE_LARGE));
26 0,
27 4);
29}
30
32{
37}
38
41{
43 LPCTSTR lpFileName = (LPCTSTR)(((LPCREATESTRUCT)lParam)->lpCreateParams);
45 UpdateMenu();
46 SetWindowText(TEXT("ReactOS Management Console"));
49 RECT rect;
51 /* Create the MDI client window */
53 //hwndMDIClient = CreateWindowEx(WS_EX_CLIENTEDGE, L"MDICLIENT", (LPCTSTR)NULL,
54 // ,
55 // rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
56 // m_hWnd, NULL, _AtlBaseModule.GetModuleInstance(), (LPVOID)&ccs);
59 if (lpFileName == NULL)
60 {
62 }
63 return 0;
64}
65
67CMainWnd::OnNewMDIChild(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
68{
73 mcs.szTitle = title.GetString();
75 mcs.hOwner = _AtlBaseModule.GetModuleInstance();
76 mcs.x = mcs.cx = CW_USEDEFAULT;
77 mcs.y = mcs.cy = CW_USEDEFAULT;
79 BOOL bMaximized = FALSE;
80 HWND hWndOld = (HWND)m_MDIClient.SendMessage(WM_MDIGETACTIVE, 0, (LPARAM)&bMaximized);
81 mcs.lParam = bMaximized || !hWndOld;
82 /* This object registers itself in the _AtlWinModule to be assigned to the next window created */
83 CConsoleWnd* child = new CConsoleWnd(this);
84 /* Ask for a new MDI Child window */
86 if (hChild)
87 {
89 }
90 else
91 {
92 delete child;
93 }
94 UpdateMenu();
95 return 1;
96}
97
99CMainWnd::OnFileSave(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
100{
102 if (child == NULL)
103 return 0;
104 if (child->m_Filename.IsEmpty())
105 return OnFileSaveAs(wNotifyCode, wID, hWndCtl, bHandled);
106 // save, and if fails clear pFileName
107 return 0;
108}
109
111CMainWnd::OnFileSaveAs(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
112{
113 OPENFILENAME saveas;
116 if (child == NULL)
117 return 0;
118 ZeroMemory(&saveas, sizeof(saveas));
119 if (!child->m_Filename.IsEmpty())
120 {
121 _tcscpy(szPath, child->m_Filename);
122 }
123 else
124 {
125 child->GetWindowText(szPath, MAX_PATH);
126 _tcscat(szPath, TEXT(".msc"));
127 }
128 saveas.lStructSize = sizeof(OPENFILENAME);
129 saveas.hwndOwner = m_hWnd;
130 saveas.hInstance = _AtlBaseModule.GetModuleInstance();
131 saveas.lpstrFilter = L"MSC Files\0*.msc\0";
132 saveas.lpstrFile = szPath;
133 saveas.nMaxFile = MAX_PATH;
135 saveas.lpstrDefExt = L"msc";
136 if (GetSaveFileName(&saveas))
137 {
138 child->m_Filename = szPath;
139 return OnFileSave(wNotifyCode, wID, hWndCtl, bHandled);
140 }
141 else
142 {
143 return 0;
144 }
145}
146
148CMainWnd::OnFileAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
149{
151 if (child == NULL)
152 return 0;
153 CAddDialog dlg(this, child);
154 dlg.DoModal(m_hWnd, (LPARAM)child);
155 return 0;
156}
157
159CMainWnd::OnFileExit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
160{
161 PostMessage(WM_CLOSE, 0, 0);
162 return 0;
163}
164
166CMainWnd::OnHelpAbout(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
167{
168 HICON hIcon = LoadIcon(_AtlBaseModule.GetModuleInstance(), MAKEINTRESOURCE(IDI_MAINAPP));
171 CAtlString TitleString;
172
173 TitleString = AboutTitle;
174 TitleString += L"#";
175 TitleString += AppTitle;
176
177 ::ShellAboutW(this->m_hWnd, (LPWSTR)TitleString.GetString(), NULL, hIcon);
178
179 return 0;
180}
181
183CMainWnd::OnMDIForward(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
184{
186 if (hChild)
187 {
188 WPARAM wParam = MAKEWPARAM(wNotifyCode, wID);
189 LPARAM lParam = (LPARAM)hWndCtl;
191 }
192 return 0;
193}
194
197{
198 RECT rcClient;
199 GetClientRect(&rcClient);
200 m_MDIClient.SetWindowPos(NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
201 return 0;
202}
203
206{
208 UpdateMenu();
209 return 0;
210}
211
214{
216 SetMenu(NULL);
217 return 0;
218}
219
222{
224 return 0;
225}
226
229{
230 CRegKey SnapinsKey;
231 if (ERROR_SUCCESS == SnapinsKey.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\MMC\\SnapIns", KEY_READ))
232 {
233 WCHAR namebuf[MAX_PATH];
234 DWORD index = 0, namelen = _countof(namebuf);
235 while (ERROR_SUCCESS == SnapinsKey.EnumKey(index++, namebuf, &namelen))
236 {
237 DPRINT1("%S\n", namebuf);
238 CSnapinCacheEntry* snapin = CSnapinCacheEntry::Create(SnapinsKey, namebuf, m_hSnapinImageList);
239 DPRINT1("CacheEntry %p\n", snapin);
240 if (snapin)
241 {
242 m_SnapinCache.Add(snapin);
243 }
244 namelen = _countof(namebuf);
245 }
246 SnapinsKey.Close();
247 }
248 return S_OK;
249}
250
251int
253{
254 return m_SnapinCache.GetSize();
255}
256
259{
260 return m_SnapinCache[nIndex];
261}
262
265{
266 for (int i = 0; i < m_SnapinCache.GetSize(); i++)
267 {
269 if (entry->GuidString().CompareNoCase(pszGuid) == 0)
270 return entry;
271 }
272 return NULL;
273}
274
277{
278 return m_hSnapinImageList;
279}
static struct myctx * mcs
Definition: adnstest.c:53
#define IDM_CONSOLE_SMALL
Definition: resource.h:8
#define IDI_MAINAPP
Definition: resource.h:6
#define IDM_FILE_NEW
Definition: resource.h:11
#define IDM_MDI_FIRSTCHILD
Definition: resource.h:19
#define IDM_CONSOLE_LARGE
Definition: resource.h:9
#define IDS_APPTITLE
Definition: resource.h:3
#define IDS_ABOUTTITLE
Definition: resource.h:15
#define DPRINT1
Definition: precomp.h:8
#define U(x)
Definition: wordpad.c:45
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE) noexcept
Definition: atlbase.h:1173
LONG Close() noexcept
Definition: atlbase.h:1156
LONG EnumKey(DWORD iIndex, LPTSTR pszName, LPDWORD pnNameLength, FILETIME *pftLastWriteTime=NULL) noexcept
Definition: atlbase.h:1421
PXSTR GetString() noexcept
Definition: atlsimpstr.h:367
HWND Create(LPCTSTR lpstrWndClass, HWND hWndParent, _U_RECT rect=NULL, LPCTSTR szWindowName=NULL, DWORD dwStyle=0, DWORD dwExStyle=0, _U_MENUorID MenuOrID=0U, LPVOID lpCreateParam=NULL)
Definition: atlwin.h:417
BOOL SetWindowPos(HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags)
Definition: atlwin.h:1288
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1116
BOOL UpdateWindow()
Definition: atlwin.h:1345
BOOL ShowWindow(int nCmdShow)
Definition: atlwin.h:1333
WNDPROC GetWNDPROC()
Definition: atlwin.h:258
BOOL Init(WNDPROC proc, void *pThis)
Definition: atlwin.h:250
static LPCTSTR GetWndClassName()
Definition: CConsoleWnd.h:56
CMainWnd()
Definition: CMainWnd.cpp:12
bool m_AppAuthorMode
Definition: CMainWnd.h:22
CWndProcThunk m_FrameThunk
Definition: CMainWnd.h:16
LRESULT OnFileExit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
Definition: CMainWnd.cpp:159
LRESULT OnDestroy(UINT nMessage, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: CMainWnd.cpp:213
int m_nConsoleCount
Definition: CMainWnd.h:19
static LRESULT CALLBACK XDefFrameProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: CMainWnd.h:76
LRESULT OnHelpAbout(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
Definition: CMainWnd.cpp:166
int GetSnapinCacheCount()
Definition: CMainWnd.cpp:252
LRESULT OnFileAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
Definition: CMainWnd.cpp:148
LRESULT OnCreate(UINT nMessage, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: CMainWnd.cpp:40
~CMainWnd()
Definition: CMainWnd.cpp:31
void CreateNewConsoleTitle(CAtlString &str)
Definition: CMainWnd.h:103
CWindow m_MDIClient
Definition: CMainWnd.h:28
void UpdateMenu()
Definition: CMainWnd.h:84
HMENU m_hMenuConsoleSmall
Definition: CMainWnd.h:20
LRESULT OnFileSaveAs(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
Definition: CMainWnd.cpp:111
CSnapinCacheEntry * GetSnapinCacheEntry(int nIndex)
Definition: CMainWnd.cpp:258
HIMAGELIST SnapinImageList()
Definition: CMainWnd.cpp:276
HIMAGELIST m_hSnapinImageList
Definition: CMainWnd.h:25
LRESULT LoadSnapinCache()
Definition: CMainWnd.cpp:228
CConsoleWnd * GetActiveChildInfo()
Definition: CMainWnd.h:92
CSimpleArray< CSnapinCacheEntry * > m_SnapinCache
Definition: CMainWnd.h:24
HMENU m_hMenuConsoleLarge
Definition: CMainWnd.h:21
LRESULT OnCloseChild(UINT nMessage, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: CMainWnd.cpp:205
LRESULT OnClose(UINT nMessage, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: CMainWnd.cpp:221
LRESULT OnFileSave(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
Definition: CMainWnd.cpp:99
LRESULT OnSize(UINT nMessage, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: CMainWnd.cpp:196
LRESULT OnNewMDIChild(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
Definition: CMainWnd.cpp:67
LRESULT OnMDIForward(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
Definition: CMainWnd.cpp:183
CSnapinCacheEntry * GetSnapinCacheEntryByGuid(PWSTR pszGuid)
Definition: CMainWnd.cpp:264
static CSnapinCacheEntry * Create(CRegKey &SnapinsKey, PWSTR guidString, HIMAGELIST hImageList)
RECT rect
Definition: combotst.c:67
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define OFN_OVERWRITEPROMPT
Definition: commdlg.h:116
#define GetSaveFileName
Definition: commdlg.h:666
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define OFN_PATHMUSTEXIST
Definition: commdlg.h:117
OPENFILENAMEA OPENFILENAME
Definition: commdlg.h:657
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(void *reserved, DWORD model)
Definition: combase.c:2803
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:941
HIMAGELIST WINAPI ImageList_Create(INT cx, INT cy, UINT flags, INT cInitial, INT cGrow)
Definition: imagelist.c:814
HANDLE HWND
Definition: compat.h:19
#define MAX_PATH
Definition: compat.h:34
#define false
Definition: stdbool.h:25
#define L(x)
Definition: resources.c:13
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint namelen
Definition: glext.h:7232
GLuint index
Definition: glext.h:6031
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: sysinfo.c:13
char TCHAR
Definition: tchar.h:1402
#define _tcscat
Definition: tchar.h:622
#define _tcscpy
Definition: tchar.h:623
#define S_OK
Definition: intsafe.h:52
uint32_t entry
Definition: isohybrid.c:63
#define TEXT(s)
Definition: k32.h:28
#define ZeroMemory
Definition: minwinbase.h:31
LONG_PTR LPARAM
Definition: minwindef.h:175
LONG_PTR LRESULT
Definition: minwindef.h:176
UINT_PTR WPARAM
Definition: minwindef.h:174
LPCWSTR szPath
Definition: env.c:37
static HICON
Definition: imagelist.c:80
static HTREEITEM hChild
Definition: treeview.c:383
static HWND child
Definition: cursoricon.c:298
LPCSTR LPCTSTR
Definition: ms-dtyp.idl:130
HICON hIcon
Definition: msconfig.c:44
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define KEY_READ
Definition: nt_native.h:1026
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
@ COINIT_APARTMENTTHREADED
Definition: objbase.h:279
#define WS_CHILD
Definition: pedump.c:617
short WCHAR
Definition: pedump.c:58
#define WS_VSCROLL
Definition: pedump.c:627
#define WS_HSCROLL
Definition: pedump.c:628
#define WS_CLIPCHILDREN
Definition: pedump.c:619
static char title[]
Definition: ps.c:92
#define ILC_COLOR32
Definition: commctrl.h:358
#define ILC_MASK
Definition: commctrl.h:351
BOOL WINAPI ShellAboutW(HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff, HICON hIcon)
#define _countof(array)
Definition: sndvol32.h:70
LPCSTR lpstrDefExt
Definition: commdlg.h:345
HWND hwndOwner
Definition: commdlg.h:330
HINSTANCE hInstance
Definition: commdlg.h:331
LPSTR lpstrFile
Definition: commdlg.h:336
DWORD Flags
Definition: commdlg.h:342
DWORD lStructSize
Definition: commdlg.h:329
LPCSTR lpstrFilter
Definition: commdlg.h:332
DWORD nMaxFile
Definition: commdlg.h:337
LONG right
Definition: windef.h:108
LONG bottom
Definition: windef.h:109
uint16_t * PWSTR
Definition: typedefs.h:56
uint16_t * LPWSTR
Definition: typedefs.h:56
_In_ LPCSTR lpFileName
Definition: winbase.h:2800
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define MAKEWPARAM(l, h)
Definition: winuser.h:4117
#define WM_CLOSE
Definition: winuser.h:1649
BOOL WINAPI SetMenu(_In_ HWND, _In_opt_ HMENU)
#define WM_MDICREATE
Definition: winuser.h:1840
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_COMMAND
Definition: winuser.h:1768
#define SM_CYSMICON
Definition: winuser.h:1024
#define MDIS_ALLCHILDSTYLES
Definition: winuser.h:253
#define SM_CXSMICON
Definition: winuser.h:1023
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define LoadIcon
Definition: winuser.h:5979
#define SendMessage
Definition: winuser.h:6009
#define LoadMenu
Definition: winuser.h:5983
#define PostMessage
Definition: winuser.h:5998
#define CW_USEDEFAULT
Definition: winuser.h:225
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define SW_SHOW
Definition: winuser.h:786
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
#define SetWindowText
Definition: winuser.h:6023
#define WM_MDIGETACTIVE
Definition: winuser.h:1849
#define SWP_NOZORDER
Definition: winuser.h:1258
BOOL WINAPI DestroyWindow(_In_ HWND)
int WINAPI GetSystemMetrics(_In_ int)