How To: Place WP7 App to Games Hub

When you create new application project for Windows Phone 7 after installation it will appear in applications list. But what if you’re creating a game and you’d like to have it in Games Hub instead?

Last weekend I downloaded simple time killing game for my nephew. Surprisingly it didn’t appear in Games Hub and this drive me to write this post ;)

Each WP7 app belongs to one of genres: normal apps or games. Normal apps appear in applications list while games appear in Games Hub. And it has nothing to do with framework you use (Silverlight or XNA). Genre is specified in WMAppManifest.xml:

WMAppManifest.xml Location

By default app has “apps.normal” genre:

Simply change it to “apps.games” and you’re done:

P.S.

Remember that on emulator app with genre “apps.games” will not be available for manual start as Games Hub is not available there.

Also if you mistype in genre name your application will be treated as apps.normal.

How To: Read String Line by Line

Breaking a string containing multi-line text to a list of lines can be easily done using StringReader. Here is a method that does this and small test program:


class Program
{
    static void Main(string[] args)
    {
        IList<string> lines = BreakLines("This is a test for breaking multiline string \nto a list of lines.");

        foreach (var item in lines)
        {
            Console.WriteLine(item);
        }

        Console.ReadLine();
    }

    private static IList<string> BreakLines(string text)
    {
        IList<string> lines = new List<string>();

        using (StringReader reader = new StringReader(text))
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                lines.Add(line);
            }
        }

        return lines;
    }
}

 

How To: Fix TortoiseCVS Icon Overlay in Windows 7

After installing TortoiseCVS on Windows 7 icons of folders and files that are under CVS control didn’t change. Which clearly dispappointed me. Some Web browsing and several tries lead me to the proper solution.

To fix the issue you need to rename subkeys  under “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\ShellIconOverlayIdentifiers” starting with “Groove” to something that will move them to the bottom of subkeys list (i.e. VGroove).

TortoiseCVS Fix On Windows7

How To: Perform column-based selection in Visual Studio

Sometimes is is needed to copy some information from source code in a column-based style (parts of several lines starting from some position inside the line). It turned out that there is very easy way to achieve that. Just need to use Shift + Alt during selecting area with the mouse.

Column-based selection in Visual Studio

How To: Convert String to InputStream

Here is a method that does convertion:

public InputStream stringToInputStream(String text) throws UnsupportedEncodingException {
	return new ByteArrayInputStream(text.getBytes("UTF-8"));
}

How To: Get Correct Messages for Exceptions Fired from .Net Compact Framework Classes

Sometimes message from exception that occurred inside .Net CF classes doesn’t look handly at all:

An error message cannot be displayed because an optional resource assembly containing it cannot be found.

The thing is that error messages are actually in the resource assembly which is not installed on the device. So to fix the problem you just need to install this assembly:

  1. Navigate to CompactFramework folder in the SDK which is “%Program Files%\Microsoft.NET\SDK\CompactFramework”.
  2. Navigate to Diagnostics folder under desired .Net CF version (“v3.5\WindowsCE\Diagnostics” for 3.5 or “v2.0\WindowsCE\Diagnostics” for 2.0).
  3. Copy resource CAB file to device according to the language you want and install it.

How To: Unit Test a Singleton

Unit testing a Singleton is not a trivial task because each test needs untouched Singleton object to keep all the tests isolated. One way to achieve this is to recreate underlying singleton object using reflection during test setup or teardown as described by Jonathan de Halleux and Omer van Kloeten.

But I think that a better way is to extract implementation from singleton into a separated class. This way we’ll have a class that contains all the logic to be tested and another class used to wrap it into a singleton.

public class LoadBalancer {
	internal LoadBalancer() {
	}

	// LoadBalancer class implementation goes here...
}

public sealed class LoadBalancerSingleton {
	private static readonly LoadBalancer _instance = new LoadBalancer();

	private LoadBalancerSingleton() {
	}

	public static LoadBalancer Instance {
		get {
			return _instance;
		}
	}
}

Using InternalsVisibleTo attribute in this assembly we can allow test project to perform needed unit testing. Although technically it is possible to create another instance of the LoadBalancer class inside this assembly comments on constructor and common sense should prevent such a situation.

So to my mind it’s a good alternative to reflection approach.

How To: Rotate Screen on Windows Mobile Device

Below is a snapshot that shows how to change screen orientation from normal to 90 degree rotated or from 90 degree back to normal depending on current screen state:

if (SystemSettings.ScreenOrientation == ScreenOrientation.Angle0) {
	SystemSettings.ScreenOrientation = ScreenOrientation.Angle90;
}
else {
	SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;
}

To make this code compile don’t forget to import Microsoft.WindowsCE.Forms namespace.

How To: Refresh Home Screen on Windows Mobile 6.5

New home screen available in Windows Mobile 6.5 should be refreshed differently for Professional and Standard editions of OS. It can be done using the same API methods as for earlier versions of Windows Mobile.

For Professional edition it can be done like this:

[DllImport("coredll.dll")]
private static extern IntPtr PostMessage(int hWnd, int msg, uint wParam, uint lParam);

private const int HWND_BROADCAST = 0xFFFF;
private const int WM_WININICHANGE = 0x001A;

public static void Refresh() {
	PostMessage(HWND_BROADCAST, WM_WININICHANGE, 0xF2, 0);
}

For Standard edition the trick is to provide correct GUID to API. This GUID can be found in SlidingPanel.home.xml file located in “\Application Data\Home” folder. Here is the code:

[DllImport("aygshell.dll")]
public extern static uint SHOnPluginDataChange(ref Guid clsid);

public static void Refresh() {
	Guid guid = new Guid("{E9267CAB-02EE-4f37-8216-6BF6A8FF5A71}");
	SHOnPluginDataChange(ref guid);
}

I’m Tweeting

Follow

Get every new post delivered to your Inbox.