• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

menu simconnect

Messages
11
Country
canada
Hi,

I would to add a menu in FSX and for that I build a Dll.

I'll used this code and it compile fine (I added too the reference in the dll.xml).
But in FSX the menu doesn't show.

Any idee?

Code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>

#include "Simconnect/SimConnect.h"
EXTERN_C __declspec(dllexport) int DLLStart() 
{
   // called by SimConnect when dll is loaded
   return 0;  // return 0 for S_OK or load is cancelled
}

EXTERN_C __declspec(dllexport) int DLLStop()
{
  // called by SimConnect when dll is unloaded
  return 0;
}
int     quit = 0;
HANDLE  hSimConnect = NULL;

static enum GROUP_ID {
	GROUP_MENU
};

static enum EVENT_ID {
	EVENT_MENU_ONE,
	EVENT_MENU_TWO,
 };

static int menuUseCount = 0;

void CALLBACK MyDispatchProcMI(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
	HRESULT hr;

    switch(pData->dwID)
    {
        case SIMCONNECT_RECV_ID_EVENT:
        {
            SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;

            switch(evt->uEventID)
            {
                case EVENT_MENU_ONE:
					printf("\nMenu item one selected %d", evt->dwData);

					++menuUseCount;

					// Selected four times, so replace item one with item two
					if (menuUseCount == 4)
					{		
						hr = SimConnect_MenuDeleteItem(hSimConnect, EVENT_MENU_ONE);
						hr = SimConnect_RemoveClientEvent(hSimConnect, GROUP_MENU, EVENT_MENU_ONE);

						hr = SimConnect_MenuAddItem(hSimConnect, "Menu Item Two", EVENT_MENU_TWO, 54321);
						hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_MENU, EVENT_MENU_TWO);
					}
                    break;

				case EVENT_MENU_TWO:
					
					++menuUseCount;

					printf("\nMenu item two selected %d", evt->dwData);
					
					if (menuUseCount == 6)
						quit = 1;
					break;

                default:
					printf("\nReceived unknown event: %d",evt->uEventID); 
                    break;
            }
            break;
        }

        case SIMCONNECT_RECV_ID_QUIT:
        {
            quit = 1;
            break;
        }

        default:
			printf("Received ID: %d", pData->dwID);
            break;
    }
}

void testMenuItems()
{
    HRESULT hr;

    if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Menu Items", NULL, 0, 0, 0)))
    {
        printf("\nConnected to Flight Simulator!");   
        
		// Create some private events
		hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_MENU_ONE);
		hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_MENU_TWO);

		// Add one menu item
		hr = SimConnect_MenuAddItem(hSimConnect, "Menu Item One", EVENT_MENU_ONE, 12345);

		
		// Sign up for the notifications
		hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_MENU, EVENT_MENU_ONE);

		hr = SimConnect_SetNotificationGroupPriority(hSimConnect, GROUP_MENU, SIMCONNECT_GROUP_PRIORITY_HIGHEST);
 	
        while( 0 == quit )
        {
            SimConnect_CallDispatch(hSimConnect, MyDispatchProcMI, NULL);
            Sleep(1);
        } 

		// Clean up before exiting
		if (menuUseCount < 4)
			hr = SimConnect_MenuDeleteItem(hSimConnect, EVENT_MENU_ONE); else
			hr = SimConnect_MenuDeleteItem(hSimConnect, EVENT_MENU_TWO);

        hr = SimConnect_Close(hSimConnect);
    }
}

int __cdecl _tmain(int argc, _TCHAR* argv[])
{
    testMenuItems();

	return 0;
}
 
Zomg! C++?!?

Livai!

I made C# programs for ya! Go look at my code and give up this (what? now 20 year old programming language?!?).

I thought that you had downloaded the source and saw how thats done? I wrong? Easily Translated to C++...

Need more help? Lemme know?

Flaps
 
Last edited:
Back
Top