我正在尝试与使用 anHWND
将消息传递回调用者的本机库进行通信,如下所示:
private void Example()
{
using (
var hwnd = new HwndSource(
new HwndSourceParameters("I sense a disturbance in the force...") {HwndSourceHook = WndProc}
)
)
{
//send hwnd.handle to native library
while (true) { }
}
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool ishandled)
{
ishandled = false;
Console.WriteLine("Intercepted message: 0x{0:X}", msg);
return IntPtr.Zero;
}
即使省略了对本机库的调用,我也只会收到以下消息(按顺序):
- 0x0001:
WM_CREATE
- 0x0018:
WM_SHOWWINDOW
- 0x0046:
WM_WINDOWPOSCHANGING
- 0x0046:
WM_WINDOWPOSCHANGING
- 0x001C:
WM_ACTIVATEAPP
- 0x0086:
WM_NCACTIVATE
- 0x007F:
WM_GETICON
- 0x007F:
WM_GETICON
- 0x007F:
WM_GETICON
- 0x0006:
WM_ACTIVATE
- 0x0281:
WM_IME_SETCONTEXT
- 0x0282:
WM_IME_NOTIFY
- 0x0007:
WM_SETFOCUS
- 0x0085:
WM_NCPAINT
- 0x0014:
WM_ERASEBKGND
- 0x0047:
WM_WINDOWPOSCHANGED
- 0x0083:
WM_NCCALCSIZE
- 0x0085:
WM_NCPAINT
- 0x0014:
WM_ERASEBKGND
- 0x0005:
WM_SIZE
- 0x0003:
WM_MOVE
- 0x000D:
WM_GETTEXT
在此之后,我可以拖动与HwndSource
周围相对应的窗口,但无法调整大小或关闭它。此外,操作系统声称此窗口没有响应。
为什么这个窗口停止响应,我怎样才能继续拦截消息?