启动隐藏在 Dot Net Compact Framework 中的应用程序

发布于 2024-09-11 02:32:18 字数 959 浏览 1 评论 0原文

我试图在 Windows 加载时隐藏我的应用程序加载。我创建了一个带有参数的快捷方式,如果参数等于“WINDOWS”,我试图隐藏表单。但无论我隐藏表单或将可见性设置为 false,表单始终显示。我该如何去做呢?

[MTAThread]
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Debug.WriteLine("Arguments were passed");
                foreach (string item in args)
                {
                    MessageBox.Show(item);
                }


                Application.Run(new frmMain("WINDOWS"));
            }    

        }

在 frmMain 的构造函数中,

public frmMain(string Argument)
        {
            InitializeComponent();

            if (Argument != null && Argument != "")
            {                
                if (Argument == "WINDOWS")
                {
                    this.Visible = false;
                    //Hide();
                }  
           }

但 frmMain 窗口始终显示。如何使其隐藏加载?

提前非常感谢:)

I am trying to make my application load hidden when windows loads. I have created a shortcut with a parameter and I am trying to hide the form if the parameter equals to "WINDOWS". But the Form is ALWAYS shown regardless I hide the form or set the visibility to false. How do i get about doing this?

[MTAThread]
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Debug.WriteLine("Arguments were passed");
                foreach (string item in args)
                {
                    MessageBox.Show(item);
                }


                Application.Run(new frmMain("WINDOWS"));
            }    

        }

and in the constructor of frmMain

public frmMain(string Argument)
        {
            InitializeComponent();

            if (Argument != null && Argument != "")
            {                
                if (Argument == "WINDOWS")
                {
                    this.Visible = false;
                    //Hide();
                }  
           }

But the frmMain window is ALWAYS shown. How do make it load hidden?

Thanx a lot in advance :)

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

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

发布评论

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

评论(3

谎言 2024-09-18 02:32:18

我相信正确的答案是启动你自己的消息泵。我从 BenPas 博客(以前位于 http://blog.xeviox.com)复制了以下代码只能在 Google 的缓存中找到——该页面的链接已失效。但我已经测试了代码并且它有效。

using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
    public int X;
    public int Y;

    public POINT(int x, int y)
    {
        this.X = x;
        this.Y = y;
    }

    public static implicit operator System.Drawing.Point(POINT p)
    {
        return new System.Drawing.Point(p.X, p.Y);
    }
        public static implicit operator POINT(System.Drawing.Point p)
    {
        return new POINT(p.X, p.Y);
    }
}

[StructLayout(LayoutKind.Sequential)]
public struct MSG
{
    public IntPtr hwnd;
    public UInt32 message;
    public IntPtr wParam;
    public IntPtr lParam;
    public UInt32 time;
    public POINT pt;
}

[DllImport("coredll.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin,
   uint wMsgFilterMax);

[DllImport("coredll.dll")]
public static extern bool TranslateMessage([In] ref MSG lpMsg);

[DllImport("coredll.dll")]
public static extern IntPtr DispatchMessage([In] ref MSG lpmsg);

以下是如何使用它来创建消息循环:

    [MTAThread]
    static void Main()
    {
        HiddenForm f = new HiddenForm();

        MSG msg;
        while(GetMessage(out msg, IntPtr.Zero, 0, 0))
        {
            TranslateMessage(ref msg);
            DispatchMessage(ref msg);
        }
    }

使用上面的计时器消息和基于 Windows 的回调被执行,但没有窗口显示,并且任务栏上没有添加任何内容。

I believe the proper answer is to start your own message pump. I copied the following code from the BenPas Blog (formerly at http://blog.xeviox.com), which I could only find in Google's cache -- the link to the page was dead. But I've tested the code and it works.

using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
    public int X;
    public int Y;

    public POINT(int x, int y)
    {
        this.X = x;
        this.Y = y;
    }

    public static implicit operator System.Drawing.Point(POINT p)
    {
        return new System.Drawing.Point(p.X, p.Y);
    }
        public static implicit operator POINT(System.Drawing.Point p)
    {
        return new POINT(p.X, p.Y);
    }
}

[StructLayout(LayoutKind.Sequential)]
public struct MSG
{
    public IntPtr hwnd;
    public UInt32 message;
    public IntPtr wParam;
    public IntPtr lParam;
    public UInt32 time;
    public POINT pt;
}

[DllImport("coredll.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin,
   uint wMsgFilterMax);

[DllImport("coredll.dll")]
public static extern bool TranslateMessage([In] ref MSG lpMsg);

[DllImport("coredll.dll")]
public static extern IntPtr DispatchMessage([In] ref MSG lpmsg);

Here is how you can use it to create the messge loop:

    [MTAThread]
    static void Main()
    {
        HiddenForm f = new HiddenForm();

        MSG msg;
        while(GetMessage(out msg, IntPtr.Zero, 0, 0))
        {
            TranslateMessage(ref msg);
            DispatchMessage(ref msg);
        }
    }

With the above timer messages and Windows based callbacks are executed, but no window shows, and there nothing is added to the taskbar.

深海里的那抹蓝 2024-09-18 02:32:18

Application.Run(Form) 方法的定义是:

“开始在当前线程上运行标准应用程序消息循环,并使指定的表单可见。”

您可以创建表单,然后休眠或阻止,直到您希望表单可见为止,然后在需要显示表单时在您创建的表单上调用 Application.Run()

如果应用程序需要在显示表单之前执行任务,则可以将该代码放置在表单逻辑之外(或者甚至根本不使用表单)。

The definition for the Application.Run(Form) method is:

"Begins running a standard application message loop on the current thread, and makes the specified form visible."

You could create the form, then sleep, or block, until you want the Form to be visible, and then call Application.Run() on the Form you created when it's time to show it.

If the application needs to perform tasks even before the Form is displayed, you could place that code outside the Form's logic (or even not use a Form at all).

雨后咖啡店 2024-09-18 02:32:18

我在这里写了一个简单的技术:

如何使启动窗体最初不可见或隐藏

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