Exemplo n.º 1
0
 /// <summary>
 /// 刷新系统托盘的图标
 /// </summary>
 public static void RefreshSystemTray()
 {
     try
     {
         int TrayWindow;
         NativeMethods.Rect WindowRect;
         int   SmallIconWidth;
         int   SmallIconHeight;
         Point CursorPos = Point.Empty;
         int   Row;
         int   Col;
         //{ 获得任务栏句柄和边框}
         int hwd = NativeMethods.FindWindow("Shell_TrayWnd", null);
         TrayWindow = NativeMethods.FindWindowEx(hwd, 0, "TrayNotifyWnd", null);
         int isGet = NativeMethods.GetWindowRect(new IntPtr(TrayWindow), out WindowRect);
         if (isGet == 0)
         {
             return;
         }
         //{ 获得小图标大小}
         SmallIconWidth  = NativeMethods.GetSystemMetrics(SM_CXSMICON);
         SmallIconHeight = NativeMethods.GetSystemMetrics(SM_CYSMICON);
         //{ 保存当前鼠标位置}
         NativeMethods.GetCursorPos(ref CursorPos);
         //{ 使鼠标快速划过每个图标 }
         for (Row = 0; Row <= (WindowRect.Bottom - WindowRect.Top) / SmallIconHeight; Row++)
         {
             for (Col = 0; Col <= (WindowRect.Right - WindowRect.Left) / SmallIconWidth; Col++)
             {
                 NativeMethods.SetCursorPos(WindowRect.Left + Col * SmallIconWidth, WindowRect.Top + Row * SmallIconHeight);
                 Thread.Sleep(1);
             }
         }
         //{恢复鼠标位置}
         NativeMethods.SetCursorPos(CursorPos.X, CursorPos.Y);
         //{ 重画任务栏 }
         NativeMethods.Rect tempRect = new NativeMethods.Rect();
         NativeMethods.RedrawWindow(new IntPtr(TrayWindow), ref tempRect, 0, 0x85);
     }
     catch (Exception ex)
     {
         LogHelper.WriteException(ex);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 刷新系统托盘的图标
 /// </summary>
 public static void RefreshSystemTray()
 {
     try
     {
         int TrayWindow;
         NativeMethods.Rect WindowRect;
         int SmallIconWidth;
         int SmallIconHeight;
         Point CursorPos = Point.Empty;
         int Row;
         int Col;
         //{ 获得任务栏句柄和边框}
         int hwd = NativeMethods.FindWindow("Shell_TrayWnd", null);
         TrayWindow = NativeMethods.FindWindowEx(hwd, 0, "TrayNotifyWnd", null);
         int isGet = NativeMethods.GetWindowRect(new IntPtr(TrayWindow), out WindowRect);
         if (isGet == 0) return;
         //{ 获得小图标大小}
         SmallIconWidth = NativeMethods.GetSystemMetrics(SM_CXSMICON);
         SmallIconHeight = NativeMethods.GetSystemMetrics(SM_CYSMICON);
         //{ 保存当前鼠标位置}
         NativeMethods.GetCursorPos(ref CursorPos);
         //{ 使鼠标快速划过每个图标 }
         for (Row = 0; Row <= (WindowRect.Bottom - WindowRect.Top) / SmallIconHeight; Row++)
         {
             for (Col = 0; Col <= (WindowRect.Right - WindowRect.Left) / SmallIconWidth; Col++)
             {
                 NativeMethods.SetCursorPos(WindowRect.Left + Col * SmallIconWidth, WindowRect.Top + Row * SmallIconHeight);
                 Thread.Sleep(1);
             }
         }
         //{恢复鼠标位置}
         NativeMethods.SetCursorPos(CursorPos.X, CursorPos.Y);
         //{ 重画任务栏 }
         NativeMethods.Rect tempRect = new NativeMethods.Rect();
         NativeMethods.RedrawWindow(new IntPtr(TrayWindow), ref tempRect, 0, 0x85);
     }
     catch (Exception ex)
     {
         LogHelper.WriteException(ex);
     }
 }