首页 新闻 会员 周边

任务管理器关闭程序后 系统托盘图标成为僵尸图标的问题

0
悬赏园豆:100 [已关闭问题] 关闭于 2016-05-03 09:40

我在任务管理器关闭进程后,在系统托盘还是会有进程的图标,只有在鼠标悬浮上去的时候,这些“僵尸”图标才会消失掉。于是我写了一个程序,模拟鼠标在任务栏悬浮的效果。可是没有效果(我电脑系统是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;
        }

 

问题补充:

天哪……堂堂博客园,竟然没有一人知道该怎么做么?博客园难道真的败落了么?

需要格局的主页 需要格局 | 老鸟四级 | 园豆:2145
提问于:2016-04-25 09:08
< >
分享
所有回答(4)
0

帮顶。虽然无法提供解决方案

小二炒豆芽菜 | 园豆:418 (菜鸟二级) | 2016-04-25 09:57
0

http://blog.csdn.net/waylife/article/details/9623833

试试这个~

waiter | 园豆:1000 (小虾三级) | 2016-04-25 10:00
0

释放资源 垃圾回收

  这些我都做过 但是有时候还是会出现 然后 大神告诉我是WIN问题 我就放弃了

不过 有时候是好的  你可以试试

skin33 | 园豆:110 (初学一级) | 2016-04-28 17:51
0

没有解决,但是这个问题已经挂了这么些天了,也没有一个人能解决,看来只能结贴了

需要格局 | 园豆:2145 (老鸟四级) | 2016-05-03 09:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册