创建一个全屏应用程序

时间:2014-07-23 12:54:47

标签: c# visual-studio-2008 compact-framework pinvoke windows-ce

我们希望我们的应用程序以全屏模式运行,而Win CE 5.0驱动的设备上没有标题栏。该应用程序正在使用.NET Compact Framework 3.5(C#)开发。

我已经按照this教程,但遇到了错误。这是我的代码:

namespace DatalogicDeviceControl
{
  public partial class Form1 : Form
  {
    public const int SWP_ASYNCWINDOWPOS = 0x4000;
    public const int SWP_DEFERERASE = 0x2000;
    public const int SWP_DRAWFRAME = 0x0020;
    public const int SWP_FRAMECHANGED = 0x0020;
    public const int SWP_HIDEWINDOW = 0x0080;
    public const int SWP_NOACTIVATE = 0x0010;
    public const int SWP_NOCOPYBITS = 0x0100;
    public const int SWP_NOMOVE = 0x0002;
    public const int SWP_NOOWNERZORDER = 0x0200;
    public const int SWP_NOREDRAW = 0x0008;
    public const int SWP_NOREPOSITION = 0x0200;
    public const int SWP_NOSENDCHANGING = 0x0400;
    public const int SWP_NOSIZE = 0x0001;
    public const int SWP_NOZORDER = 0x0004;
    public const int SWP_SHOWWINDOW = 0x0040;

    public const int HWND_TOP = 0;
    public const int HWND_BOTTOM = 1;
    public const int HWND_TOPMOST = -1;
    public const int HWND_NOTOPMOST = -2;

    public Form1()
    {
        InitializeComponent();
        HideStartBar();
    }

    [DllImport("coredll.dll", EntryPoint = "FindWindowW", SetLastError = true)]
    private static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName);

    [DllImport("user32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);


    public void HideStartBar()
    {
        IntPtr handle;

        try
        {
            // Find the handle to the Start Bar
            handle = FindWindowCE("HHTaskBar", null);

            // If the handle is found then hide the start bar
            if (handle != IntPtr.Zero)
            {
                // Hide the start bar
                SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_HIDEWINDOW);
            }
        }
        catch
        {
            MessageBox.Show("Could not hide Start Bar.");
        }
    }

}

}

我遇到以下错误:

  

'DatalogicDeviceControl.Form1.SetWindowPos(System.IntPtr,int,int,int,int,uint)'的最佳重载方法匹配有一些无效的参数

2 个答案:

答案 0 :(得分:2)

@dzerow:您的答案是正确的:Windows Mobile不支持user32.dll库。

请改用coredll.dll库。

private const int SRCCOPY = 0x00CC0020;
private const string CORE_DLL = "coredll.dll";
private static IntPtr _taskBar;
private static IntPtr _sipButton;
private static string _deviceId, _deviceIp;
private static DateTime _lastUpdateCheck, _startTime;

[DllImport(CORE_DLL)]
public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);

[DllImport(CORE_DLL)]
public static extern bool CeRunAppAtEvent(string appName, int Event);

[DllImport(CORE_DLL, EntryPoint = "FindWindowW", SetLastError = true)]
public static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName);

[DllImport(CORE_DLL)]
private static extern IntPtr GetDC(IntPtr hwnd);

[DllImport(CORE_DLL)]
public static extern bool MessageBeep(int uType);

[DllImport(CORE_DLL, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

以下是我以前管理的应用程序中的很多代码。部分内容可能不完整,可能会有太多信息。如果缺少某些东西,只需发表评论,我就会填写。

基本上,我编写的例程使您可以调用ShowWindowsMenu(bool enable)来启用或禁用 HHTaskBar (任务栏)和 MS_SIPBUTTON (软输入)按钮)。

public static void ShowWindowsMenu(bool enable) {
  try {
    if (enable) {
      if (_taskBar != IntPtr.Zero) {
        SetWindowPos(_taskBar, IntPtr.Zero, 0, 0, 240, 26, (int)WindowPosition.SWP_SHOWWINDOW); // display the start bar
      }
    } else {
      _taskBar = FindWindowCE("HHTaskBar", null); // Find the handle to the Start Bar
      if (_taskBar != IntPtr.Zero) { // If the handle is found then hide the start bar
        SetWindowPos(_taskBar, IntPtr.Zero, 0, 0, 0, 0, (int)WindowPosition.SWP_HIDEWINDOW); // Hide the start bar
      }
    }
  } catch (Exception err) {
    ErrorWrapper(enable ? "Show Start" : "Hide Start", err);
  }
  try {
    if (enable) {
      if (_sipButton != IntPtr.Zero) { // If the handle is found then hide the start bar
        SetWindowPos(_sipButton, IntPtr.Zero, 0, 0, 240, 26, (int)WindowPosition.SWP_SHOWWINDOW); // display the start bar
      }
    } else {
      _sipButton = FindWindowCE("MS_SIPBUTTON", "MS_SIPBUTTON");
      if (_sipButton != IntPtr.Zero) { // If the handle is found then hide the start bar
        SetWindowPos(_sipButton, IntPtr.Zero, 0, 0, 0, 0, (int)WindowPosition.SWP_HIDEWINDOW); // Hide the start bar
      }
    }
  } catch (Exception err) {
    ErrorWrapper(enable ? "Show SIP" : "Hide SIP", err);
  }
}

请确保在程序退出时重新打开这些功能,否则用户必须重启设备才能重新启用这些功能。

编辑:我忘记了我创建的WindowPosition枚举值:

public enum WindowPosition {
  SWP_HIDEWINDOW = 0x0080,
  SWP_SHOWWINDOW = 0x0040
}

很抱歉。

还有别的吗?

答案 1 :(得分:1)

不幸的是,Windows Mobile不包含user32.dll,以及许多其他正常的Windows API DLL。我不得不将P / Invoke改为coredll.dll。有关签名,请参阅PInvoke.net's部分(左下角)中的“智能设备功能”。