通过win32api让c#控制Windows任务栏

来源:互联网 发布:男性脱发 知乎 编辑:程序博客网 时间:2024/06/06 09:04

如果你要在你的C#程序中控制Windows的任务栏,有两个Windows api 可以帮到你!他们就是  FindWindowA 和 ShowWindow  

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);

原创粉丝点击