Friday, August 24, 2007

How to: FullScreen in a Windows Mobile APP C#

Legal Note: This code is based on the code of Oleg Levin. You can find the original in the next Link : Source Code

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

[Flags()]
public enum FullScreenFlags : int
{
SwHide = 0,
ShowTaskbar = 0x1,
HideTaskbar = 0x2,
ShowSipButton = 0x4,
HideSipButton = 0x8,
SwRestore = 9,
ShowStartIcon = 0x10,
HideStartIcon = 0x20

}
static class FullScreen
{

#region Win32 API Calls

///
/// The GetCapture function retrieves a handle to the window
///

///
[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

///
/// The SetCapture function sets the mouse capture to
/// the specified window belonging to the current thread
///

///
///
[DllImport("coredll.dll")]
private static extern IntPtr SetCapture(IntPtr hWnd);

///
/// This function can be used to take over certain areas of the screen
/// It is used to modify the taskbar, Input Panel button,
/// or Start menu icon.
///

///
///
///
[DllImport("aygshell.dll", SetLastError = true)]
private static extern bool SHFullScreen(IntPtr hwnd, int state);

///
/// 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.
///

///
///
///
[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr FindWindowW(string lpClass, string
lpWindow);

///
/// changes the position and dimensions of the specified window
///

///
///
///
///
///
///
///
[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr MoveWindow(IntPtr hwnd, int x, int y, int
w, int l, int repaint);
#endregion

#region General Methods

///
/// obtain the window handle of a .Net window or control
///

///
///
public static IntPtr GetHWnd(Control c)
{
IntPtr hOldWnd = GetCapture();
c.Capture = true;
IntPtr hWnd = GetCapture();
c.Capture = false;
SetCapture(hOldWnd);
return hWnd;



}

///
/// Set Full Screen Mode
///

///
public static void StartFullScreen()
{

//Set Full Screen For Windows CE Device

//Normalize windows state
//form.WindowState = FormWindowState.Normal;
// Here we must to put the windows name
IntPtr iptr = FindWindowW(null, "WindoName");
SHFullScreen(iptr, (int)FullScreenFlags.HideStartIcon & (int)FullScreenFlags.HideTaskbar & (int)FullScreenFlags.HideSipButton);


//detect taskbar height
MoveWindow(iptr, 0 , -40, 240, 395, 1);
//int taskbarHeight = Screen.PrimaryScreen.Bounds .Height - Screen.PrimaryScreen.WorkingArea.Height;

//// move the viewing window north taskbar height to get rid of the command
////bar
iptr = FindWindowW("menu_worker", null);
SHFullScreen(iptr, (int)FullScreenFlags.SwHide);
MoveWindow( iptr, 0, 0, 0, 0, 1);

iptr = FindWindowW("MS_SIPBUTTON", null);
SHFullScreen(iptr, (int)FullScreenFlags.SwHide);
MoveWindow(iptr, 0, 0, 0, 0, 1);

//// move the task bar south taskbar height so that its not visible anylonger
IntPtr iptrTB = FindWindowW("HHTaskBar", null);
SHFullScreen(iptrTB, (int)FullScreenFlags.SwHide);
MoveWindow(iptrTB, 0, 0, 0, 0, 1);



}


///
/// Stop Full Screen Mode
///

///




#endregion
}

No comments: