From 53a70e1ad71e5ba91f9a6aa5e02b3a95b2247c93 Mon Sep 17 00:00:00 2001 From: dreamforceinc Date: Tue, 26 Dec 2023 13:22:15 +0300 Subject: [PATCH] Fixed menu tracking according to Microsoft documentation. --- wCenterWindow/wCenterWindow.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index d073ef6..c6b84f1 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -341,10 +341,15 @@ LRESULT CALLBACK WndProc(HWND hMainWnd, UINT message, WPARAM wParam, LPARAM lPar { logger.Out(L"%s(%d): Entering the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__); - SetForegroundWindow(hMainWnd); POINT pt; GetCursorPos(&pt); - int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hMainWnd, NULL); + SetForegroundWindow(hMainWnd); + + UINT uFlags = TPM_RETURNCMD | TPM_RIGHTBUTTON; + GetSystemMetrics(SM_MENUDROPALIGNMENT) != 0 ? uFlags |= TPM_RIGHTALIGN : uFlags |= TPM_LEFTALIGN; + + int idMenu = TrackPopupMenuEx(hPopup, uFlags, pt.x, pt.y, hMainWnd, NULL); + PostMessageW(hMainWnd, WM_NULL, 0, 0); if (ID_POPUPMENU_ICON == idMenu) { logger.Out(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__); @@ -383,7 +388,7 @@ LRESULT CALLBACK WndProc(HWND hMainWnd, UINT message, WPARAM wParam, LPARAM lPar { logger.Out(L"%s(%d): Pressed the 'Exit' menuitem", TEXT(__FUNCTION__), __LINE__); - PostQuitMessage(0); + DestroyWindow(hMainWnd); } logger.Out(L"%s(%d): Exit from the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__);