代码之家  ›  专栏  ›  技术社区  ›  Ranhiru Jude Cooray

启动隐藏在dotnetcompact框架中的应用程序

  •  1
  • Ranhiru Jude Cooray  · 技术社区  · 14 年前

    我试图使我的应用程序加载隐藏时,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"));
                }    
    
            }
    

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

    但是frmMain窗口总是显示的。如何使其隐藏?

    提前很多时间:)

    3 回复  |  直到 14 年前
        1
  •  1
  •   C.Evenhuis    14 年前

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

    Application.Run() 在您创建的窗体上显示。

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

        2
  •  3
  •   erict    13 年前

    http://blog.xeviox.com ),我只能在谷歌的缓存中找到——页面链接已经失效。但我已经测试了代码,它是有效的。

    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的回调被执行,但是没有窗口显示,并且没有任何内容被添加到任务栏。