locked
How to open Winfrom app from Metro app

    Question

  • Hi all,

    My project required open Window From from Metro App. I can't not direct Window Form App, so I create BrokeredComponet and have function to open Window From App like this. It work but it not show destopApp.exe on the Top. I must go to click in task bar to open it. Show my question is have any way to open direct winfrom app from metro app ? And in my code, have any way to display WinFrom app on Top of screen ?

     public void OpenWinfrom(string fileName,string argument)
            {
                //string filepath=@"C:\Users\destopApp.exe";
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
                psi.FileName = fileName;
                psi.Arguments = argument;
                psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
                System.Diagnostics.Process.Start(psi);
            }

    Thanks so much.


    • Edited by Duc.M.Bui Thursday, April 30, 2015 8:04 PM
    Tuesday, April 28, 2015 9:12 PM

Answers

  • Windows Store apps are isolated and cannot directly run or interact with other apps, including WinForms apps. They can launch only files or protocols via the Launcher class. Your method of indirectly launching the WinForms app via a broker which performs the launch from the desktop context is as close as you'll get to launching a specific application. The problem is that since you're not launching it from the foreground process the launched app doesn't have permission to come to the foreground and so it launches behind the Windows Store app.

    I don't believe there is a proper way to let the Windows Store app allow the brokered app foreground privileges. Normally this privilege can be explicitly shared by calling AllowSetForegroundWindow or CoAllowSetForegroundWindow, but these are not available to Windows Store apps. Depending on the specific scenario (especially if this is not a general purpose application) you may be able to turn off the foreground lock timeout. See the SetForegroundWindow for more information on the conditions that must be met to bring a window into the foreground.

    Sheng Jiang's comment is mostly true but isn't relevant to the scenario you describe. Having UIAccess is both overkill and unhelpful.

    Wednesday, April 29, 2015 4:43 AM
    Moderator

All replies

  • you need to demand uiaccess privilege to be on top of store apps. and it is hard to get.


    Visual C++ MVP


    Wednesday, April 29, 2015 2:40 AM
  • Windows Store apps are isolated and cannot directly run or interact with other apps, including WinForms apps. They can launch only files or protocols via the Launcher class. Your method of indirectly launching the WinForms app via a broker which performs the launch from the desktop context is as close as you'll get to launching a specific application. The problem is that since you're not launching it from the foreground process the launched app doesn't have permission to come to the foreground and so it launches behind the Windows Store app.

    I don't believe there is a proper way to let the Windows Store app allow the brokered app foreground privileges. Normally this privilege can be explicitly shared by calling AllowSetForegroundWindow or CoAllowSetForegroundWindow, but these are not available to Windows Store apps. Depending on the specific scenario (especially if this is not a general purpose application) you may be able to turn off the foreground lock timeout. See the SetForegroundWindow for more information on the conditions that must be met to bring a window into the foreground.

    Sheng Jiang's comment is mostly true but isn't relevant to the scenario you describe. Having UIAccess is both overkill and unhelpful.

    Wednesday, April 29, 2015 4:43 AM
    Moderator