您可以使用WPF做HwndSource.AddHook此:
private HwndSource hwndSource;
void MyWindowClass_Loaded(object sender, RoutedEventArgs e)
{
hwndSource = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
hwndSource.AddHook(new HwndSourceHook(WndProc));
}
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// Process your windows proc message here
}
不幸的是,对于一个控制台应用程序没有真正equivelent。 Windows消息,根据定义,发送,并通过窗口句柄(HWND)接受,所以他们真的是为了与GUI应用程序中使用。
还有很多其他的,少奇,意味着做inter-process communication on Windows,但是。我个人比较喜欢使用管道 - 建立命名管道的作品相当不错,在本地和托管代码,并且是两个程序之间的通信效率非常高。