|
 
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
| You must Sign In to use this message board. |
|
| | Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh) | FirstPrevNext |
|
 |
|
|
 |
|
|
First Simple Option: PictureBox Control with Dock State Fill in Form
Second Option: Override OnPaint method of Form:
protected override void OnPaint(PaintEventArgs e) {
Bitmap backgroundImage = Properties.Resources.MyBitMap;
e.Graphics.DrawImage(backgroundImage, this.ClientRectangle, new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height), GraphicsUnit.Pixel); }
Oleg Levin .NET Development Manager
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi i follow your code,and implement the code i do a little bit change in the code part only public static void StartFullScreen(Form form) { //Set Full Screen For Windows CE Device
//Normalize windows state form.WindowState = FormWindowState.Normal;
IntPtr iptr = form.Handle; SHFullScreen(iptr, (int)FullScreenFlags.HideStartIcon); SHFullScreen(iptr, (int)FullScreenFlags.HideSipButton); //detect taskbar height int taskbarHeight = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height;
// move the viewing window north taskbar height to get rid of the command //bar MoveWindow(iptr, 0, -taskbarHeight, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height + taskbarHeight, 1);
// move the task bar south taskbar height so that its not visible anylonger IntPtr iptrTB = FindWindowW("HHTaskBar", null); MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height, Screen.PrimaryScreen.Bounds.Width, taskbarHeight, 1);
}
/// /// Stop Full Screen Mode /// /// public static void StopFullScreen(Form form) { IntPtr iptr = form.Handle;
SHFullScreen(iptr, (int)FullScreenFlags.ShowStartIcon);
//detect taskbar height int taskbarHeight = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height;
MoveWindow(iptr, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height - taskbarHeight, 1);
IntPtr iptrTB = FindWindowW("HHTaskBar", null); MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height - taskbarHeight, Screen.PrimaryScreen.Bounds.Width, taskbarHeight, 1);
} i want to make the application for pocket pc only,due to i do little bit change,i only want to hide the sip key icon and start icon in the form load in C# ,when we move to the next form the keyboard again show.Please help me regarding this problem. give me suggestion .
Ram Krishna Pattnayak Software Developer(SDS) Sun-Dew Solutions Pvt.Ltd www.sundewsolutions.com kolkata
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
it not work .i wan to hide the sip keyboard icon ,please refer any code c# then also that will be ok for me.
Ram Krishna Pattnayak Software Developer(SDS) Sun-Dew Solutions Pvt.Ltd www.sundewsolutions.com kolkata
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi This may be helpful:
Sip class wrapper:
using System; using System.Runtime.InteropServices;
namespace Put.Your.Namespace.Here { /// <summary> /// show the Standard SIP without the menu /// with the "SetPosition" method you can set where to display the SIP /// </summary> public class Sip { class WinApi { [DllImport("coredll.dll")] public static extern int SipShowIM(SIPStatus i); [DllImport("coredll.dll")] public static extern bool SipSetInfo(ref SIPINFO pSipInfo); [DllImport("coredll.dll")] public static extern bool SipGetInfo(ref SIPINFO pSipInfo); } private static bool pvtVisible = false; private enum SIPStatus { SIPF_OFF = 0, SIPF_ON } private struct SIPINFO { public Int32 cbSize; public Int32 fdwFlags; public RECT rcVisibleDesktop; public RECT rcSipRect; public Int32 dwImDataSize; public Int32 pvImData; }
private struct RECT { public Int32 left; public Int32 top; public Int32 right; public Int32 bottom; }
private void Show () { WinApi.SipShowIM(SIPStatus.SIPF_ON); }
private void Hide () { WinApi.SipShowIM(SIPStatus.SIPF_OFF); }
public void SetPosition (Int32 top) { SIPINFO mySi = new SIPINFO(); bool result = true; mySi.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(SIPINFO)); result = WinApi.SipGetInfo(ref mySi); mySi.rcSipRect.top = top; mySi.rcSipRect.bottom = top + 80; result = WinApi.SipSetInfo(ref mySi); }
/// <summary> /// Property setting shows or hides the SIP /// </summary> public static bool Visible { get { return pvtVisible; } set { if (value == true) { WinApi.SipShowIM(SIPStatus.SIPF_ON); } else { WinApi.SipShowIM(SIPStatus.SIPF_OFF); } pvtVisible = value; } } } }
Oleg Levin .NET Development Manager
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, Great article, thank you. One question.
What if application will exited abnormally? I.e. it set FS mode and crashed. In this case only system reset can help to restore system windows?
Regards, Oleg.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Setting the WindowStaus property to the form to maximized is enough without a need of P/Invoke Regards
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hi Thanks for sharing - I found I had to do a tweak to get it to work on Smartphone Mobile 5. The existing code left the taskbar visible at the top of the screen. To make the screen go fullscreen I changed:
IntPtr iptrTB = FindWindowW("HHTaskBar", null);
to
IntPtr iptrTB = FindWindowW("Tray", null); and then it works great
and also removed the buttons since they're not supported controls on Smartphone
Thanks Tim
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Good article...
I have one ( maybe stupid) question on your source code, that why you use partial class for [PInvoke] and [PlatformDetection]? What's the purpose or advantage?
Thanks!
DG
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Hi. It is not important in this demo code. i have some other extensions for my internal using and this is a reason for some partials classes in this sample code. Thank you.
Oleg Levin .NET Developer/Group Leader
|
| Sign In·View Thread·PermaLink | 3.00/5 (1 vote) |
|
|
|
 |
|
|
This may be a much easier way...
I don't know if this works on a Smartphone, but it definitely works on Windows Mobile 5.
Simply set the form's WindowState property to be FormWindowState.Maximized.
Works a treat!
Ronny
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I found that the topic is very interesting, but after reading your article I do not have a clue how you did it. Did you use some kind of P/Invoke, or have you written a kind of wrapper-class for your functions? Probably they are from a third party vendor, if so, where did you get it? Is there more information available on this? How did you get to your solution? Are there any requirements to be able to implement your solution? Don't get me wrong, i think your article is worth being on Codeproject - but til now there is not really more than pure downloadable source code.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
I will update some information in this article. This is article for advanced developers. And i don't understand your problem. You have source code and if you are not beginner in this area you can understand all. Please explain me if you can. Thank you.
-- modified at 3:39 Wednesday 13th June, 2007
-- modified at 4:19 Wednesday 13th June, 2007
Oleg Levin .NET Developer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Oleg, thanks in advance for the coming update.
To answer your questions: I do not have a problem; I only think that additional information will make your article more useful and understandable - even for advanced users 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Always supposing you've got a 240x320 resolution display...
I understand it's pretty much the same for other different resolutions or the 24 pixels you play with, vary on other resolutions?
I personally use a little class to hide "TaskBar":
using System; using System.Runtime.InteropServices;
namespace PPC.Utilities { public sealed class TaskBar { private const int SW_HIDE = 0x0000; private const int SW_SHOW = 0x0001;
private const string TASKBAR_PARAMETER = "HHTaskBar";
/// /// Hides the taskbar so that the user cannot tap into "Start" and exit the application /// public static void Hide() { int h = FindWindow(TASKBAR_PARAMETER, ""); ShowWindow(h, SW_HIDE); }
/// /// Shows the taskbar so that the user can tap into "Start" /// public static void Show() { int h = FindWindow(TASKBAR_PARAMETER, ""); ShowWindow(h, SW_SHOW); }
[DllImport("coredll.dll")] private static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("coredll.dll")] private static extern int ShowWindow(int hwnd, int nTaskShow);
[DllImport("coredll.dll")] private static extern int MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); } }
And appart from calling "Hide" method inside this class, in order to all forms appear maximized, there are some properties that must be set for each form of the application:
/// /// Sets the target form to kiosk mode /// /// public static void SetFormToKioskMode(Form target) { target.Text = ""; target.MaximizeBox = false; target.MinimizeBox = false; target.ControlBox = false; target.FormBorderStyle = FormBorderStyle.None; target.WindowState = FormWindowState.Maximized; }
Nice trick! I'l try it out in my next project!
Regards.
MIGUEL "Rezad a vuestros Dioses, amad a vuestras mujeres y luchad por vuestra patria!"
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
this sample was based on 240x320 resolution display.
Please try this if you want to know height of taskbar.
taskbarHeight = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height
Soon I will update my article.
Thank you for reply.
Oleg Levin
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|