WPF Continuous Sim Event Receiving without polling

I found this lovely example from year 2009. It works perfectly with SimConnect! I hope you enjoy it! I am writing a tutorial of how to make a SimConnect C# WPF app. Stay tuned :cowboy_hat_face:
-Pauli Käppi

https://web.archive.org/web/20091019124817/http://www.steverands.com/2009/03/19/custom-wndproc-wpf-apps/

1 Like

using System.Windows.Interop;

MainWindow.xaml.cs

protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
Console.WriteLine(“OnSourceInitialized”);
}

private IntPtr WndProc(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, ref bool isHandled)
{
isHandled = false;
if (message == USER_EVENT_WIN32)
{
if (simConnect != null)
{
simConnect.ReceiveMessage();
isHandled = true;
}
}
return IntPtr.Zero;
}