【发布时间】:2013-12-05 01:05:23
【问题描述】:
我有一段代码,例如:
IntPtr hWnd = new WindowInteropHelper(this).Handle;
HwndSource source = HwndSource.FromHwnd(hWnd);
source.AddHook(new HwndSourceHook(WndProc));
NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_CALL, IntPtr.Zero, IntPtr.Zero);
这最初是在 WPF 应用程序中。但是,我需要在 WinForms 应用程序中复制该功能。另外,NativeMethods.PostMessage 只是映射到 user32.dll PostMessage:
[DllImport("user32")]
public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
我可以在我的 WinForms 应用程序中使用一对一的 WindowInteropHelper/HwndSource/HwndSourceHook 吗?
【问题讨论】:
-
只需覆盖 WndProc() 方法。
标签: c# .net winforms native user32