本文参考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 else19 {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 }方法
C# 调用SendMessage刷新任务栏图标(强制结束时图标未消失)拉美和非洲跨境电商平台Linio&Jumia卖家见面会、 auditor、 贝贝母婴网、 【供应商资源】------床上用品四件套 枕套*2 被套*1床单*1、 亚马逊:从小小图书馆到跨境电商巨头、 ASOS Marketplace、 Shopee大战(大促)将近!新老卖家该如何应对这无声的硝烟?、 PPC、
没有评论:
发表评论