有些Window应用程序在启动以后会在系统托盘去添加一个小图标, 一般情况下当程序正常退出时会自动去掉,但有时由于应用程序非法关闭,这个图标便一直留在托盘区,直到用鼠标移动图标上时,才会自己消失发。那么如何用C#实现自动移去系统托盘失效的图标

解决方案 »

  1.   

    楼主是还在vs里调试的时候发现c#写的代码直接结束后图标没有消失么?那你多虑了,发布了以后就不能随便结束的,真异常结束,也不是你这个程序能处理的
      

  2.   

    顶。
    都结束了,怎么能控制任务栏图标失效呢,Windows就是这样设计的,所有系统指示器图标都会这样。
      

  3.   

    正常关闭时也是一样的。该程序的系统托盘图标仍在,只有当鼠标移过去图标才消失。我在网上找了C++有这样的。谁能把它改成C#.如何自动移去系统托盘失效的图标void __fastcall RemoveDeadIcons()
    {
      HWND hTrayWindow;
      RECT rctTrayIcon;
      int nIconWidth;
      int nIconHeight;
      TPoint CursorPos;
      int nRow;
      int nCol;
      // Get tray window handle and bounding rectangle
      hTrayWindow = FindWindowEx(FindWindow(
          "Shell_TrayWnd", NULL), 0, "TrayNotifyWnd", NULL);
      if(!GetWindowRect(hTrayWindow, &rctTrayIcon))
        return;
      // Get small icon metrics
      nIconWidth = GetSystemMetrics(SM_CXSMICON);
      nIconHeight = GetSystemMetrics(SM_CYSMICON);
      // Save current mouse position }
      GetCursorPos(&CursorPos);
      // Sweep the mouse cursor over each icon in the tray in both dimensions
      for(nRow=0; nRow<(rctTrayIcon.bottom-rctTrayIcon.top)/nIconHeight; nRow++)
      {
        for(nCol=0; nCol<(rctTrayIcon.right-rctTrayIcon.left)/nIconWidth; nCol++)
        {
          SetCursorPos(rctTrayIcon.left + nCol * nIconWidth + 5,
              rctTrayIcon.top + nRow * nIconHeight + 5);
          Sleep(0);
        }
      }
      // Restore mouse position
      SetCursorPos(CursorPos.x, CursorPos.x);
      // Redraw tray window (to fix bug in multi-line tray area)
      RedrawWindow(hTrayWindow, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
    }
      

  4.   

    lz是这样退出的?
            private void exitToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
      

  5.   

     Application.Exit(); 我的是这样退出的。我所做的程序是调用一个在系统托盘上带有图标的软件。程序关闭时先结束调用程序的进程。再用Application.Exit();关闭本程序的。
      

  6.   

    退出的时间notifyIcon1.Dispose();这样应该可以关闭吧。
      

  7.   

    QQ MSN Outlook都没解决这个问题-_- 祝你能解决...
      

  8.   

    退出的时候
    notifyIcon1.Dispose();