【问题标题】:How to create a full screen application in Win CE 6.0 using .NET Compact Framework 3.5?如何使用 .NET Compact Framework 3.5 在 Win CE 6.0 中创建全屏应用程序?
【发布时间】:2009-12-09 14:49:46
【问题描述】:

我们希望我们的应用程序在 Win CE 6.0 驱动的设备上以没有标题栏的全屏模式运行。该应用程序正在使用 .NET Compact Framework 3.5 (C#) 开发。任何示例代码或文章指针都表示赞赏。

【问题讨论】:

    标签: c# compact-framework


    【解决方案1】:

    使用此代码:

    public class FullScreenEngine
    {
        // Fields
        private IntPtr _hWndInputPanel;
        private IntPtr _hWndSipButton;
        private IntPtr _hWndTaskBar;
        private Rectangle _desktopArea;
    
        public FullScreenEngine()
        {
            Init();
        }
    
        public bool SetFullScreen(bool mode)
        {
            try
            {
                if (mode)
                {
                    if (_hWndTaskBar.ToInt64() != 0L)
                    {
                        ShowWindow(_hWndTaskBar, SW_HIDE);
                    }
                    if (_hWndInputPanel.ToInt64() != 0L)
                    {
                        ShowWindow(_hWndInputPanel, SW_HIDE);
                    }
                    if (_hWndSipButton.ToInt64() != 0L)
                    {
                        ShowWindow(_hWndSipButton, SW_HIDE);
                    }
                    WorkArea.SetWorkArea(new RECT(Screen.PrimaryScreen.Bounds));
                }
                else
                {
                    if (_hWndTaskBar.ToInt64() != 0L)
                    {
                        ShowWindow(_hWndTaskBar, SW_SHOW);
                    }
                    if (_hWndInputPanel.ToInt64() != 0L)
                    {
                        //ShowWindow(_hWndInputPanel, SW_SHOW);
                    }
                    if (_hWndSipButton.ToInt64() != 0L)
                    {
                        ShowWindow(_hWndSipButton, SW_SHOW);
                    }
                    WorkArea.SetWorkArea(new RECT(_desktopArea));
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
    
        private bool Init()
        {
            try
            {
                _desktopArea = Screen.PrimaryScreen.WorkingArea;
                _hWndInputPanel = FindWindowW("SipWndClass", null);
                _hWndSipButton = FindWindowW("MS_SIPBUTTON", null);
                _hWndTaskBar = FindWindowW("HHTaskBar", null);
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
    
        private const uint SW_HIDE = 0;
        private const uint SW_SHOW = 1;
    
        [DllImport("coredll.dll")]
        private static extern int ShowWindow(IntPtr hwnd, uint command);
    
        [DllImport("coredll.dll")]
        private static extern IntPtr FindWindowW(string lpClassName, string lpWindowName);
    
        // Nested Types
        public struct RECT
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
    
            public RECT(Rectangle rect) : this()
            {
                Left = rect.Left;
                Right = rect.Left+rect.Width;
                Top = rect.Top;
                Bottom = rect.Top + rect.Height;
            }
        }
    
        private static class WorkArea
        {
            [DllImport("coredll.dll")]
            private static extern bool SystemParametersInfo(uint uAction, uint uparam, ref RECT rect, uint fuWinIni);
    
            private const uint WM_SETTINGCHANGE = 0x1a;
            const uint SPI_GETWORKAREA = 48;
            const uint SPI_SETWORKAREA = 47;
    
            public static bool SetWorkArea(RECT rect)
            {
                return SystemParametersInfo(SPI_SETWORKAREA, 0, ref rect, WM_SETTINGCHANGE);
            }
    
            public static RECT GetWorkArea()
            {
                var rect = new RECT();
                SystemParametersInfo(SPI_GETWORKAREA, 0, ref rect, 0);
                return rect;
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      首先,您必须通过 P/Invoke 隐藏任务栏。这是C代码,应该很简单to convert

      HWND hwndTaskbar = ::FindWindow(_T("HHTaskBar"), NULL); 
      ::ShowWindow(hwndTaskbar, SW_HIDE); 
      

      一旦你这样做了,然后使用 Screen.PrimaryScreen 来确定你的显示器有多大,并将你的表单调整为这些尺寸。

      【讨论】:

      • 能否请您提供一些用于调用这些 API 的 C#。抱歉,我对 P/Invoke 了解不多。
      • 如果你要编写一个 CF 应用程序,你将不得不学习 P/Invoke - 这是没有办法的。这些非常简单,我提供了一个链接,可以帮助您入门。我不给你鱼,只给你鱼竿。
      猜你喜欢
      • 1970-01-01
      • 2012-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      相关资源
      最近更新 更多