[CONSRV] Cache the console window system menu handle; simplify its initialization code.

This commit is contained in:
Hermès Bélusca-Maïto 2019-04-28 21:47:55 +02:00
parent cf48f8bf8a
commit 0aed8b09a4
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 29 additions and 24 deletions

View file

@ -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)
hMenu = GetSystemMenu(hWnd, FALSE);
if (hMenu == NULL)
return;
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_STRING;
mii.dwTypeData = szMenuStringBack;
mii.cch = ARRAYSIZE(szMenuStringBack);
GetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
ptrTab = wcschr(szMenuStringBack, L'\t');
if (ptrTab)
{
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_STRING;
mii.dwTypeData = szMenuStringBack;
mii.cch = sizeof(szMenuStringBack)/sizeof(WCHAR);
*ptrTab = L'\0';
mii.cch = wcslen(szMenuStringBack);
GetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
ptrTab = wcschr(szMenuStringBack, '\t');
if (ptrTab)
{
*ptrTab = '\0';
mii.cch = wcslen(szMenuStringBack);
SetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
}
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)

View file

@ -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 */

View file

@ -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;
}