如何禁用第 3 方事件循环
How to disable 3rd party event loop
我使用 SetWinEventHook
来处理第 3 方操作,例如 EVENT_SYSTEM_MINIMIZESTART
事件。
如何防止此应用程序最小化?我的意思是我需要像 WinForms 这样的东西 e.Cancel = true;
如何工作:第 3 方应用程序正在最小化,我的应用程序捕获此操作,取消它,然后询问 Do you really want to minimize %appname%?
,如果用户单击 Yes
按钮,则使用 SendMessage 将其最小化。
这是 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();
}
唯一的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钩子。这允许您修改消息。用 WM_NULL
消息替换适当的传入消息与取消消息基本相同。这仅适用于发布到消息队列的消息。已发送的消息不会通过此挂钩进行过滤。
我使用 SetWinEventHook
来处理第 3 方操作,例如 EVENT_SYSTEM_MINIMIZESTART
事件。
如何防止此应用程序最小化?我的意思是我需要像 WinForms 这样的东西 e.Cancel = true;
如何工作:第 3 方应用程序正在最小化,我的应用程序捕获此操作,取消它,然后询问 Do you really want to minimize %appname%?
,如果用户单击 Yes
按钮,则使用 SendMessage 将其最小化。
这是 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();
}
唯一的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钩子。这允许您修改消息。用 WM_NULL
消息替换适当的传入消息与取消消息基本相同。这仅适用于发布到消息队列的消息。已发送的消息不会通过此挂钩进行过滤。