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

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;
}

Just ran across this. Wondering if you ever wrote that tutorial. I’m trying to convert my old code to WPF. Have you registered for any data or set LVARs or HVARs?

Install the VS templates from the SDK

Then just clone this repository and compile it,

This is fun to use too.

And it got me started with WPF and Flight Sim… it has a very simple WPF form too… :relieved: and a well structured dynamic SimConect Poll. Once you have that Roslyn precompiled for your set… it is very fast and it can do any combination of variables.