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

来源:互联网 发布:知乎 海天盛筵全部玩法 编辑:程序博客网 时间:2024/05/17 22:13
<script type="text/javascript"><!--google_ad_client = "pub-8218974082131540";google_ad_width = 120;google_ad_height = 240;google_ad_format = "120x240_as";google_ad_type = "text_image";google_ad_channel = "";google_color_border = "FFFFFF";google_color_bg = "FFFFFF";google_color_link = "0000FF";google_color_text = "000000";google_color_url = "008000";//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>  如果你要在你的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);