Introduction
Many developers must include a "full screen" feature into their applications. In this article, I am focusing on Pocket PC and Windows CE devices. I've tried to introduce a universal solution for PDA software developers using the .NET Compact Framework that will enable them to include a full screen mode on both platforms, without requiring recompilation or code changes.
Background
Why do we need a full screen mode on our PDAs? My three main reasons are:
- To disable user interaction and access other programs on the device
- To make full use of the screen space
- To customize forms
Using the code
There are three steps to my full screen solution.
- Detecting the platform type by invoking Windows API and changing the form behavior accordingly:
Platform type detection is a simple call to SystemParametersInfo
to find whether you are running on a Smartphone or a Pocket PC. You need a few constants defined and the P/Invoke
marshaling code to make it work from managed code. I am using SystemParametersInfo4Strings P/Invoke
to detect if the device is a Pocket PC or not.
public enum SystemParametersInfoActions : uint
{
SPI_GETPLATFORMTYPE = 257,
}
#endregion
public static string GetPlatformType()
{
StringBuilder platformType = new StringBuilder(50);
if (SystemParametersInfo4Strings(
(uint)SystemParametersInfoActions.SPI_GETPLATFORMTYPE,
(uint)platformType.Capacity, platformType, 0) == 0)
throw new Exception("Error getting platform type.");
return platformType.ToString();
}
Platform detection method:
internal partial class PlatformDetection
{
public static bool IsSmartphone()
{
return PInvoke.GetPlatformType() == "SmartPhone";
}
public static bool IsPocketPC()
{
return PInvoke.GetPlatformType() == "PocketPC";
}
}
P/Invoke
descriptions:
[DllImport("Coredll.dll", EntryPoint = "SystemParametersInfoW",
CharSet = CharSet.Unicode)]
tatic extern int SystemParametersInfo4Strings(uint uiAction,
uint uiParam, StringBuilder pvParam, uint fWinIni);
[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();
[DllImport("coredll.dll")]
private static extern IntPtr SetCapture(IntPtr hWnd);
[DllImport("aygshell.dll", SetLastError = true)]
private static extern bool SHFullScreen(IntPtr hwnd, int state);
[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr FindWindowW(string lpClass, string
lpWindow);
[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr MoveWindow(IntPtr hwnd, int x,
int y, int w, int l, int repaint);
This code is of the "set full screen" method:
if (!Platform.PlatformDetection.IsPocketPC())
{
form.WindowState = FormWindowState.Normal;
IntPtr iptr = form.Handle;
SHFullScreen(iptr, (int)FullScreenFlags.HideStartIcon);
int taskbarHeight =
Screen.PrimaryScreen.Bounds.Height -
Screen.PrimaryScreen.WorkingArea.Height;
MoveWindow(iptr, 0, -taskbarHeight,
Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height + taskbarHeight, 1);
IntPtr iptrTB = FindWindowW("HHTaskBar", null);
MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height,
Screen.PrimaryScreen.Bounds.Width, taskbarHeight, 1);
}
else {
form.Menu = null;
form.ControlBox = false;
form.FormBorderStyle = FormBorderStyle.None;
form.WindowState = FormWindowState.Maximized;
form.Text = string.Empty;
}
- Calling the form load event's "make full screen" method:
private void MainForm_Load(object sender, EventArgs e)
{
FullScreen.StartFullScreen(this);
}
- Calling the form closing event's "remove full screen" method:
private void MainForm_Closing(object sender, CancelEventArgs e)
{
FullScreen.StopFullScreen(this);
}
What is next?
In addition, you can customize forms as well as set your own title with battery life and your own close button. Let's do it!
History
- 7 June, 2007 -- Original article posted
- 13 June, 2007 -- Updated
- 14 June, 2007 -- Updated some more