需调用API函数
需在开头引入命名空间
using System.Runtime.InteropServices;
1、通过窗口名字查找
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lp1, string lp2);
示例:
IntPtr hWnd = FindWindow(null, "abc");
2、对窗口进行在任务栏隐藏和打开操作
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern IntPtr ShowWindow(IntPtr hWnd, int _value);
0 隐藏窗口到后台
1 正常大小显示窗口
3、获取当前焦点窗口的句柄
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();
使用方法 : IntPtr myPtr=GetForegroundWindow();
4、获取到该窗口句柄后,可以对该窗口进行操作
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
使用实例: ShowWindo

这篇博客介绍了如何在C#中使用API函数操作Windows任务栏窗口,包括通过窗口名字查找句柄、隐藏/显示窗口、获取焦点窗口句柄、关闭、最大化和最小化窗口,以及获取窗口尺寸。示例代码展示了具体实现方法。
最低0.47元/天 解锁文章
4万+

被折叠的 条评论
为什么被折叠?



