diff --git a/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c b/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c index 9da1e92e76d..13f5da948f8 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) + + 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) diff --git a/win32ss/user/winsrv/consrv/frontends/gui/conwnd.h b/win32ss/user/winsrv/consrv/frontends/gui/conwnd.h index 1efc2103cb0..6a5215fb693 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 2b2e9d4f27f..c811c4c030c 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; }