Jump to content
The simFlight Network Forums
Aum364

MenuItems problem

Recommended Posts

Hi,

For days I've been trying to get some menus into FS, using the given example.
Works absolutely fine when I do it with the checkbox method, as given in the example, but I want to have the menus auto, when FSUIPC is connected.

Tried many different methods to achieve that but no success whatsoever.
Could any of you show me an example please, where the menus are created at startup and no checkbox is needed? (Using VB...)
Thanks in advance

Achoriham

Share this post


Link to post
Share on other sites

Hi Achoriham,

The following code works fine here on FSX:SE (FSUIPC4):
 

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                FSUIPCConnection.Open();
                AddMenus();
            }
            catch (FSUIPCException)
            {
                // no connection
            }
        }

        private void AddMenus()
        {
            UserInputServices ui = FSUIPCConnection.UserInputServices;
            ui.AddMenuItem("Menu1", "Menu One", false);
            ui.AddMenuItem("Menu2", "Menu Two", false);
            this.tmrMenuKeepAlive.Start();
        }

        private void tmrMenuKeepAlive_Tick(object sender, EventArgs e)
        {
            // This timer ticks every 10 seconds.
            FSUIPCConnection.UserInputServices.KeepMenuItemsAlive();
        }

Make sure you have the latest updates for FSUIPC and my DLL.

If you can't get this working, please post the relevant parts of your code so I can take a look.

Paul

Share this post


Link to post
Share on other sites

Hi Paul,

Many thanks, works like a charm! Grateful to you!

If you do not mind it, I'd have two other questions, which would be my next steps in the small prg I'm trying to do.
1. The menu works fine now, it is added to P3D, but how can I get the menu-item to display a simple message-box when the menu-item is pressed?

2. I'd like to read (or is "capture" the right word for that?) keystrokes in P3D and would like to write some Lvars according to the key-presses. I can write the Lvars but cannot read the key events.
How can I do that?

Thanks in advance
Achoriham

Share this post


Link to post
Share on other sites
Quote

how can I get the menu-item to display a simple message-box when the menu-item is pressed?

It depends where you want the message box to appear. If it's in your own application then you just use the normal MessageBox class, or make a form.

If you want it to appear inside FlightSim then you need to use the text display facilities provided by FSUIPC. This will just be text display though, there are no buttons and it doesn't look like a messagebox. It either appears as text along the top of the FlightSim window, or if the text is multi-line it appears in a window. This window can be moved by the user or even undocked.

I've expanded the example above to display a multiline message in FlightSim when Menu Item 1 is clicked:

        // Message Writing Offsets: (In their own group and marked as Write-Only)
        private Offset<string> msgText = new Offset<string>("msg", 0x3380, 128, true);
        private Offset<string> msgTitle = new Offset<string>("msg", 0x6D60, 32, true);
        private Offset<short> msgControl = new Offset<short>("msg", 0x32FA, true);

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                FSUIPCConnection.Open();
                AddMenus();
            }
            catch (FSUIPCException)
            {
                // no connection
            }
        }

        private void AddMenus()
        {
            UserInputServices ui = FSUIPCConnection.UserInputServices;
            ui.AddMenuItem("Menu1", "Menu One", false);
            ui.AddMenuItem("Menu2", "Menu Two", false);
            ui.MenuSelected += Ui_MenuSelected;
            this.tmrMenuKeepAlive.Start();
            this.tmrCheckForInput.Start();
        }

        private void Ui_MenuSelected(object sender, UserInputMenuEventArgs e)
        {
            switch (e.ID)
            {
                case "Menu1":
                    // show message in FS
                    msgText.Value = "This is a multiline message.\nThis is line 2\nThis is line 3";
                    msgTitle.Value = "Example Text Window";
                    msgControl.Value = 0;
                    FSUIPCConnection.Process("msg");
                    break;
                case "Menu2":
                    break;
            }
        }

        private void tmrMenuKeepAlive_Tick(object sender, EventArgs e)
        {
            // This timer ticks every 10 seconds
            FSUIPCConnection.UserInputServices.KeepMenuItemsAlive();
        }

        private void tmrCheckForInput_Tick(object sender, EventArgs e)
        {
            // This timer ticks every 250ms
            FSUIPCConnection.UserInputServices.CheckForInput();
        }

 

Quote

I can write the Lvars but cannot read the key events.
How can I do that?

Please see the examples application - "IS001- Key Presses" under Input Services. Key presses work in a similar way to Menu Items.

Paul 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.