【发布时间】:2011-04-03 14:05:02
【问题描述】:
问题:我有一个不应该看到的控制台程序。 (它会重置 IIS 并删除临时文件。)
现在我可以像这样在启动后立即隐藏窗口:
static void Main(string[] args)
{
var currentProcess = System.Diagnostics.Process.GetCurrentProcess();
Console.WriteLine(currentProcess.MainWindowTitle);
IntPtr hWnd = currentProcess.MainWindowHandle;//FindWindow(null, "Your console windows caption"); //put your console window caption here
if (hWnd != IntPtr.Zero)
{
//Hide the window
ShowWindow(hWnd, 0); // 0 = SW_HIDE
}
问题是这会显示窗口一秒钟。 是否有任何控制台程序的构造函数,我可以在窗口显示之前将其隐藏?
第二个:
我用
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
我不喜欢里面的 32。没有 DllImport 有没有办法做到这一点?
.NET 方式?
【问题讨论】:
-
你为什么不喜欢
user32.dll这个名字? -
user32.dll不是专门的 32 位 DLL,并且适用于所有当前版本的 Windows,无论体系结构如何。这个名字是可以追溯到 NT4 的遗产。
标签: c# .net vb.net winapi console