-
Notifications
You must be signed in to change notification settings - Fork 20
/
MainWindow.xaml.cs
42 lines (35 loc) · 1.12 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// ReSharper disable InconsistentNaming
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Interop;
using fs2ff.SimConnect;
namespace fs2ff
{
public partial class MainWindow
{
private const uint WM_USER_SIMCONNECT = 0x0402;
public MainWindow()
{
InitializeComponent();
}
private void Window_Closing(object sender, CancelEventArgs e)
{
((ISimConnectMessageHandler) DataContext).Dispose();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
HwndSource hwndSource = (HwndSource) PresentationSource.FromVisual(this)!;
hwndSource.AddHook(WndProc);
((ISimConnectMessageHandler) DataContext).WindowHandle = hwndSource.Handle;
}
private IntPtr WndProc(IntPtr hWnd, int iMsg, IntPtr hWParam, IntPtr hLParam, ref bool bHandled)
{
if (iMsg == WM_USER_SIMCONNECT)
{
((ISimConnectMessageHandler) DataContext).ReceiveFlightSimMessage();
}
return IntPtr.Zero;
}
}
}