开始栏显示在最大化形式上 (Pocket PC 2003)

发布于 2024-10-31 20:24:26 字数 1374 浏览 6 评论 0 原文

环境

  • Windows XP SP3 x32
  • Visual Studio 2005 标准
  • Windows Mobile/Pocket PC 2003
  • .NET Compact Framework 1.0 SP3 和 .NET Framework 1.1
  • Honeywell Dolphin 9500 手持式条码扫描仪

目标

我有一个三表单应用程序和一个外部类 (Program.cs),它具有应用程序入口点 Main()。主窗体首先加载,然后从 MainForm_Load(...) 内部实例化/显示一个类似于启动屏幕的新窗体。我希望所有三种形式都最大化。所有三个窗体都设置了以下属性:

  • this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
  • this.WindowState = System.Windows.Forms.FormWindowState.Maximized; >
  • this.ControlBox = false;

问题

“闪屏”表单显示全屏,没有任何问题。然后我处理它并显示主屏幕(首先加载和 Application.Run(); 的参数。在主屏幕上,一旦检测到列表框 SelectedIndexChanged 事件,就会出现第三种形式显示(将主窗体留在第三个窗体后面)。第三个窗体在窗体的顶部显示任务栏:图片在此 关闭此窗体后,主窗体现在也覆盖了任务栏。

友粘贴链接。让我知道我是否应该在此处发布代码。 WorkOrderView 有一千多行,所以我认为这会更容易。

不相关的建议

我是一个相当新手的程序员,而且我特别缺乏在这种环境中的经验。因此,如果您对我做某些事情的方式有任何建议/批评,请随时向我提出。最好只对帖子发表评论,而不是针对这些类型的回复发布答案。

谢谢!

Environment

  • Windows XP SP3 x32
  • Visual Studio 2005 Standard
  • Windows Mobile/Pocket PC 2003
  • .NET Compact Framework 1.0 SP3 and .NET Framework 1.1
  • Honeywell Dolphin 9500 Handheld Barcode Scanner

Goal

I have a three form application and an external class (Program.cs) that has the application entry point, Main(). The main form loads first and then, from within MainForm_Load(...), instantiates/shows a new form kind of like a splash screen. I want all three forms to be maximized. All three forms have the following properties set:

  • this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
  • this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
  • this.ControlBox = false;

Problem

The "splash screen" form shows up full screen without any issue. I then dispose of it and show the main screen (first to load and the param for Application.Run();. From the main screen, once a list box SelectedIndexChanged event is detected, a third form is shown (leaving the main form behind said third form). That third form shows the task bar over the top portion of my form: image here
Upon closing this form, the main form now has the task bar overlayed as well.

Code

Friend paste links. Let me know if I should just post the code here. WorkOrderView is over a thousand lines so I figured this would be easier.

Unrelated Suggestions

I am quite a green programmer and I especially lack experience in this environment. So, if you have any suggestions/criticisms on the way I'm doing some things, don't hesitate to hit me with them. Probably best to just comment on the post instead of posting an answer for those types of replies.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山人契 2024-11-07 20:24:26

首先,我这些天只运行 Windows Mobile 5 (WM5)。 (几年前我从 PocketPC 2003 升级到了。哈哈)

我发现定义表单的窗口大小在移动设备上效果不佳,并且显示/隐藏多个表单很尴尬,并且行为方式永远不会像您那样想。

不过,请确保您的主窗体的 WindowState 设置为最大化

我还将 ControlBoxMinimizeBox 设置为 False,如果有帮助的话。

与其使用多个表单,不如直接使用面板作为表单,将主表单作为某种 MDI 容器(用词不好,但这就是我正在做的事情),它看起来会好得多。

在我的设计器视图中,每个面板只是一个充满控件的小盒子。

  • 要使用每个面板,请在 Visual Studio 设计器中选择它,您将看到一个位置框(向上和向下、向左和向右箭头)。
  • 右键单击位置框,然后单击置于前面
  • 现在转到面板控件的属性并将Dock 设置为Fill
  • 当此面板为全屏时,请使用适当的名称添加所有按钮、文本框等。像 pnl1_button1pnl2_button1 这样的名称在代码中比 VS 默认的 button1button2 更容易理解。
  • 当您完成此面板的设计视图后,返回到 Dock 属性并将其设置回 None
  • 继续下一个面板控制。

我发现它也有助于维护面板的小草图及其名称和控件的名称。

在主窗体的 Load 事件中,将每个 PanelDock 属性设置为 DockStyle.Fill。然后,当您想要显示一种表单时,只需调用 Panel1.BringToFront() 而不是 dialog.Show() 即可。

移动开发并不难,但又有所不同。 :)

编辑:

在项目的 Program.cs 文件中,我保留了以下静态工具,可用于打开和关闭“开始”菜单(不起作用,因此在 WM5 中很好,但我仍然在我的 PocketPC 版本的代码中得到它)。

我已经有一年左右的时间没有打开这个项目了,但它应该都是有效的。尝试一下。如果我遗漏了什么,请告诉我。

将其粘贴到项目的 Program.cs 文件中后,只需在程序启动时调用 Program.ShowWindowsMenu(false);Program.ShowWindowsMenu(true); 即可。 当你的程序退出时。

static IntPtr _taskBar;
static IntPtr _sipButton;

public enum Notify_Events {
  NOTIFICATION_EVENT_NONE = 0,
  NOTIFICATION_EVENT_TIME_CHANGE = 1,
  NOTIFICATION_EVENT_SYNC_END = 2,
  NOTIFICATION_EVENT_DEVICE_CHANGE = 7,
  NOTIFICATION_EVENT_RS232_DETECTED = 9,
  NOTIFICATION_EVENT_RESTORE_END = 10,
  NOTIFICATION_EVENT_WAKEUP = 11,
  NOTIFICATION_EVENT_TZ_CHANGE = 12,
  NOTIFICATION_EVENT_OFF_AC_POWER,
  NOTIFICATION_EVENT_ON_AC_POWER
}

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

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

[DllImport("coredll.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);

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);
  }
}

static void ErrorWrapper(string routine, Exception e) {
  if (!String.IsNullOrEmpty(e.Message)) {
    MessageBox.Show(e.Message, routine, MessageBoxButtons.OKCancel, MessageBoxIcon.None, 0);
  }
}

编辑2:

声明主窗体的私有静态实例,然后将其包装在项目的Program.cs文件中的try...catch例程中,如下所示:

static Form1 ppcForm = null;

static void Main() {
  ShowWindowsMenu(false);
  try {
    ppcForm = new Form1();
    Application.Run(ppcForm );
  } catch (Exception err) {
    if (!String.IsNullOrEmpty(err.Message)) {
      ErrorWrapper("Mobile Form (Program)", err);
    }
  } finally {
    ShowWindowsMenu(true);
  }
}

First off, I only run Windows Mobile 5 (WM5) these days. (I got to move up from PocketPC 2003 a couple of years ago. LOL)

I've found that defining a Form's Window Size does not work well on mobile devices, and that showing/hiding multiple forms is awkward and never behaves the way you want.

Still, make sure your Main Form has it's WindowState set to Maximized.

I also set ControlBox and MinimizeBox to False, if that helps.

Instead of using multiple forms, it will look much nicer if you simply use Panels as your forms with the Main Form as some kind of MDI container (bad choice of words, but that is what I'm doing).

In my Designer View, each panel is just a small box full of controls.

  • To work with each panel, select it in the Visual Studio designer, and you will see a position box (arrows up & down and left & right).
  • Right-Click the position box and click Bring to Front.
  • Now go over to the panel control's Properties and set Dock to Fill.
  • While this panel is full screen, add all of your buttons, textboxes, etc. with appropriate names. Names like pnl1_button1 and pnl2_button1 are easier to understand in your code than the VS default button1 and button2.
  • When you are through with your design view of this panel, go back to the Dock properties and set it back to None.
  • Go on to the next panel control.

I have found it also helps to maintain a small sketch of your panels with their names and the names of their controls.

In the Load event of your main form, set every Panel's Dock property to DockStyle.Fill. Then, as you want to show one form, simply call Panel1.BringToFront() instead of dialog.Show().

Mobile development isn't hard, but it is different. :)

EDIT:

In the project's Program.cs file, I keep the following static tools that I can use to turn ON and OFF the Start Menu (doesn't work so well in WM5, but I've still got it in my code from my PocketPC version).

I have not had to open this project in a year or so, but it should all be valid. Give them a try. If I've left something out, just let me know.

Once this is pasted into your project's Program.cs file, just call Program.ShowWindowsMenu(false); when your program starts and Program.ShowWindowsMenu(true); when your program exits.

static IntPtr _taskBar;
static IntPtr _sipButton;

public enum Notify_Events {
  NOTIFICATION_EVENT_NONE = 0,
  NOTIFICATION_EVENT_TIME_CHANGE = 1,
  NOTIFICATION_EVENT_SYNC_END = 2,
  NOTIFICATION_EVENT_DEVICE_CHANGE = 7,
  NOTIFICATION_EVENT_RS232_DETECTED = 9,
  NOTIFICATION_EVENT_RESTORE_END = 10,
  NOTIFICATION_EVENT_WAKEUP = 11,
  NOTIFICATION_EVENT_TZ_CHANGE = 12,
  NOTIFICATION_EVENT_OFF_AC_POWER,
  NOTIFICATION_EVENT_ON_AC_POWER
}

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

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

[DllImport("coredll.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);

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);
  }
}

static void ErrorWrapper(string routine, Exception e) {
  if (!String.IsNullOrEmpty(e.Message)) {
    MessageBox.Show(e.Message, routine, MessageBoxButtons.OKCancel, MessageBoxIcon.None, 0);
  }
}

EDIT2:

Declare a private static instance of your main form, then wrap that in a try....catch routine inside your project's Program.cs file like so:

static Form1 ppcForm = null;

static void Main() {
  ShowWindowsMenu(false);
  try {
    ppcForm = new Form1();
    Application.Run(ppcForm );
  } catch (Exception err) {
    if (!String.IsNullOrEmpty(err.Message)) {
      ErrorWrapper("Mobile Form (Program)", err);
    }
  } finally {
    ShowWindowsMenu(true);
  }
}
就是爱搞怪 2024-11-07 20:24:26

您所追求的通常称为“信息亭模式”(这可能有助于您的搜索引擎结果)。

根本问题是开始栏不是您的应用程序的一部分 - 它是 Shell 应用程序的一部分,并且您正在与它竞争所需的行为。您想要的是平台试图阻止您做的事情,因此您必须准备好将您的开发人员引导到平台的脖子上以使其正常运行。

此博客条目是解决此问题的一个非常好的起点,并且可能会给您带来帮助您需要什么,但请随意使用搜索引擎来查找更多/备用建议。实际上,网络上有很多这方面的材料 - 超出了这个答案的范围。

What you're after is usually referred to as "kiosk mode" (which may help your search engine results).

The underlying issue is that the start bar is not part of your app - it's part of the Shell app and you're competing with it for desired behavior. What you want is something the Platform is trying to prevent you from doing, so you have to be prepared to put your developer boot on the platform's neck to get it to behave.

This blog entry is a really good starting point for this issue and will probably give you what you need, but feel free to use a search engine to find more/aternate proposals. There's actually a lot of material on the web for this - more than would belong in this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文