Imports System.ComponentModel
' Add these two statements to all SimConnect clients
Imports Microsoft.FlightSimulator.SimConnect
Imports System.Runtime.InteropServices
PublicClass frmMain
PrivateConst WM_USER_SIMCONNECT AsInteger = &H402
Enum MENU_EVENTS
MAINMENU
SUBITEM_ONE
EndEnum
Enum MenuGroupID
GROUPMENU
EndEnum
Private fsx_simconnect As SimConnect
PublicSubNew()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
fsx_simconnect = Nothing
EndSub
PrivateSub frmMain_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
fsx_simconnect = New SimConnect("Application Name", Me.Handle, WM_USER_SIMCONNECT, Nothing, 0)
fsx_simconnect.MapClientEventToSimEvent(MENU_EVENTS.SUBITEM_SLEWMASTER, "")
fsx_simconnect.AddClientEventToNotificationGroup(MenuGroupID.GROUPMENU, MENU_EVENTS.MAINMENU, False)
fsx_simconnect.AddClientEventToNotificationGroup(MenuGroupID.GROUPMENU, MENU_EVENTS.SUBITEM_ONE, False)
fsx_simconnect.MenuAddItem("Application Name", MENU_EVENTS.MAINMENU, 1)
fsx_simconnect.MenuAddSubItem(MENU_EVENTS.MAINMENU, "Sub Item One", MENU_EVENTS.SUBITEM_ONE, 2)
fsx_simconnect.SetNotificationGroupPriority(MenuGroupID.GROUPMENU, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST)
AddHandler fsx_simconnect.OnRecvEvent, New SimConnect.RecvEventEventHandler(AddressOf fsx_simconnect_OnRecvEvent)
AddHandler fsx_simconnect.OnRecvQuit, New SimConnect.RecvQuitEventHandler(AddressOf fsx_simconnect_OnRecvQuit)
AddHandler fsx_simconnect.OnRecvException, New SimConnect.RecvExceptionEventHandler(AddressOf fsx_simconnect_OnRecvException)
EndSub
PrivateSub fsx_simconnect_OnRecvEvent(ByVal sender As SimConnect, ByVal data As Microsoft.FlightSimulator.SimConnect.SIMCONNECT_RECV_EVENT)
SelectCase data.uEventID
Case MENU_EVENTS.SUBITEM_ONE
' place code here to handle event
EndSelect
EndSub
PrivateSub fsx_simconnect_OnRecvQuit(ByVal sender As SimConnect, ByVal data As Microsoft.FlightSimulator.SimConnect.SIMCONNECT_RECV)
If fsx_simconnect IsNotNothingThen
fsx_simconnect.Dispose()
fsx_simconnect = Nothing
fsx_simconnect.MenuDeleteItem(MENU_EVENTS.MAINMENU)
fsx_simconnect.MenuDeleteSubItem(MENU_EVENTS.MAINMENU, MENU_EVENTS.SUBITEM_ONE)
Application.Exit()
EndIf
EndSub
ProtectedOverridesSub DefWndProc(ByRef m As Message)
If m.Msg = WM_USER_SIMCONNECT Then
If fsx_simconnect IsNotNothingThen
fsx_simconnect.ReceiveMessage()
EndIf
Else
MyBase.DefWndProc(m)
EndIf
EndSub
PrivateSub fsx_simconnect_OnRecvException(ByVal sender As SimConnect, ByVal data As Microsoft.FlightSimulator.SimConnect.SIMCONNECT_RECV_EXCEPTION)
EndSub
EndClass