winform 有些项目是不允许显示任务栏的,只允许自己的程序,这类项目,就需要隐藏电脑的任务栏,防止用户操作.
1.注册系统底层方法.
private const int SW_HIDE = 0;
private const int SW_RESTORE = 9;
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int ShowWindow(int hwnd, int nCmdShow);
2.调用方法,控制显示和隐藏
private void zbtnshow_Click(object sender, EventArgs e)
{
ShowWindow(FindWindow("Shell_TrayWnd", null), SW_RESTORE);
}
private void zbtnhide_Click(object sender, EventArgs e)
{
ShowWindow(FindWindow("Shell_TrayWnd", null), SW_HIDE);
}