原文 C#使用Windows API 隐藏/显示 任务栏 (FindWindowEx, ShowWindow)

今天,有网友询问,如何显示和隐藏任务栏?

我这里,发布一下使用Windows API 显示和隐藏 Windows 的任务栏的方法,windows 的任务栏,其实是一个窗口(window),只要找到这个窗口的句柄,显示和隐藏就轻而易举了,任务栏是个没有标题的窗口,但它的类名是 Shell_TrayWnd,所以,可以用FindWindow 或 FindWindowEx 去查找它的句柄,而显示和隐藏窗口,使用的是 ShowWindow:

  • 引入Windows API 的声明
[DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
  • 显示/隐藏任务栏窗口
IntPtr trayHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
if (trayHwnd != IntPtr.Zero)
{
ShowWindow(trayHwnd, 0);
}

上面的代码中, ShowWindow 的第二参数, 1 表示显示, 0 表示隐藏

C#使用Windows API 隐藏/显示 任务栏 (FindWindowEx, ShowWindow)的更多相关文章

  1. Windows api实现桌面任务栏隐藏\显示

    //隐藏任务栏 HWND hWnd = ::FindWindow(TEXT("Shell_traywnd"),TEXT("")); ::SetWindowPos ...

  2. 教程-隐藏/显示任务栏-程序不在任务显示-全面控制Windows

    1.隐藏任务条 var  h:THandle; //变量h:=FindWindow('Shell_TrayWnd',nil);ShowWindow(h,SW_hide); 2.显示任务条h:=Find ...

  3. WinCE隐藏显示任务栏,当任务栏隐藏时将其显示,当任务栏显示时将其隐藏(FindWindow,ShowWindow,IsWindowVisible),

    HANDLE hWndTaskBar = ::FindWindow(TEXT("HHTaskBar"), NULL);  if(::IsWindowVisible(hWndTask ...

  4. iOS 隐藏/显示导航栏

    一.隐藏导航栏 [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBa ...

  5. Android 动态隐藏显示导航栏,状态栏

    Talk is cheap, show me the code. --Linus Torvalds Okay, here: 一.导航栏: [java] view plain copy private  ...

  6. Winform 基础二 最小化 最大化 关闭 点击任务栏隐藏显示 点击鼠标左键移动窗体

    一 最大化 二 最小化 三 关闭 四 点击任务栏隐藏显示 五 点击鼠标左键移动窗体 六 阴影效果鼠标左键移动窗口 #region UI设置 最大化.最小化.关闭.鼠标移动窗口.点击任务栏切换窗口 th ...

  7. C#隐藏与显示系统任务栏和开始菜单栏按钮

    隐藏与显示系统任务栏和开始菜单栏按钮:直接上代码:       private const int SW_HIDE = 0;  //隐藏       private const int SW_REST ...

  8. C#调用Windows API(示例:显示任务管理器里的程序名称)

    作为初学者来说,在C#中使用API确是一件令人头疼的问题. 在使用API之前你必须知道如何在C#中使用结构.类型转换.安全/不安全代码,可控/不可控代码等许多知识. 在.Net Framework S ...

  9. windows API 创建系统托盘图标

    系统托盘在我们使用的程序中很普遍,下面我们来看一个很不错的例子,使用Win32 API实现,对理解系统托盘有些帮助. [cpp] view plaincopy #include <windows ...

随机推荐

  1. hosts文件的路径

    在windows中,hosts文件的路径为:C:\Windows\System32\drivers\etc 在Linux中,hosts文件的路径为:/etc/hosts

  2. JavaSE思维导图(六)

  3. (转)Java通过axis调用WebService

    转自:http://blog.csdn.net/wanglha/article/details/49679825 转载地址:http://www.linuxidc.com/Linux/2015-06/ ...

  4. STL模板_智能指针概念

    一.智能指针1.类类型对象,在其内部封装了一个普通指针.当智能指针对象因离开作用域而被析构时,其析构函数被执行,通过其内部封装的普通指针,销毁该指针的目标对象,避免内存泄露.2.为了表现出和普通指针一 ...

  5. php简单数据缓存类

    公司手机触屏站 ,由于页面图片太多,所以需要做数据缓存,就随便写一个数据缓存类. 直接贴代码 <?php/**** fianl_m@foxmail.com* 缓存类* 把数据查询出,并序列化写入 ...

  6. 获取多个汉字首字母(php)

    <?php function getfirstchar($s0){ $fchar = ord($s0{0}); if($fchar >= ord("A") and $f ...

  7. 编程习题——Maximum Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  8. PullToRrefresh自定义下拉刷新动画

    首先,下载著名的刷新框架https://github.com/chrisbanes/Android-PullToRefresh,其中simple为demo,library和extras作为项目包导入到 ...

  9. nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException

    You should autowire interface AbstractManager instead of class MailManager. If you have different im ...

  10. sublime编辑器怎样高速输入PHP头部版本号声明

    Sublime 菜单条->Tools→New Snippet→得到例如以下图内容: 输入下面内容: <snippet> <content><![CDATA[ < ...