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);
}

Applications for Working with Icons

Recently I needed to do some stuff with icons and I found two programs I really liked. Moreover they are absolutely free.

First one is IconsExtract is a program that helps to extract embedded icons from different types of files (EXE, DLL, OCX, CPL).

The other one is Greenfish Icon Editor Pro: a powerful icon, cursor, animation and icon library editor.

How To: Load Image from Embedded Resource

Here is a code for loading embedded image named MyImage.png stored directly in project directory:

Assembly assembly = Assembly.GetExecutingAssembly();
string iconFileName = string.Format("{0}.MyImage.png", assembly.GetName().Name);
using (Stream io = assembly.GetManifestResourceStream(iconFileName)) {
	return new Bitmap(io);
}

Name of resource to load contains three elements divided by dots:

  • Assembly name;
  • Path where resource is stored inside of a project (must be omitted if resource is in project directory);
  • File name of resource.

Path to resource should be created using names of folders. For example, if resource is in “Resources/Images” folder than path will be “Resources.Images”.

How To: Save XmlDocument without Declaration

Normally saving XmlDocument leads to xml declaration at the beginning of file. In case it is desirable to omit it, XmlWriterSettings comes to help:

XmlDocument doc = new XmlDocument();
// Do with document whatever is needed...

// Save xml document without xml declaration.
XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.OmitXmlDeclaration = true;
using (XmlWriter writer = XmlWriter.Create(@"\omit.xml", writerSettings)) {
	doc.Save(writer);
}

How To: Make File Writable on Windows Mobile

Making read-only file writable with full .Net Framework is a piece of cake: there is FileInfo.IsReadOnly. Just set it to false and it’s done.

With Compact Framework we need to use FileInfo.Attributes and a solid knowledge of bitwise operations:

FileInfo info = new FileInfo(pathToReadonlyFile);
info.Attributes &= ~FileAttributes.ReadOnly;

How To: Check That Application is Running Under Windows Mobile 6.5

As I wrote in Linkpool: Windows Mobile 6.1 and 6.2 Build Numbers they have the same version (which by the way is 5.2). So checking if application is running under WM 6.5 must be based on build number. Like this:

Version osVersion = Environment.OSVersion.Version;
if (osVersion.Major == 5 && osVersion.Minor == 2 && osVersion.Build >= 21139) {
    // It's Windows Mobile 6.5
}

Windows Mobile 6.1 and 6.2 Build Numbers

Both Windows Mobile 6.1 and 6.5 have the same version (5.2), but they differ in build numbers. Today I found some useful resources that describe their build numbers:

I’m Tweeting

Follow

Get every new post delivered to your Inbox.