有一个别人的程序,我需要定时杀它的进程,但是会在托盘遗留下它的托盘图标,只要鼠标一移到上面就会消失,但是怎么用程序控制,每当我杀掉它的进程,就自动刷新托盘图标或者让它消失。
我试着找了一些代码,如SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_IDLIST+SHCNF_FLUSH,nil,nil);这样的刷新并不起作用。

解决方案 »

  1.   

    如何自动移去系统托盘失效的图标
    http://www.ccrun.com/article.asp?i=617&d=5sbm2o
      

  2.   

    准确的说是用C++Builder写的,翻译成Delphi就可以了。原理清楚了就好办。
      

  3.   

    procedure  TForm1.RemoveDeadIcons();
    var
        hTrayWindow:HWND;
        rctTrayIcon:TRECT;
        nIconWidth,nIconHeight:integer;
        CursorPos:TPoint;
        nRow,nCol:Integer;
    Begin
        // Get tray window handle and bounding rectangle
        hTrayWindow := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'TrayNotifyWnd', nil);
        if Not (GetWindowRect(hTrayWindow, rctTrayIcon)) then
            Exit;
        // 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 To ((rctTrayIcon.bottom-rctTrayIcon.top) div nIconHeight) Do
        Begin
            for nCol:=0 To ((rctTrayIcon.right-rctTrayIcon.left)div nIconWidth) Do
            Begin
                SetCursorPos(rctTrayIcon.left + nCol * nIconWidth + 5,
                        rctTrayIcon.top + nRow * nIconHeight + 5);
                Sleep(0);
            end;
        end;
        // Restore mouse position
        SetCursorPos(CursorPos.x, CursorPos.x);
        // Redraw tray window (to fix bug in multi-line tray area)
        RedrawWindow(hTrayWindow, nil, 0, RDW_INVALIDATE Or RDW_ERASE Or RDW_UPDATENOW);
    end;