Jump to content
The simFlight Network Forums

Recommended Posts

It sounds like the focus is taking longer than the dll expects.

I've increased the wait time from 150 to 300 ms and released 3.1.9-beta. Please upgrade via Nuget and let me know if it fixes the problem. (To get beta versions you need tick the box called 'include pre-release' in the nuget manager).

Paul

Share this post


Link to post
Share on other sites

Hello,

thanks for the fast answer.

I have used your Template for a short test to exclude the possibility my Programm did anything wrong.
So i compiled a poor FSUIPC Test with 2 Buttons. One of them is using a Sleep, so that i can click on the FS Window.
I uplad a little video and also the Video as a rar archive for the case it dosent load in the Explorer:

http://starflight-virtual.de/Videos/20190116_131735.mp4

http://starflight-virtual.de/Videos/20190116_131735.rar

In the video you see the FS Symbol in the Tskbar is only "blinking" after i press the Button without delay.

When i press the Button with delay and activate the FS window, then the GSX Manu comes up.

Thanks

Matthias

 

Ps: Button code

        private void button1_Click(object sender, EventArgs e)
        {
            FSUIPCConnection.SendKeyToFS(Keys.F12, SendModifierKeys.Control);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(2000);
            FSUIPCConnection.SendKeyToFS(Keys.F12, SendModifierKeys.Control);
        }

 

Share this post


Link to post
Share on other sites

It's not clear to me if you've tried the new version of the dll (3.1.9). Does it not work?

If not, then it's possible there's something different about P3D when switching focus. I don't have P3D so I can't test it here. It works fine on FSX.

Your video shows that P3D isn't getting focus properly. It should come the foreground above your application. I don't know why it's just flashing.

Here is the code to switch focus to the flight sim:

SendControlToFS(FSUIPCControl.Key_focus_restore, 0);

You can try this on its own and see if P3D gets proper focus or not.

If this also gives you a flashing icon without proper focus then we'll have to ask Pete about this.

Paul

Share this post


Link to post
Share on other sites

Yes for sure, i have it updated

image.png.bd6e88d239a754f0a4905e5b3c5a4e96.png

 

I have also tried the new code, but it is doing the same...P3D is just "blinking".

Before i get your great dll, i send this key via sendkeys and had also the problem with the focus. I have tried all the dll imports , 
SetForegroundWindow, ShowWindow, GetWindowPlacement and so on, but othing works.
FindWindow gives me all the time the MainWindowHandle, but anything else is not working with P3D, nothing will work.

But now, view minutes ago, i found a solution that works for me:

        public enum WindowState
        {
            Hide = 0, ShowNormal = 1, ShowMinimized = 2, ShowMaximized = 3, ShowNoActivate = 4, Show = 5,
            Minimize = 6, ShowMinNoActive = 7, ShowNA = 8, Restore = 9, ShowDefault = 10
        }

        [DllImport("user32.dll")]
        public static extern int ShowWindow(IntPtr hWnd, WindowState wFlags);

        [DllImport("user32.dll")]
        private static extern int SetForegroundWindow(IntPtr hWnd);

        private void button1_Click(object sender, EventArgs e)
        {
            FS_Focus();
            FSUIPCConnection.SendKeyToFS(Keys.F12, SendModifierKeys.Control);
        }

        void FS_Focus()
        {
            Process[] SameProcesses = Process.GetProcessesByName("Prepar3D");
            IntPtr windowHandle = SameProcesses[0].MainWindowHandle;

            if (windowHandle == IntPtr.Zero)
            {
                MessageBox.Show("Prepar3D is not running.");
            }
            ShowWindow(windowHandle, WindowState.ShowNormal);
            SetForegroundWindow(windowHandle);            
        }

Maybe you can improve your dll with that and it helps a bit .

Matthias

Share this post


Link to post
Share on other sites

I'm glad you got it working.

It seems like the focus feature in FSUIPC isn't working properly for P3D. I'll discuss it with Pete.

Thanks for the DLL import code.

Paul

Share this post


Link to post
Share on other sites

I am glad that also I can help you a little bit.

For me the Problem stays, because it is a bit more complicated.
The code works fine if you take the Mouse and press a Button on the App which gives the Focus to the P3D.
BUt for me, and my litte programm, it works a bit different. The Programm is a little "Talker" (lets say) between my Program and the FMC from Prosim737.
So, the talker runs always minimized. Now i can call a page in the FMC and press there a LSK, which then should open GSX. (like a Remote control for GSX,
because in my Homecockpit i dont want to use a Mouse)
Ok, after that this command to open GSX is transported via a HttpListener to my talker, which then should activate P3D and send STRG+F12.

Now, after my first test i wonder very very because the code, which works in the little test app ( where i click with the Mouse on the button to open the GSX menu (( little app has the Focus ))) did not work when i use the FMC...wonder wonder ... 🙂

After that i put a testbutton on my talker app, which did exactly the same like the FMC calls or the little test app...and voila, it works ... more wonder wonder ???

Now, it seams the app which should get the Focus by

            ShowWindow(windowHandle, WindowState.ShowNormal);
            SetForegroundWindow(windowHandle);

must have the Focus to give the Focus to another windows.

The Problem here ( for me ) is, that the Talker will never have the Focus.... so it is difficult.

Thinking about a solution, but that is a Poblem, which only exists in my spezial environment and i have to sort that out myself.
I just explained that for you and maybe it hels for further questions by other users.

Matthias

  • Like 1

Share this post


Link to post
Share on other sites

Hi Matthius,

Just to let you know... John Dowson has been investigating this and got the same problem as you. He's made a fix in FSUIPC5 so

FSUIPConnection.SendKeyToFS()

should work with his new version. The details are here if you're interested:

Paul

Share this post


Link to post
Share on other sites

Hello,

thanks for that info, but i must ask a (stupid) question if that dll is the one which runs in the sim or the one i must use in my Programm ?
Sorry for the stupid question 🙂

Matthias

Share this post


Link to post
Share on other sites

Hallöchen mal wieder,

anscheinend bist du ja richtig fit mit der FSUIPC.
Darf ich dich fragen, ob du irgendwie ein event einbaue könntest, welches man abonnieren kann um
den Status abzufragen?

Matthias

Share this post


Link to post
Share on other sites

Owww... I didn't know you had a new version of the dll Paul. I will check it as soon as I get home. Does it require new coding for old applications?

Share this post


Link to post
Share on other sites
Quote

Does it require new coding for old applications?

If you are upgrading from version 2, then there are a few breaking changes, but nothing major. Also the DLL is now delivered as a Nuget package.

There are instructions and a video on my website about upgrading from version 2.

http://fsuipc.paulhenty.com/#help

Let me know (new thread please) if you have any problems.

Paul

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

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.