通过win32api让c#控制Windows任务栏
C#中声明如下:
using System.Runtime.InteropServices;
[DllImport("user32.dll", EntryPoint = "FindWindowA")]
public static extern IntPtr FindWindowA(string lp1, string lp2);
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern IntPtr ShowWindow(IntPtr hWnd, int _value);
其实Windows的任务栏就是一个特殊的窗口,所以操作窗口的方法,对任务栏一样适合!控制代码如下:
//获取任务栏
IntPtr hTray = Form1.FindWindowA("Shell_TrayWnd", String.Empty);
//显示任务栏
Form1.ShowWindow(hTray, 5);
//隐藏任务栏
Form1.ShowWindow(hTray, 0);