I recently had the need to insure that a mobile application I wrote, run full screen on a Windows Mobile device. Since I couldn’t find a clear example of how to control the display of the taskbar on a device running Windows CE 5.0. I thought I would post this code snippet from a project I just completed.
const uint SPI_SETWORKAREA = 0×002F;
const uint SPIF_SENDCHANGE = 0×0002;
const UInt32 SWP_NOSIZE = 0×0001;
const UInt32 SWP_NOMOVE = 0×0002;
const UInt32 SWP_NOACTIVATE = 0×0010;
const UInt32 SWP_HIDEWINDOW = 0×0080;
const int HWND_NOTTOPMOST = -2;
[DllImport("coredll.dll", CharSet=CharSet.Auto)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("coredll.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("coredll.dll")]
private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, Rectangle rect, uint fWinIni);
private void HideTaskBar()
{
IntPtr hWndTaskBar = FindWindow(”HHTaskBar”, “”);
SetWindowPos(hWndTaskBar, HWND_NOTTOPMOST, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOSIZE);
Rectangle r = Screen.PrimaryScreen.Bounds;
SystemParametersInfo(SPI_SETWORKAREA, 0, r, SPIF_SENDCHANGE);
}
Basically, the code (C#) above uses P/Invoke to acquire a handle to the taskbar window using FindWindow. Next, a call to SetWindowPos is used to change the topmost status, reposition the taskbar to the top of the screen and hide it. In this case, the Start Menu can still appear (at the top of screen) using Ctrl+Esc but the taskbar is hidden and now my application can consume the entire desktop. If you want to disable the taskbar and Start Menu all together, then call the EnableWindow API function. The last call to SystemParametersInfo is necessary to reclaim the space consumed by the taskbar. The SPIF_SENDCHANGE flag is included to announce the change to other desktop windows.
Bruce is a Microsoft MVP (C#) and founder of Simplify, where he specializes in designing and developing enterprise and mobile applications. In addition to teaching and mentoring developers, Bruce runs the Montgomery Area .NET Developer Group and is frequent speaker at MSDN, user groups and community events.