• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#调用SendMessage刷新任务栏图标(强制结束时图标未消失)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文参考C++改写 https://blog.csdn.net/dpsying/article/details/20139651  (该文章的坐标理解的有误解,会导致功能无效)

SendMessage的移动鼠标里的坐标 是基于句柄内的 坐标,并不是屏幕坐标,任务栏宽度300 高度固定40,那么就应该从宽度0-300 坐标15之间 移动过去。

首先声明需要用到的 winapi 函数

 1         [DllImport("user32.dll", EntryPoint = "FindWindow")]
 2         private static extern int FindWindow(string lpszClass, string lpszWindow);
 3         [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
 4         private static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string lpszClass, string lpszWindow);
 5 
 6         [DllImport("user32.dll", EntryPoint = "GetWindowRect")]
 7         private static extern int GetWindowRect(int hwnd, ref System.Drawing.Rectangle lpRect);
 8         [DllImport("user32.dll", EntryPoint = "SendMessage")]
 9         private static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam);
10 
11         private static readonly int WM_MOUSEMOVE = 512;
winapi

封装调用的流程方法

 1         /// <summary>
 2         /// 刷新任务栏图标
 3         /// </summary>
 4         public static void RefreshTaskbarIcon()
 5         {
 6             //任务栏窗口
 7             int one = FindWindow("Shell_TrayWnd", null);
 8             //任务栏右边托盘图标+时间区
 9             int two = FindWindowEx(one, 0, "TrayNotifyWnd", null);
10             //不同系统可能有可能没有这层
11             int three = FindWindowEx(two, 0, "SysPager", null);
12             //托盘图标窗口
13             int foor;
14             if (three > 0)
15             {
16                 foor = FindWindowEx(three, 0, "ToolbarWindow32", null);
17             }
18             else
19             {
20                 foor = FindWindowEx(two, 0, "ToolbarWindow32", null);
21             }
22             if (foor > 0)
23             {
24                 System.Drawing.Rectangle r = new System.Drawing.Rectangle();
25                 GetWindowRect(foor, ref r);
26                 //从任务栏左上角从左到右 MOUSEMOVE一遍,所有图标状态会被更新
27                 for (int x = 0; x < (r.Right - r.Left) - r.X; x++)
28                 {
29                     SendMessage(foor, WM_MOUSEMOVE, 0, (1 << 16) | x);
30                 }
31             }
32         }
方法

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c/c++调用dos命令发布时间:2022-07-13
下一篇:
C++中的函数定义、声明、调用发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap