locked
Programmatically Return to Start

    Question

  • Is there a way that I can, from within a running Metro application, programmatically return to the Metro "Start" page (i.e., the one that has all the Tiles on it?)

    For instance, suppose I have a button in my Metro app, and in the responder to the button click, I want to "deactivate" the app and have the device bring up the "Start" page with all the Tiles on it.

    Is this possible to do? 

    Tuesday, September 18, 2012 11:55 PM

Answers

All replies

  • No, you can't do that programmatically. The user can do this at any time though.

    What is the scenario that you want this for?

    --Rob

    Tuesday, September 18, 2012 11:58 PM
    Owner
  • Just as an example, I have a standard "*.exe" program that I've wrapped into a Metro app.

    I've pinned a Tile for this "app" on the Start page. 

    I tap on the Tile on the Start page, and the app (i.e., the *.exe program) starts running like normal.

    When the program terminates, it dumps me out into the "Desktop" portion of the system.

    Is there a way I can get the program to dump me out into the Start page instead, i.e., the page w/ all the Tiles on it? 

    • Proposed as answer by u2519 Friday, September 28, 2012 3:45 PM
    Wednesday, September 19, 2012 5:28 PM
  • how you wrapped a standaard exe in a metro app?
    • Proposed as answer by u2519 Friday, September 28, 2012 3:45 PM
    Wednesday, September 19, 2012 6:50 PM
  • I created a basic console app like so, and once I had compiled the *.exe, I pinned it to the Start Page:

    #include "stdafx.h"
    #include "windows.h"
    #include "shellapi.h"
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	SHELLEXECUTEINFO shExecInfo;
    
          shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    
          shExecInfo.fMask = NULL;
          shExecInfo.hwnd = NULL;
          shExecInfo.lpVerb = L"runas";
          shExecInfo.lpFile = L"MyApplication";
          shExecInfo.lpParameters = L"-x MyParameters";
          shExecInfo.lpDirectory = NULL;
          shExecInfo.nShow = SW_NORMAL;
          shExecInfo.hInstApp = NULL;
    
    	   ShellExecuteEx(&shExecInfo);
    
    	return 0;
    }
    
    • Proposed as answer by ibarheeym Wednesday, September 19, 2012 8:07 PM
    • Unproposed as answer by ibarheeym Wednesday, September 19, 2012 8:07 PM
    • Proposed as answer by ibarheeym Wednesday, September 19, 2012 8:07 PM
    • Unproposed as answer by Rob Caplan [MSFT]Microsoft employee, Owner Wednesday, September 19, 2012 8:13 PM
    • Proposed as answer by u2519 Friday, September 28, 2012 3:46 PM
    Wednesday, September 19, 2012 6:59 PM
  • program a windows key press at the end of the application?
    Wednesday, September 19, 2012 7:04 PM
  • I already thought of this and tried it, but... it didn't seem to work. 

    Perhaps I wasn't doing it correctly, though. I'll post my code. 

    Wednesday, September 19, 2012 7:30 PM
  • OK, so to test sending a "windows button" event to the Metro app, I coded up a really simple "demo" app (independent to the *.exe wraper I described above). I did it in the JavaScript/HTML5 mode of developing Metro apps.

    In the default.html file, I filled out the body as follows:

    <p>
     <button id="button1">Send Event!</button>
    <p>
    

    In my default.js file, in the app.onactivated function, I added the following line:

    document.getElementById("button1").addEventListener("click",button1Click,false);
    

    and finally I added the button1Click function in the default.js file:

    function button1Click() {
      var code = 91;
      var evt = document.createEvent("KeyboardEvent");
      evt.initKeyboardEvent("keypress",true,true,window,0,0,0,0,0,code);
      var canceled = !document.dispatchEvent(evt);
      if ( canceled ) { 
        console.log("CANCELED: " + code);
      } else { 
        console.log("GOOD: " + code);
      }
    }

    When I run the app, and tap the button, the console logs a "GOOD: 91" message. But it doesn't "cancel" the app or return to the Start screen.

    Do I have the keycode 91 wrong?

    • Proposed as answer by u2519 Friday, September 28, 2012 3:46 PM
    Wednesday, September 19, 2012 9:19 PM
  • well from a metro app you cant do this.

    from a desktop app you got more chance.

    Wednesday, September 19, 2012 10:21 PM
  • Creating a Windows Store app as a wrapper for a desktop app is not a supported scenario and there is no good way to achieve it.

    There is no direct way for a Windows Store app to communicate with or launch a specific desktop app. You can partially hack around this by launching a file or protocol, but there are unsolvable edge cases. Such an app will not pass certification.

    Your Windows Store app cannot interact with the system outside of deliberate patterns such as Contracts. It cannot synthesize a input to send to the system or other apps: your console receives the key because it is in the same system.

    I think Dave's suggestion was to synthesize a keystroke from desktop app. How that will work will be context dependent.

    Activating a Windows Store app from a desktop app is possible, but off topic for this forum (see IApplicationActivationManager interface (Windows)‎ . The Automating the testing of Windows 8 apps block entry includes a sample).

    There is no good way to programmatically bring up the Start Screen.

    --Rob

    Wednesday, September 19, 2012 10:28 PM
    Owner
  • Hi Rob, 

    Thanks for your feedback. It's more for an in-house Windows 8 demo, and not so much for "certification" or public deployment on the Windows app store, but in general I'm finding what you're describing -- namely, that there seems to be no good way to programmatically bring up the Start screen.

    I've tried writing a native Win32 app and sending it Key Events (and specifically, Windows key events), but this too doesn't seem to to anything. The code I'm using here is as follows:

    void GenerateKey(int vk, BOOL bExtended) 
    {
    KEYBDINPUT kb = {0};
    INPUT Input = {0};

    // Generate Down
    if ( bExtended ) {
    kb.dwFlags = KEYEVENTF_EXTENDEDKEY;
    }
    kb.wVk = vk;
    Input.type = INPUT_KEYBOARD;

    Input.ki = kb;
    ::SendInput(1,&Input,sizeof(Input));

    // Generate Up
    ::ZeroMemory(&kb,sizeof(KEYBDINPUT));
    ::ZeroMemory(&Input,sizeof(INPUT));
    kb.dwFlags = KEYEVENTF_EXTENDEDKEY;
    if ( bExtended ) {
    kb.dwFlags |= KEYEVENTF_EXTENDEDKEY;
    }
    kb.wVk = vk;
    Input.type = INPUT_KEYBOARD;
    Input.ki = kb;
    ::SendInput(1,&Input,sizeof(Input));
    }

    and I'm invoking the code by calling:

    GenerateKey(VK_LWIN,FALSE);

    but again, it doesn't seem to do anything. Executing this code in the Win32 app doesn't seem to bring up the Start screen.

    Thanks for your help!

    Thursday, September 20, 2012 6:54 PM
  • Hi Sholtz9421,

    I suggest having a look at the Desktop Automation Sample first. If you have any further problems on this, try posting at http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/threads for better support.

    Have a nice day!


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, September 26, 2012 2:00 AM
    Moderator