Microsoft Windows Vista
Media Center Development Guide
Table of Contents
Getting Started in Visual
Studio
Update the
Registration.xml with the public key token
Testing your application
for the first time
Change the default menu
category location for your application
Fix the default template
source code
Launching your
application in Debug Mode
This document if followed step by step should teach you how to build your first media center application. This is an unofficial guide, and is not intended to replace any content delivered by Microsoft.
After days and days of searching and trying to keep myself inspired, I finally found a site that shows how to develop a Media Center application from ground up. Yea, the guide that comes with the SDK is pretty good; however, I could never get past launching the application because the template that comes with the SDK is set up all wrong. It’s still a good template to use, but only with specific modifications.
· Visual Studio 2008 Full Edition (No Express Editions will work to the best of my knowledge, and secondly I don’t know if VS2005 will work or not)
· Microsoft Media Center Software Development Kit. Click Here to download
· Windows Installer Package. Click Here to download
· A Vista Media Center Development Environment
After installing the SDK, you will notice you now have a section for Windows Media Center templates.
Choose the first template labeled “WindowsMedia Center
Application”. Give it a name, for the
sake of this example; let’s call it TestCalc.
You have to choose a name that does
not have spaces within it.
Next, you will notice a web page that comes up telling you some of the next steps that you need to take should be. For now, ignore it because we are going to do everything a bit differently.
One of the first things we must do is get the token for the application we are about to build. To do so, take the following steps.
· In the properties of your project, go to Signing then if needed, click “Sign the assembly” to ensure it is checked
·
Click on the drop down under Choose a strong
name key file

· Click <New…>
·
Simply give it your first name, and a generic
password

· Build your application (Control + Shift + B). This will compile your application, and generate your DLL assembly file
· Copy your DLL assembly file to the GAC
o Go to Start type in Assembly, this should bring up a new explorer window
o
Point to the bin\debug directory in another explorer
window
(i.e. D:\Visual Studio 2008\Projects\Project1\Media Center Test Application
1\Media Center Test Application 1\bin\Debug)
o Drag the DLL assembly file from the Debug folder to assembly folder, this will install the assembly to the GAC
·
Locate the assembly in the GAC, then right click
and go to Properties

·
Next select the public key token, and copy it to
your clip board. This is your public key token used for the next step.

Going back to the solution file, select and open the Registration.xml file. Paste your public key token in place of the following text “insert_public_key_token_here”. This will be required for your application to run in Media Center.
Back in the Projects Properties window, go to the Build
Events, under Post-build event command
line paste the following text:
"C:\Program Files\Microsoft
SDKs\Windows\v6.0A\bin\gacutil.exe" /i "$(TargetPath)"
%windir%\eHome\McmlVerifier.exe
-verbose -assemblyredirect:"$(FullyQualifiedOutputPath)"
-directory:"$(ProjectDir)Markup"
cd
"$(ProjectDir)"
"$(ProjectDir)DevInstall.cmd"

Under the Start Action, and the Start External Program text box, enter the following relative to your system:
C:\Windows\ehome\ehshell.exe
This will
enforce the Media Center application to run instead of the default application.
Secondly
modify the Startup option. Here, modify
the Command Line Arguments with the following code:
/entrypoint:{GUID1}\{GUID2}
Example:
/entrypoint:{fb63ef76-617e-4f50-93c9-aa55829fc997}\{c9f7856f-93d5-473f-b3d2-9acacb63ddd8}
Modify the
GUID1 and GUID2 with the following from the Registration.xml file GUIDs:
·
GUID1:
ID of the application
·
GUID2:
Entry point of the application
Here is an
example of my Registration.xml file. In
the bold you will see the GUIDS that I used
<application title="TestCalc" id="{fb63ef76-617e-4f50-93c9-aa55829fc997}">
<entrypoint
id="{c9f7856f-93d5-473f-b3d2-9acacb63ddd8}"
addin="TestCalc.MyAddIn,
TestCalc,Culture=Neutral,Version=1.0.0.0,PublicKeyToken=9d716d5075ff0442"
title="TestCalc"
description="TestCalc Description"
ImageUrl=".\Application.png">
<category
category="More
Programs"/>
</entrypoint>
</application>
Here is a
screen shot of my properties page

Next, Save All of your open documents and properties, then Compile your application, but don’t run it yet.
Now, you can go to your solution, and hit F5 to run. This will compile and run the application. Next if you modified your registry correctly, you should see the following screen:

If you go back, you will be able to navigate to the app
programs section, and see your application there.
In the Registration.xml file, modify the XML file changing the category tag so it shows up “Services\Movies” this will move it from the default application to the movies location.
<application title="TestCalc" id="{fb63ef76-617e-4f50-93c9-aa55829fc997}">
<entrypoint
id="{c9f7856f-93d5-473f-b3d2-9acacb63ddd8}"
addin="TestCalc.MyAddIn,
TestCalc,Culture=Neutral,Version=1.0.0.0,PublicKeyToken=9d716d5075ff0442"
title="TestCalc"
description="TestCalc Description"
ImageUrl=".\Application.png">
<category
category="Services\Movies"/>
</entrypoint>
</application>

As a developer, I consider myself pretty ok, I can move around in code quite a bit, however it seems like the code that is in the template is a bit old school, and kind of scattered up a bit.
Launch.cs is ok, however Application.cs might need a bit of work.
Remove all the methods out of the Application.cs file except the GoToMenu() method. Paste the following code above it.
#region
"Required Peices to Application"
private static Application
singleApplicationInstance;
private AddInHost host;
private HistoryOrientedPageSession session;
/// <summary>
/// Default constructor
/// </summary>
public
Application()
: this(null, null)
{
}
/// <summary>
/// Constructor for Application
/// </summary>
/// <param
name="session"></param>
/// <param name="host"></param>
public
Application(HistoryOrientedPageSession
session,
AddInHost
host)
{
this.session
= session;
this.host =
host;
singleApplicationInstance = this;
}
/// <summary>
/// Sets up the environment host
/// </summary>
public MediaCenterEnvironment MediaCenterEnvironment
{
get
{
if (host == null) return null;
return
host.MediaCenterEnvironment;
}
}
#endregion
#region "Meta
Data"
// Sample Meta
Data
public string[] MyData
{
get
{
return new string[4] {
"Alpha",
"Bravo",
"Charlie",
"Delta"
};
}
}
#endregion
#region
"Helper Methods"
/// <summary>
/// Shows a Dialog
/// </summary>
/// <param name="text">Text to show in message</param>
/// <param name="title">Message Dialog Title</param>
/// <param name="timeout">Time out</param>
/// <param name="modal">If Modal</param>
public void DialogTest(string
text, string title,
int
timeout, bool modal)
{
MediaCenterEnvironment.Dialog(text, title,
DialogButtons.Ok,
timeout, modal);
}
#endregion
Now make
your GoToMenu() look like this, you might have to change the url if needed.
public void GoToMenu()
{
// Used to pass
in some of the applicatons
// properties such as the application its
self
Dictionary<string, object>
properties = new Dictionary<string, object>();
properties["Application"]
= this;
TransparentBackgroundMCML = true;
DialogTest("Testing
Application", "Debug Mode",
100, true);
// Launches the
first page
session.GoToPage("resx://TestCalc/TestCalc.Resources/Menu",
properties);
}
You can use Visual Studio Debugging to debug your MCE application.
Under Start, type in RegEdit, and make the following changes (I had to create a new dword):
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\MediaCenter\Settings\Extensibility]
"EnableAddInLaunchDebugging"
= dword:00000001
Setting this value to 1 will allow Media Center to run a process that can be attached allowing for debugging.

Debugging is easy, just requires a bit more work than before. Here you will have to attach a process, if you haven’t done this before, I will show you now.
Let’s start by inserting a break point into your code. Let’s put it in the Application.cs code file, then put it where the dictionary code is.

Press the F5 key to compile and run your application. When Media Center opens, it will start out with this screen, showing this dialog.

This is your process number to attach your debugger to. So tab over to Visual Studio and go to Debug, Attach to Process…

Choose the process to attach to, and press the Attach button.

Note, you may get this message:
This means you have to copy the latest assembly to the GAC again. Follow the steps in the Get the Key Token section. Once you do this, re-run this step, this will enable debugging.
Walla! You should be able to see your first (and only) break point

1. Apply the default background (working on now)
2. Add Media Center style buttons
3. Hooking up event handlers and testing with buttons
4. Allowing users to enter text