.NET CF, Windows CE and Fullscreen

.NET CF, Windows CE and Fullscreen

Assuming you are creating an application for the .NET compact framework and further assuming that the application is designed to be the only one running on the target device because the whole device is defined by your application.

Also, you don’t want the end-users to tamper with the device.

This is why you sometimes want to put your application in a full-screen mode, hiding all other UI elements on the screen. Of course, to prevent tampering, you’d have to take additional measures, but that’s another topic.

The application I’m currently working on is written for the .NET compact framework, so the explanations are made for that environment.

Putting your application to full screen on the PocketPC is easy: Set your form’s FormBorderStyle to None and set WindowState to Maximized. That will do the trick.

On Windows CE (PocketPC is basically a special UI library and application collection running on top of Windows CE), there’s a bit more work to do.

First of all, you have to remove the task bar, which is acomplished by some P/Invoke calls which are declared like this:

[DllImport("coredll.dll", CharSet=CharSet.Auto)]
public static extern bool ShowWindow(int hwnd, int nCmdShow);

[DllImport("coredll.dll", CharSet = CharSet.Auto)]
public static extern bool EnableWindow(int hwnd, bool enabled);

Then, in your main form’s constructor, do the magic:

int h = FindWindow("HHTaskBar", "");
ShowWindow(h, 0);
EnableWindow(h, false);

And don’t forget to turn the task bar on again when your application exits.

int h = FindWindow("HHTaskBar", "");
ShowWindow(h, 5);
EnableWindow(h, true);

There’s one important additional thing to do though:

WindowState = Maximized won’t work!

Well. It will work, but it will resize your form in a way that there weill be empty space at the bottom of the screen where the taskbar was. You will have to manually resize the form by using something like this:

this.Height = Screen.PrimaryScreen.Bounds.Height;
this.Width = Screen.PrimaryScreen.Bounds.Width;

That last bit hit me hard today :-)

On a side note: There’s also the SHFullScreen-API call which also allows your application to position itself on the top of the taskbar. This basically is the official way to go, but the DLL aygshell.dll where the function is implemented in is not always available on all CE configurations.

%d bloggers like this: