Thoughts about setup and deployment issues, WiX, XNA, the .NET Framework and Visual Studio
All postings are provided AS IS with no warranties, and confer no rights. Additionally, views expressed herein are my own and not those of my employer, Microsoft.
Question:
I have written an executable that I want to be able to run as a Windows Media Center application and as a standalone program outside of Media Center. I am able to register the executable with Media Center using RegisterMceApp or RegisterApplication and it can be launched from within Media Center. When I launch my executable from within Media Center, I see that Media Center automatically minimizes to get out of the way of the program when launching it. However, when I close my program, Media Center does not restore, and the user has to navigate back to Media Center on their own (which is difficult with only a remote control and/or via a Media Center extender session).
How can I cause Media Center to restore to its previous full-screen state when a user exits my executable after it was launched within Media Center?
Answer:
To start with, you will need to register the EXE as a Windows Media Center application using the RegisterApplication API or the RegisterMceApp utility. When registering an EXE, you will need to create an entry point that specifies a Run attribute that points to the path of the EXE on the local file system.
If your EXE is designed to run both from within Media Center and as a standalone application, you will need some mechanism of differentiating how the user launched the EXE so that you can have the application navigate back to Media Center when the user exits only in the case when it was launched from within Media Center. One way to differentiate launch states is to have Windows Media Center pass a command line parameter when launching the application.
Windows Media Center does not support specifying any command line parameters in the Run attribute, so you will need to work around that limitation somehow. Possible options include the following:
In addition to registering the application, you will need to add logic in the application itself to handle navigating back to Media Center when the application exits. The following is an example algorithm that can be used to accomplish this:
Example of an EXE that is registered as a Windows Media Center application:
The Windows Vista games (such as Chess, FreeCell, etc) are examples of EXEs that are designed to launch as Media Center applications and as standalone applications. They use the 1st strategy listed above for their Media Center application registration.
As an example, you can open regedit on a Windows Vista Home Premium or Ultimate system and look at the Media Center entry point registration for one of the Windows games. For the chess game, the Run attribute is located in the following location in the registry and contains the following setting:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\Extensibility\Entry Points\{115EADF1-41C4-471b-8FE5-7A52B91BFE75}]Run=%ProgramFiles%\Microsoft Games\Chess\ChessMCE.lnk
Next, you can go to the %ProgramFiles%\Microsoft Games\Chess folder specified by the Run entry, right-click on the ChessMCE.lnk file and choose Properties. In the properties page for the .lnk file, you can see that a command line parameter is being passed to the game executable by looking at the value in the Target text box. For the Chess game, it looks like the following:
"%ProgramFiles%\Microsoft Games\chess\chess.exe" -mce
The Windows games use this -mce command line switch to determine whether or not they were launched within Media Center. When the games are launched with the -mce switch, they will display in full-screen UI mode, hide the standard Windows title bar and menu, and display text with larger fonts that are easier to read on a TV from 10 feet away. They also navigate the user back to Media Center when the user exits the application.
Interestingly, you can also launch the games with this -mce command line switch on your own outside of Media Center, and they will launch Media Center when you exit, even if it was not previously running on the system.