我正在使用下面的类来隐藏和显示窗口任务栏。 我打电话给下面的班级。应用程序退出甚至不在C#窗口应用程序中触发
问题:当我启动应用程序时,任务栏完全隐藏。 但是当我通过停止调试退出应用程序时,任务栏 没有显示出来。我的意思是应用程序退出不在我的代码中触发。 我需要这样的一种方式,无论我如何关闭应用程序,它都会在退出之前不断地显示tashbar()。
请帮忙。谢谢。
方案:
static class Program
{
[STAThread]
static void Main()
{
Taskbar.Hide();
Form1 TargerForm = new Form1();
Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
Application.EnableVisualStyles();
Application.Run(TargerForm);
}
static void Application_ApplicationExit(object sender, EventArgs e)
{
Taskbar.Show();
}
}
类:
public class Taskbar
{
[DllImport("user32.dll")]
public static extern int FindWindow(string className, string windowText);
[DllImport("user32.dll")]
public static extern int ShowWindow(int hwnd, int command);
public const int SW_HIDE = 0;
public const int SW_SHOW = 1;
public int _taskbarHandle;
protected static int Handle
{
get
{
return FindWindow("Shell_TrayWnd", "");
}
}
public Taskbar()
{
_taskbarHandle = FindWindow("Shell_TrayWnd", "");
}
public static void Show()
{
ShowWindow(Handle, SW_SHOW);
}
public static void Hide()
{
ShowWindow(Handle, SW_HIDE);
}
}
你是什么意思,“仍然没有解决”?当TargetForm完成运行时,Taskbar.Show()将执行。想想看,看起来有趣的一行是App.Run行,它应该看起来像Application.Run(新的TargetForm()) – 2009-07-21 15:31:11