简体   繁体   中英

enter win32 desktop from metro app at its startup

I want to enter win32 desktop from a metro app when launch the metro app (press the app's tile on metro startup screen). One way is to open a file (eg a TXT file) when start the metro app. I add the following code logic into OnLaunched, sometimes it can open the file and enter desktop, but sometimes, it doesn't. Could someone help me? (just create a blank app in VS2012).

async protected override void OnLaunched(LaunchActivatedEventArgs args) {
// Do not repeat app initialization when already running, just ensure that the window     //is active
if (args.PreviousExecutionState == ApplicationExecutionState.Running)
{
    Window.Current.Activate();
    return;
}
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
    //TODO: Load state from previously suspended application
}

// Create a Frame to act navigation context and navigate to the first page
// var rootFrame = new Frame();
if (!rootFrame.Navigate(typeof(MainPage)))
{
    throw new Exception("Failed to create initial page");
}

// Place the frame in the current Window and ensure that it is active
Window.Current.Content = rootFrame;
Window.Current.Activate();
{
    string txtfile = @"Assets\a.txt";
    var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(txtfile);

    if (file != null)
    {
         bool success = await Windows.System.Launcher.LaunchFileAsync(file);
         if (success)
         {
         }
         else
         {
         }
    }
}

}

BatRT allows you to execute a batch file from a metro app. This could be used to run any desktop application from a metro app. As soon as the metro app starts execute a batch file to run your desired desktop application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM