【resolved】maui TrayIcon with ContextMenuStrip not close when app lose focus (windows)

zd yu 41 Reputation points MVP
2022-12-12T14:57:39.323+00:00

i am learning maui.

https://github.com/yuzd/maui_chatgpt/blob/master/chatgpt/Platforms/Windows/NativeWindowing/WindowMessageSink.cs#L193-L250

The above source code shows the tray icon with menu created by winapi.

How to close this menu in response to mouse click events(any click include from other apps)

0v53m12000a9rnhqi1391.png

~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0v56312000a9rnzcx9AD3.png

Windows development | Windows API - Win32
Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. zd yu 41 Reputation points MVP
    2022-12-14T12:09:00.51+00:00
    SetForegroundWindow(hDlg);  
      
    // Display the menu  
    TrackPopupMenu( hSubMenu,  
    TPM_RIGHTBUTTON,  
    pt.x,  
    pt.y,  
    0,  
    hDlg,  
    NULL);  
      
    PostMessage(hDlg, WM_NULL, 0, 0);  
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.