Full Screen Control on a Pocket PC

Cags

Well-known member
Joined
Feb 19, 2004
Messages
690
Location
Melton Mowbray, England
Foreward
I recently ran into a very annoying problem whilst developing for the Pocket PC. How to create an application that was full screen? The simple answer to this is you create a Form with its WindowState property set to Maximised and set the Menu property to null. I wasnt happy with this however as although I didnt want the TaskBar and the SIP Icon, I still wanted to allow a menu.

Solution 1
Many places I looked suggested that the way to get around this was to use the SHFullScreen API. The way this works is by moving the items passed into dwState below the object with the windows handle passed into hwndRequester. Im not going to go into too much detail, but sufficed to say I could not get this method to work to a satisfactory standard. The problem is that many things can cause the Z Order to be changed back to its initial state which causes the SIP Icon to suddenly re-appear. One annoying thing that used to trigger this was selecting a top level MenuItem, then not selecting a child MenuItem, but instead clicking back on the form.
NB. SHFullScreen is generally in aygshell.dll however its in coredll.dll on the Pocket PC
Code:
Declare Function SHFullScreen Lib "aygshell" (ByVal hwndRequester As Long, ByVal dwState As Long) As Boolean
C#:
[DllImport("aygshell.dll")]
private extern static bool SHFullScreen(IntPtr hWnd, long dwState);
Solution 2
Still determined to come up with the effect I wanted I continued on experimenting/researching. Eventually I came across some articles which used a different method. Namely moving the items off screen so that the form can be resize in thier place. The solution I came up with uses the following three API Calls...
C#:
[DllImport("coredll.dll")]
public static extern int FindWindow(string LPClassName, string LPWindowName);

[DllImport("coredll.dll")]
public static extern int GetWindowRect(int hwnd, ref RECT rc);

[DllImport("coredll.dll")]
public static extern int MoveWindow(int hWnd, int X, int Y, int cx, int cy);
The basic theory is as follows. The constructor of the class gathers the required info for each item. This information is the Handle and its Location. This information is then stored for later use. A reference to the form is stored as its possible its handle will change.
C#:
public ScreenHelper(System.Windows.Forms.Form mainForm) 
{
	_parent = mainForm;
	hiddenItems = new ScreenItem();
	
	GetWindowRect(FindWindow(null, _parent.Text), ref rtFormDefault);

	hWndSipButton = FindWindow("MS_SIPBUTTON", null);
	GetWindowRect(hWndSipButton, ref rtSipButton);

	hWndTaskBar = FindWindow("HHTaskBar", null);
	GetWindowRect(hWndTaskBar, ref rtTaskBar);

	hWndSip = FindWindow("SipWndClass", null);
	GetWindowRect(hWndSip, ref rtSip);
}
There are two other public methods, they are ChangeItemVisibility and ResetScreen.

I wont cover the code too much here as its in the file, but essentially ChangeItemVisibility accepts a flagged enum, which allows you to alter whether an item is displayed on screen or not. The ResetScreen method is very important as it replaces all the items in their correct positions. It is very important that this message is called before the application is closed otherwise the user may have to reset their device in order to get the items back.

To use the class successfully in an application you will need to call ChangeItemVisibilty each time the application gets control and call ResetScreen when your application looses control. To-do this I override the OnActivated and OnDeactivated events. Its also worth noting that OnDeactivated is not called when you call Application.Exit(), so be sure to add an extra call to ResetScreen() before calling it.

Afterword
Well Im no Guru, but I thought that since this problem caused me a lot of headaches, Id share the solution I came up with. Attached is a sample project which contains my ScreenHelper class. Feel free to use it or any parts at your descretion, no guarantee implied etc, etc. Comments, suggestions, bug reports all welcome.

References
The following is a list of the main articles that helped me create my ScreenHelper class.
http://www.pocketpcdn.com/articles/fullscreen.html
http://support.microsoft.com/kb/q266244/
http://www.codeproject.com/netcf/netfullscreen.asp
 

Attachments

Last edited by a moderator:
Back
Top