The first task I had to do when I started developing my first Windows CE application was to make my main program window appear in full screen mode. After some research I came across a small article posted on Code Project. It describes a method of showing a window in full screen mode using standard window management calls which is what I was looking for. I completed the source with proper definitions of system calls and structures. I provide this source code along with a basic test application.
The usual method of doing this would have been to use SHFullScreen, but I was not able to use this function as my OS Design was not to contain aygshell.dll, the library from which this function was part of.
I am developing under .NET Compact Framework 2.0.
First, I had to define some useful enums containing constants of the Windows API. Here are some of them, for the rest please see the attached project as this post would grow unreasonably if I pasted them here.
[Flags( )]
internal enum FullScreenFlags : int
{
SwHide = 0,
ShowTaskbar = 0×1,
HideTaskbar = 0×2,
ShowSipButton = 0×4,
HideSipButton = 0×8,
SwRestore = 9,
ShowStartIcon = 0×10,
HideStartIcon = 0×20
}
internal enum Hwnd : int
{
HWND_TOP = 0,
HWND_BOTTOM = 1,
HWND_TOPMOST = -1,
HWND_NOTOPMOST = -2
}
A very useful thing to do is to check www.pinvoke.net and retrieve the values of certain constants that you would make use of in various situations.
Next, I had to implement a static class that imports my needed functions from coredll.dll. This dll is very useful to get acustomed with because in it you will find system calls that you are very likely to need in your development process under .NET CF. So, here is what you need:
public static class Coredll
{
/// <summary>
/// The function retrieves the handle to the top-level
/// window whose class name and window name match
/// the specified strings. This function does not search child windows.
/// </summary>
/// <param name=”lpClass”></param>
/// <param name=”lpWindow”></param>
/// <returns></returns>
[DllImport( "coredll.dll", SetLastError = true )]
public static extern IntPtr FindWindowW( string lpClass, string lpWindow );
[DllImport( "coredll.dll", SetLastError = true )]
public static extern bool ShowWindow( IntPtr hwnd, int state );
[DllImport( "coredll.dll", SetLastError = true )]
public static extern bool SetWindowPos( IntPtr hwnd, IntPtr hwndAfter,
int xPos, int yPos, int cX, int cY, int wFlage );
[DllImport( "coredll.dll" )]
public static extern int GetSystemMetrics( int smIndex );
[DllImport( "coredll.dll", SetLastError = true )]
[return: MarshalAs( UnmanagedType.Bool )]
public static extern bool SystemParametersInfo( Spi uiAction, uint uiParam, IntPtr pvParam, Spif fWinIni );
[DllImport( "coredll.dll", SetLastError = true )]
[return: MarshalAs( UnmanagedType.Bool )]
public static extern bool SystemParametersInfo( Spi uiAction, uint uiParam, String pvParam, Spif fWinIni );
[DllImport( "coredll.dll", SetLastError = true )]
[return: MarshalAs( UnmanagedType.Bool )]
public static extern bool SystemParametersInfo( Spi uiAction, uint uiParam, ref AnimationInfo pvParam, Spif fWinIni );
[DllImport( "coredll.dll", EntryPoint = "SystemParametersInfo", SetLastError = true )]
public static extern bool SystemParametersInfoGet( uint action, uint param, ref uint vparam, uint init );
[DllImport( "coredll.dll", EntryPoint = "SystemParametersInfo", SetLastError = true )]
public static extern bool SystemParametersInfoSet( uint action, uint param, uint vparam, uint init );
/// <summary>
/// to find whether you are running on a Smartphone or a Pocket PC
/// </summary>
/// <param name=”uiAction”></param>
/// <param name=”uiParam”></param>
/// <param name=”pvParam”></param>
/// <param name=”fWinIni”></param>
/// <returns></returns>
[DllImport( "Coredll.dll", EntryPoint = "SystemParametersInfoW", CharSet = CharSet.Unicode )]
public static extern int SystemParametersInfo4Strings( uint uiAction, uint uiParam, System.Text.StringBuilder pvParam, uint fWinIni );
}
Now, to put things toghether here are the two methods needed to enter full screen mode and end it:
public static void StartFullScreen( Control control )
{
IntPtr hWndInputPanel = Coredll.FindWindowW( “SipWndClass” , null );
IntPtr hWndSipButton = Coredll.FindWindowW( “MS_SIPBUTTON”, null );
if( hWndInputPanel != null ) Coredll.ShowWindow( hWndInputPanel, SW_HIDE );
IntPtr hWndTaskBar = Coredll.FindWindowW( “HHTaskBar”, null );
IntPtr hWnd = control.Handle;
if( hWndTaskBar != null ) Coredll.ShowWindow( hWndTaskBar, (int) Sw.SW_HIDE );
if( hWndInputPanel != null ) Coredll.ShowWindow( hWndInputPanel, (int) Sw.SW_HIDE );
if( hWndSipButton != null ) Coredll.ShowWindow( hWndSipButton, (int) Sw.SW_HIDE );
Coredll.SetWindowPos(
hWnd, (IntPtr) ( (int)Hwnd.HWND_TOPMOST ), 0, 0,
Coredll.GetSystemMetrics( (int) SystemMetric.SM_CXSCREEN ),
Coredll.GetSystemMetrics( (int) SystemMetric.SM_CYSCREEN ),
(int) Swp.SWP_SHOWWINDOW );
}
public static void StopFullScreen( Control control )
{
//IntPtr hWndInputPanel = Coredll.FindWindowW( “SipWndClass” , null );
IntPtr hWndSipButton = Coredll.FindWindowW( “MS_SIPBUTTON”, null );
IntPtr hWndTaskBar = Coredll.FindWindowW( “HHTaskBar”, null );
IntPtr hWnd = control.Handle;
Rect rtDesktop = new Rect( );
if( hWndTaskBar != null )
{
Coredll.ShowWindow( hWndTaskBar, (int) Sw.SW_SHOW );
}
//Never forcibly show the input panel
//if( hWndSipButton != null )
//{
// Coredll.ShowWindow( hWndSipButton, Sw.SW_SHOW );
//}
IntPtr rectPtr = Marshal.AllocHGlobal( Marshal.SizeOf( rtDesktop ) );
if( Coredll.SystemParametersInfo( Spi.SPI_GETWORKAREA, 0, rectPtr, Spif.None ) ) )
{
Rect rect = (Rect) Marshal.PtrToStructure( rectPtr, typeof( Rect ) );
Coredll.SetWindowPos( hWnd, (IntPtr) ( (int) Hwnd.HWND_TOPMOST ), 0, 0, rect.right – rect.left, rect.bottom – rect.top, (int) Swp.SWP_SHOWWINDOW );
}
Marshal.FreeHGlobal( rectPtr );
}
The first method, StartFullScreen, hides the SIP( Standard Input Panel ), the SIP button bar and the task bar leaving the entire screen to be filled by the application window. The application window’s size is set to the size of the entire screen in SetWindowPos. It’s that simple!
When you want to exit full screen mode, you need to show the task bar, get the size of the client work area, specified with Spi.SPI_GETWORKAREA and then calculated the new size of the window( it would appear as a maximized window on your screen ).
You can download a sample project form 4shared: Source code here.