https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0aed8b09a411b6c2ef4af…
commit 0aed8b09a411b6c2ef4af5976c2f80a40f0b2604
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Apr 28 21:47:55 2019 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Apr 28 21:47:55 2019 +0200
[CONSRV] Cache the console window system menu handle; simplify its initialization
code.
---
win32ss/user/winsrv/consrv/frontends/gui/conwnd.c | 40 ++++++++++++----------
win32ss/user/winsrv/consrv/frontends/gui/conwnd.h | 1 +
win32ss/user/winsrv/consrv/frontends/gui/guiterm.c | 8 ++---
3 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
b/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
index 9da1e92e76..13f5da948f 100644
--- a/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
+++ b/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
@@ -231,30 +231,32 @@ VOID
CreateSysMenu(HWND hWnd)
{
MENUITEMINFOW mii;
+ HMENU hMenu;
+ PWCHAR ptrTab;
WCHAR szMenuStringBack[255];
- WCHAR *ptrTab;
- HMENU hMenu = GetSystemMenu(hWnd, FALSE);
- if (hMenu != NULL)
- {
- mii.cbSize = sizeof(mii);
- mii.fMask = MIIM_STRING;
- mii.dwTypeData = szMenuStringBack;
- mii.cch = sizeof(szMenuStringBack)/sizeof(WCHAR);
- GetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
+ hMenu = GetSystemMenu(hWnd, FALSE);
+ if (hMenu == NULL)
+ return;
- ptrTab = wcschr(szMenuStringBack, '\t');
- if (ptrTab)
- {
- *ptrTab = '\0';
- mii.cch = wcslen(szMenuStringBack);
+ mii.cbSize = sizeof(mii);
+ mii.fMask = MIIM_STRING;
+ mii.dwTypeData = szMenuStringBack;
+ mii.cch = ARRAYSIZE(szMenuStringBack);
- SetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
- }
+ GetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
+
+ ptrTab = wcschr(szMenuStringBack, L'\t');
+ if (ptrTab)
+ {
+ *ptrTab = L'\0';
+ mii.cch = wcslen(szMenuStringBack);
- AppendMenuItems(hMenu, GuiConsoleMainMenuItems);
- DrawMenuBar(hWnd);
+ SetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
}
+
+ AppendMenuItems(hMenu, GuiConsoleMainMenuItems);
+ DrawMenuBar(hWnd);
}
static VOID
@@ -597,6 +599,7 @@ OnNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
Console = GuiData->Console;
GuiData->hWindow = hWnd;
+ GuiData->hSysMenu = GetSystemMenu(hWnd, FALSE);
/* Initialize the fonts */
if (!InitFonts(GuiData,
@@ -1370,6 +1373,7 @@ OnNcDestroy(HWND hWnd)
/* Free the GuiData registration */
SetWindowLongPtrW(hWnd, GWLP_USERDATA, (DWORD_PTR)NULL);
+ /* Reset the system menu back to default and destroy the previous menu */
GetSystemMenu(hWnd, TRUE);
if (GuiData)
diff --git a/win32ss/user/winsrv/consrv/frontends/gui/conwnd.h
b/win32ss/user/winsrv/consrv/frontends/gui/conwnd.h
index 1efc2103cb..6a5215fb69 100644
--- a/win32ss/user/winsrv/consrv/frontends/gui/conwnd.h
+++ b/win32ss/user/winsrv/consrv/frontends/gui/conwnd.h
@@ -73,6 +73,7 @@ typedef struct _GUI_CONSOLE_DATA
BOOL HackCORE8394IgnoreNextMove; /* HACK FOR CORE-8394. See conwnd.c!OnMouse for more
details. */
+ HMENU hSysMenu; /* Handle to the console window system menu */
BOOL IsCloseButtonEnabled; /* TRUE if the Close button and the corresponding system
menu item are enabled (default), FALSE otherwise */
UINT CmdIdLow ; /* Lowest menu id of the user-reserved menu id range */
UINT CmdIdHigh; /* Highest menu id of the user-reserved menu id range */
diff --git a/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
b/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
index 2b2e9d4f27..c811c4c030 100644
--- a/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
+++ b/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
@@ -96,6 +96,7 @@ InvalidateCell(PGUI_CONSOLE_DATA GuiData,
* GUI Terminal Initialization *
******************************************************************************/
+// FIXME: HACK: Potential HACK for CORE-8129; see revision 63595.
VOID
CreateSysMenu(HWND hWnd);
@@ -1116,7 +1117,7 @@ GuiMenuControl(IN OUT PFRONTEND This,
GuiData->CmdIdLow = CmdIdLow ;
GuiData->CmdIdHigh = CmdIdHigh;
- return GetSystemMenu(GuiData->hWindow, FALSE);
+ return GuiData->hSysMenu;
}
static BOOL NTAPI
@@ -1130,12 +1131,11 @@ GuiSetMenuClose(IN OUT PFRONTEND This,
*/
PGUI_CONSOLE_DATA GuiData = This->Context;
- HMENU hSysMenu = GetSystemMenu(GuiData->hWindow, FALSE);
- if (hSysMenu == NULL) return FALSE;
+ if (GuiData->hSysMenu == NULL) return FALSE;
GuiData->IsCloseButtonEnabled = Enable;
- EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | (Enable ? MF_ENABLED :
MF_GRAYED));
+ EnableMenuItem(GuiData->hSysMenu, SC_CLOSE, MF_BYCOMMAND | (Enable ? MF_ENABLED :
MF_GRAYED));
return TRUE;
}