简体   繁体   中英

How to disable 3rd party event loop

I use SetWinEventHook to handle 3rd party actions, for example EVENT_SYSTEM_MINIMIZESTART event.

How can I prevent this app from minimizing? I mean I need something like WinForms e.Cancel = true;

How could it work: 3rd party application is minimizing, my app capture this action, cancels it, then ask Do you really want to minimize %appname%? , then use SendMessage to minimize it if user clicks on Yes button. Here is HookCreation:

    public Hook(IntPtr hWnd)
    {
        lpfnWinEventProc = WinEvent;
        handle = GCHandle.Alloc(lpfnWinEventProc);
        pHook = SetWinEventHook((uint)SystemEvents.EVENT_MIN,
                                (uint)SystemEvents.EVENT_MAX,
                                hWnd,
                                lpfnWinEventProc,
                                0,
                                0,
                                WINEVENT_OUTOFCONTEXT
            );
        if (IntPtr.Zero.Equals(pHook))
            throw new Win32Exception();
    }

The only hook that allows you to filter messages is a CBT Hook . If the list of operations that are reported through this hook is not sufficient, you may find a solution by installing a GetMsgProc hook. This allows you to modify the message. Replacing appropriate incoming messages with a WM_NULL message is essentially the same as cancelling the message. This only works for messages that are posted to the message queue. Sent messages are not filtered through this hook.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM