c#实现隐藏与显示任务栏的方法详解
时间:2023-05-27 11:59:04
1.导入System.Runtime.InteropServices命名空间。
2.API函数ShowWindow()能够控制人和窗体的现实状态,其声明格式如下:
[DllImport("user32.dll")]
public static extern int ShowWindow(int hwnd,int nCmdShow);
其中hwnd表示窗体的句柄,nCmdShow表示窗体的现实状态。
3.API函数FindWindow()可用于返回任务栏所在窗体类“Shell_TrayWnd”句柄,其声明格式如下:
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName,string lpWindowName);
实例如下,主要代码为(使用了2个btn控件):
private const int SW_HIDE = 0; //隐藏任务栏
private const int SW_RESTORE = 9;//显示任务栏
[DllImport("user32.dll")]
public static extern int ShowWindow(int hwnd,int nCmdShow);
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName,string lpWindowName);
private void button1_Click(object sender, EventArgs e)
{
ShowWindow(FindWindow("Shell_TrayWnd",null),SW_HIDE);
//YinYiNiao's Blog
}
private void button2_Click(object sender, EventArgs e)
{
ShowWindow(FindWindow("Shell_TrayWnd",null),SW_RESTORE);
}
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#获取真实IP地址(IP转为长整形、判断是否内网IP的方法)
![](https://img.aspxhome.com/file/2023/8/69218_0s.jpg)
Java文件读写IO/NIO及性能比较详细代码及总结
java实现MD5加密算法的实例代码
android Retrofit2+okHttp3使用总结
Android极光推送处理message遇到的坑解决
![](https://img.aspxhome.com/file/2023/8/105978_0s.jpg)
Android编程自定义线程池与用法示例
详解Jmeter线程组的设置方法
![](https://img.aspxhome.com/file/2023/2/78362_0s.png)
Java C++ 算法leetcode828统计子串中唯一字符乘法原理
![](https://img.aspxhome.com/file/2023/8/61118_0s.png)
Spring interceptor拦截器配置及用法解析
Java 遍历取出Map集合key-value数据的4种方法
![](https://img.aspxhome.com/file/2023/0/71640_0s.png)
基于ChatGPT+SpringBoot实现智能聊天AI机器人接口并上线至服务器的方法
![](https://img.aspxhome.com/file/2023/5/68015_0s.png)
Android系统设置中的清除数据会清除哪些数据?
Spring JPA find分页示例详解
java 用itext设置pdf纸张大小操作
LINQ排序操作符用法
![](https://img.aspxhome.com/file/2023/2/89902_0s.jpg)
java线程之用Thread类创建线程的方法
Java与Kotlin互调原理讲解
![](https://img.aspxhome.com/file/2023/1/67681_0s.png)
java两种单例模式用法分析
C#字符串如何提取数值(带小数点)
![](https://img.aspxhome.com/file/2023/9/94649_0s.jpg)
Android拼接实现动态对象方法详解
![](https://img.aspxhome.com/file/2023/2/138002_0s.jpg)