全屏应用程序:Windows CE 和 Pocket PC






4.77/5 (16投票s)
为 Windows CE 和 Pocket PC 设备创建全屏应用程序。
引言
许多开发者必须在他们的应用程序中包含“全屏”功能。 在本文中,我专注于 Pocket PC 和 Windows CE 设备。 我尝试为使用 .NET Compact Framework 的 PDA 软件开发者引入一个通用的解决方案,该方案将使他们能够在两个平台上包含全屏模式,而无需重新编译或更改代码。
背景
为什么我们的 PDA 需要全屏模式? 我的三个主要原因如下:
- 禁用用户交互并访问设备上的其他程序
- 充分利用屏幕空间
- 自定义窗体
使用代码
我的全屏解决方案包含三个步骤。
- 通过调用 Windows API 并相应地更改窗体行为来检测平台类型
平台类型检测是调用
SystemParametersInfo
的一个简单操作,用于确定您是在 Smartphone 还是 Pocket PC 上运行。 您需要定义一些常量和P/Invoke
编组代码才能使其从托管代码中工作。 我使用SystemParametersInfo4Strings P/Invoke
来检测设备是否为 Pocket PC。public enum SystemParametersInfoActions : uint { SPI_GETPLATFORMTYPE = 257, // this is used elsewhere for Smartphone/PocketPC detection } #endregion /// /// Get Platform Type: Pocket Pc or Windows CE /// /// 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 Detections methods /// internal partial class PlatformDetection { public static bool IsSmartphone() { return PInvoke.GetPlatformType() == "SmartPhone"; } public static bool IsPocketPC() { return PInvoke.GetPlatformType() == "PocketPC"; } }
P/Invoke
说明//to find whether you are running on a Smartphone or a Pocket PC [DllImport("Coredll.dll", EntryPoint = "SystemParametersInfoW", CharSet = CharSet.Unicode)] tatic extern int SystemParametersInfo4Strings(uint uiAction, uint uiParam, StringBuilder pvParam, uint fWinIni); //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);
这段代码是“设置全屏”方法的一部分
//if not Pocket PC platform if (!Platform.PlatformDetection.IsPocketPC()) { //Set Full Screen For Windows CE Device //Normalize windows state form.WindowState = FormWindowState.Normal; IntPtr iptr = form.Handle; SHFullScreen(iptr, (int)FullScreenFlags.HideStartIcon); //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 it's // not visible anylonger IntPtr iptrTB = FindWindowW("HHTaskBar", null); MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height, Screen.PrimaryScreen.Bounds.Width, taskbarHeight, 1); } else //pocket pc platform { //Set Full Screen For Pocket Pc Device form.Menu = null; form.ControlBox = false; form.FormBorderStyle = FormBorderStyle.None; form.WindowState = FormWindowState.Maximized; form.Text = string.Empty; }
- 调用窗体加载事件的“设置全屏”方法
private void MainForm_Load(object sender, EventArgs e) { FullScreen.StartFullScreen(this); }
- 调用窗体关闭事件的“移除全屏”方法
private void MainForm_Closing(object sender, CancelEventArgs e) { FullScreen.StopFullScreen(this); }
接下来是什么?
此外,您可以自定义窗体以及设置自己的标题,包括电池寿命和自己的关闭按钮。 让我们开始吧!
历史
- 2007 年 6 月 7 日 -- 发布原始文章
- 2007 年 6 月 13 日 -- 更新
- 2007 年 6 月 14 日 -- 进一步更新