You can do this in WPF using 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) {
Unfortunately, there is no real equivalence for the console application. Windows messages are, by definition, transmitted and received by a window descriptor (HWND), so they are really intended for use with graphics applications.
There are many other, less bizarre ways to do interprocess communication in Windows . I personally like to use pipes - setting up named pipes works very well in both native and managed code, and is very effective for exchanging data between two programs.
Reed copsey
source share