From fba1005cd52e61a2e73f0b1ef5c1c4375097c1b9 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Mon, 7 Feb 2022 17:48:00 +0800 Subject: [PATCH] Windows QPA: Highlight the first entry in the system menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is what native Win32 applications usually do. Change-Id: I19f1170113b4064f1d683dbd13b7de7d263105f0 Reviewed-by: Mårten Nordheim Reviewed-by: André de la Rocha (cherry picked from commit 64d65a645c3f64c6b317aed571366bc049c1cd25) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/windows/qwindowskeymapper.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp index 73654010899..5954f35b070 100644 --- a/src/plugins/platforms/windows/qwindowskeymapper.cpp +++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp @@ -800,7 +800,6 @@ static void showSystemMenu(QWindow* w) bool maximized = IsZoomed(topLevelHwnd); EnableMenuItem(menu, SC_MAXIMIZE, ! (topLevel->flags() & Qt::WindowMaximizeButtonHint) || maximized?disabled:enabled); - EnableMenuItem(menu, SC_RESTORE, maximized?enabled:disabled); // We should _not_ check with the setFixedSize(x,y) case here, since Windows is not able to check // this and our menu here would be out-of-sync with the menu produced by mouse-click on the @@ -808,6 +807,15 @@ static void showSystemMenu(QWindow* w) EnableMenuItem(menu, SC_SIZE, (topLevel->flags() & Qt::MSWindowsFixedSizeDialogHint) || maximized?disabled:enabled); EnableMenuItem(menu, SC_MOVE, maximized?disabled:enabled); EnableMenuItem(menu, SC_CLOSE, enabled); + + // Highlight the first entry in the menu, this is what native Win32 applications usually do. + MENUITEMINFOW restoreItem; + SecureZeroMemory(&restoreItem, sizeof(restoreItem)); + restoreItem.cbSize = sizeof(restoreItem); + restoreItem.fMask = MIIM_STATE; + restoreItem.fState = MFS_HILITE | (maximized ? MFS_ENABLED : MFS_GRAYED); + SetMenuItemInfoW(menu, SC_RESTORE, FALSE, &restoreItem); + // Set bold on close menu item MENUITEMINFO closeItem; closeItem.cbSize = sizeof(MENUITEMINFO);