C# 启动隐藏在Dot Net Compact Framework中的应用程序
我试图在windows加载时隐藏我的应用程序加载。我创建了一个带有参数的快捷方式,如果参数等于“WINDOWS”,我将尝试隐藏窗体。但是无论我隐藏窗体还是将可见性设置为false,窗体始终显示。我该怎么做呢C# 启动隐藏在Dot Net Compact Framework中的应用程序,c#,windows-mobile,compact-framework,startup,hidden,C#,Windows Mobile,Compact Framework,Startup,Hidden,我试图在windows加载时隐藏我的应用程序加载。我创建了一个带有参数的快捷方式,如果参数等于“WINDOWS”,我将尝试隐藏窗体。但是无论我隐藏窗体还是将可见性设置为false,窗体始终显示。我该怎么做呢 [MTAThread] static void Main(string[] args) { if (args.Length > 0) { Debug.WriteLine("A
[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窗口。如何使其加载隐藏
Thanx提前了很多:)应用程序.Run(Form)方法的定义是: 开始在当前线程上运行标准应用程序消息循环,并使指定表单可见 您可以创建表单,然后休眠或阻塞,直到希望表单可见,然后在需要显示表单时对创建的表单调用
Application.Run()
如果应用程序甚至在表单显示之前就需要执行任务,您可以将该代码置于表单逻辑之外(甚至根本不使用表单)。应用程序运行(表单)方法的定义是: 开始在当前线程上运行标准应用程序消息循环,并使指定表单可见 您可以创建表单,然后休眠或阻塞,直到希望表单可见,然后在需要显示表单时对创建的表单调用
Application.Run()
如果应用程序甚至在表单显示之前就需要执行任务,您可以将该代码放在表单逻辑之外(甚至根本不使用表单)。我在这里介绍了一种简单的技术:
我在这里写了一个简单的技巧:
我认为正确的答案是启动自己的信息泵。我从BenPas博客(原名at)上复制了以下代码,我只能在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);
以下是如何使用它创建messge循环:
[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的回调将执行,但不会显示任何窗口,任务栏中也不会添加任何内容。我认为正确的答案是启动您自己的消息泵。我从BenPas博客(原名at)上复制了以下代码,我只能在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);
以下是如何使用它创建messge循环:
[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的回调,但不会显示任何窗口,任务栏中也不会添加任何内容。此答案不应标记为答案,因为除非调用Application.Run(…),否则消息泵不会运行。在Compact Framework中,唯一存在的Application.Run需要一个表单对象。此应答不应标记为应答,因为除非调用Application.Run(…),否则消息泵不会运行。在Compact Framework中,唯一存在的应用程序.Run需要一个表单对象。问题是关于.NET Compact Framework,这意味着windows CE。问题是关于.NET Compact Framework,这意味着windows CE。我认为最好不要与windows消息争用。在frmMain.Location put EXTER visible屏幕的可见区域中,设置一个定时器组件来设置frmMain.visible=false。我认为最好不要使用windows消息。在frmMain.Location put Out visible area of screen中,将计时器组件设置为设置frmMain.visible=false。