From 9565c83981a34758ddade54186eec5cc3761325a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sat, 30 May 2015 15:51:18 +0000 Subject: [PATCH 1/1] [NTVDM]: When ntvdm crashes and we restart it in the same console, do not add fresh new menu items but just keep the old ones. Patch by Christoph von Wittich, with some added comments to think about. CORE-9487 #resolve svn path=/trunk/; revision=67970 --- reactos/subsystems/mvdm/ntvdm/ntvdm.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/reactos/subsystems/mvdm/ntvdm/ntvdm.c b/reactos/subsystems/mvdm/ntvdm/ntvdm.c index 94e54145502..a6ac026e2eb 100644 --- a/reactos/subsystems/mvdm/ntvdm/ntvdm.c +++ b/reactos/subsystems/mvdm/ntvdm/ntvdm.c @@ -116,6 +116,21 @@ AppendMenuItems(HMENU hMenu, } while (!(Items[i].uID == 0 && Items[i].SubMenu == NULL && Items[i].wCmdID == 0)); } +BOOL +VdmMenuExists(HMENU hConsoleMenu) +{ + INT MenuPos, i; + MenuPos = GetMenuItemCount(hConsoleMenu); + + /* Check for the presence of one of the VDM menu items */ + for (i = 0; i <= MenuPos; i++) + { + if (GetMenuItemID(hConsoleMenu, i) == ID_SHOWHIDE_MOUSE) + return TRUE; + } + return FALSE; +} + /*static*/ VOID CreateVdmMenu(HANDLE ConOutHandle) { @@ -124,9 +139,17 @@ CreateVdmMenu(HANDLE ConOutHandle) ID_VDM_QUIT); if (hConsoleMenu == NULL) return; + /* Get the position where we are going to insert our menu items */ VdmMenuPos = GetMenuItemCount(hConsoleMenu); - AppendMenuItems(hConsoleMenu, VdmMainMenuItems); - DrawMenuBar(GetConsoleWindow()); + // FIXME: What happens if the menu already exist? + // VdmMenuPos points *after* the already existing menu! + + /* Really add the menu if it doesn't already exist (in case eg. NTVDM crashed) */ + if (!VdmMenuExists(hConsoleMenu)) + { + AppendMenuItems(hConsoleMenu, VdmMainMenuItems); + DrawMenuBar(GetConsoleWindow()); + } } /*static*/ VOID -- 2.17.1