我在任务管理器关闭进程后,在系统托盘还是会有进程的图标,只有在鼠标悬浮上去的时候,这些“僵尸”图标才会消失掉。于是我写了一个程序,模拟鼠标在任务栏悬浮的效果。可是没有效果(我电脑系统是win7)大神们能帮我看看代码哪里有错么?真正解决后,还附送福利……
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); //发送消息 [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern Int32 SendMessage(IntPtr hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam); [DllImport("user32.dll")] private static extern bool SendMessage(IntPtr hwnd, int msg, int wParam, StringBuilder lParam); [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", SetLastError = true)] static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect); public Form1() { InitializeComponent(); } const int WM_MOUSEMOVE = 0X0200; //刷新任务栏图标 void RefreshTaskbarIcon() { //任务栏窗口 IntPtr hShellTrayWnd = FindWindow("Shell_TrayWnd", null); //任务栏右边托盘图标+时间区 IntPtr hTrayNotifyWnd = FindWindowEx(hShellTrayWnd, IntPtr.Zero, "TrayNotifyWnd", null); //不同系统可能有可能没有这层 IntPtr hSysPager = FindWindowEx(hTrayNotifyWnd, IntPtr.Zero, "SysPager", null); //托盘图标窗口 IntPtr hToolbarWindow32; hToolbarWindow32 = FindWindowEx(hSysPager, IntPtr.Zero, "ToolbarWindow32", null); if (hToolbarWindow32 != IntPtr.Zero) { RECT r; GetWindowRect(hToolbarWindow32, out r); int width = r.right - r.left; int height = r.bottom - r.top; //从任务栏中间从左到右 MOUSEMOVE一遍,所有图标状态会被更新 for (int x = 1; x < width; x++) { SendMessage(hToolbarWindow32, WM_MOUSEMOVE, 0, MAKELPARAM((uint)x, (uint)height / 2)); } //for (int x = 1; x < width; x++) //{ // for (int y = 0; y < height; y += 4) // { // SendMessage(hToolbarWindow32, WM_MOUSEMOVE, 0, MAKELPARAM((uint)x, (uint)height / 2)); // } //} } hToolbarWindow32 = FindWindowEx(hTrayNotifyWnd, IntPtr.Zero, "ToolbarWindow32", null); if (hToolbarWindow32 != IntPtr.Zero) { RECT r; GetWindowRect(hToolbarWindow32, out r); int width = r.right - r.left; int height = r.bottom - r.top; //从任务栏中间从左到右 MOUSEMOVE一遍,所有图标状态会被更新 for (int x = 1; x < width; x++) { for (int y = 0; y < height; y += 4) { SendMessage(hToolbarWindow32, WM_MOUSEMOVE, 0, MAKELPARAM((uint)x, (uint)height / 2)); } } } } string MAKELPARAM(uint wLow, uint wHigh) { return (wHigh * 0x10000 + wLow).ToString(); } public static IntPtr MakeLParam(int LoWord, int HiWord) { return (IntPtr)(HiWord << 16 | (LoWord & 65535)); } [StructLayout(LayoutKind.Sequential)] private struct RECT { public int left; public int top; public int right; public int bottom; }
帮顶。虽然无法提供解决方案
http://blog.csdn.net/waylife/article/details/9623833
试试这个~
释放资源 垃圾回收
这些我都做过 但是有时候还是会出现 然后 大神告诉我是WIN问题 我就放弃了
不过 有时候是好的 你可以试试
没有解决,但是这个问题已经挂了这么些天了,也没有一个人能解决,看来只能结贴了