windows mobile全屏
近日,需要写一个全屏的程序,以前在WinCE下都是使用ShowWindow来隐藏任务栏就可以了,可是在WM下这样还有开始菜单栏,
用中文关键字google了一圈,还是没出来,后来换成英文关键字终于找到一个函数SHFullScreen(MSDN说这个函数可以用于WinCE的,测试没通过)
具体实现:
public class Win32
{
[DllImport("aygshell.dll")]
public static extern bool SHFullScreen(IntPtr hWnd, uint dwState);
//http://msdn.microsoft.com/en-us/library/aa930139.aspx
const uint SHFS_SHOWTASKBAR = 0x1;//任务栏
const uint SHFS_HIDETASKBAR = 0x2;
const uint SHFS_SHOWSIPBUTTON = 0x4;//输入法
const uint SHFS_HIDESIPBUTTON = 0x8;
const uint SHFS_SHOWSTARTICON = 0x10;//开始菜单栏
const uint SHFS_HIDESTARTICON = 0x20;
/// <summary>
/// 全屏显示,即隐藏WM和win CE的任务栏(和开始菜单栏)
/// </summary>
/// <param name="hWnd">要显示的窗体句柄</param>
/// <param name="isFull">true全屏,false取消全屏</param>
/// <returns></returns>
public static bool FullScreen(IntPtr hWnd, bool isFull)
{
uint dwState = 0;
if (isFull)
{
dwState = SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON;
}
else
{
dwState = SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON;
}
return Win32.SHFullScreen(hWnd, dwState);
}
}
{
[DllImport("aygshell.dll")]
public static extern bool SHFullScreen(IntPtr hWnd, uint dwState);
//http://msdn.microsoft.com/en-us/library/aa930139.aspx
const uint SHFS_SHOWTASKBAR = 0x1;//任务栏
const uint SHFS_HIDETASKBAR = 0x2;
const uint SHFS_SHOWSIPBUTTON = 0x4;//输入法
const uint SHFS_HIDESIPBUTTON = 0x8;
const uint SHFS_SHOWSTARTICON = 0x10;//开始菜单栏
const uint SHFS_HIDESTARTICON = 0x20;
/// <summary>
/// 全屏显示,即隐藏WM和win CE的任务栏(和开始菜单栏)
/// </summary>
/// <param name="hWnd">要显示的窗体句柄</param>
/// <param name="isFull">true全屏,false取消全屏</param>
/// <returns></returns>
public static bool FullScreen(IntPtr hWnd, bool isFull)
{
uint dwState = 0;
if (isFull)
{
dwState = SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON;
}
else
{
dwState = SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON;
}
return Win32.SHFullScreen(hWnd, dwState);
}
}
form的构造函数中调用:
this.WindowState = FormWindowState.Maximized;//这句不能少,且注意窗体的大小与屏幕相同
Win32.FullScreen(this.Handle,true);//本示例在windows mobile 6.1下测试通过
Win32.FullScreen(this.Handle,true);//本示例在windows mobile 6.1下测试通过
这样form启动后就会位于开始菜单和任务栏之上了,而且比使用隐藏任务栏的方法更好,因为如果隐藏了任务栏,程序还要在退出时让任务栏显示,如果程序意外退出就不好了