Close button freezes by injected input in WinUI3?

youki 966 Reputation points

The application and anything else freezes, if i click the close button by my own MOUSEEVENTF_LEFTDOWN/UP.

I'm blocking WM_LBUTTONDOWN/ UP by a mouse hook to forward my own injected input. I can click everything (buttons, listview items) except the close button.
If it freezes and i open the task manager, the window closes immediately and the WM_CLOSE gets executed, the same in Debug and Release mode.
I avoid injected input in the hook:

if (MSLLHOOKSTRUCT* pMouseStruct = (MSLLHOOKSTRUCT*)lParam; nCode >= 0 && (pMouseStruct->flags & LLMHF_INJECTED) == 0)  

It seems, as if the close button doesn't accept injected input.

What could be the solution here?


Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
655 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,321 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. youki 966 Reputation points

    Tested it with WM_LBUTTONDOWN/ UP from a keyboard key and that works. It doesn't work only with injected input from the mouse. I have no problems with any other application on my pc, Win Forms included.

    Don't know, if that is a bug?

  2. youki 966 Reputation points

    Really don't know what to do:

    Should i change to Electron. As i saw, the memory was pretty low in WinUI, in Electron it's not.

    I could safely ignore that:

    0 comments No comments

  3. Tong Xu - MSFT 116 Reputation points Microsoft Vendor

    The docunment shows: The mouse_event function synthesizes mouse motion and button clicks.

    It is recommended to use SendInput instead

    WM_LBUTTONDOWN/UP is viable, but be aware that you must get a window to create and deliver messages.