0

I need to get an icon to disappear out of the system tray. When I move the mouse over it, it does disappear. Can I get Inno Setup to simulate the mouse movements? I found some Pascal code online but can't get it to run in Inno. Maybe I'm missing something easy.

uses 
.... probably not all of these are necessary, but jwawinuser is at least....
  JwaTlHelp32 {for running processes},
  JwaWinType {for processes declarations},
  JwaWinBase {just a guess: for closing process handles},
  JwaWinSvc {for services declarations, always required},
  jwawinuser {for clearing tray icon/notification area},
....
procedure CleanSystemTray;
  {description Clean dead icons from system tray/notification area}
var
  hNotificationArea: HWND;
  r: RECT;
  x: integer;
  y: integer;
begin
  hNotificationArea:=FindWindowEx(
    FindWindowEx(FindWindowEx(FindWindowEx
    (0,0,'Shell_TrayWnd', ''),0,'TrayNotifyWnd', ''),0,'SysPager',''),
    0,
    'ToolbarWindow32',
    'Notification Area');
  GetClientRect(hNotificationArea,r);

  //Now we've got the area, force it to update
  //by sending mouse messages to it.
  x:=0;
  y:=0;
  while x < r.Right do begin
    while y < r.Bottom do begin
      SendMessage(hNotificationArea, WM_MOUSEMOVE, 0, (y shl 16) + x);
      y:=y+5;
    end;
    x:=x+5;
  end;
end;  
ees
  • 335
  • 1
  • 2
  • 11
  • Moving the mouse over them is a quirk based on an implementation detail in Windows, and won't work if they're hidden icons. You should really fix the application that is crashing and leaving the icons in place though. This was also given in [your previous question](http://stackoverflow.com/q/25608445/588306). – Deanna Sep 25 '14 at 11:53
  • Nothing is crashing. The service is starting up and continuing to run. I just don't want the icon in the tray. Unfortunately I don't have the source code for the service anymore. – ees Sep 25 '14 at 12:35
  • If the process is still running then moving over it won't change anything. The icon will only disappear on mouse event if whatever process created it is no longer running. – Deanna Sep 25 '14 at 12:43
  • You're right. I did some digging and it turns out we are executing a program from Inno that starts the service. The program is putting the icon out, not the service. All of this was done years ago by people who have left the company. What I really need is to start the service directly from Inno and avoid this whole mess. – ees Sep 25 '14 at 13:39
  • Here is an [`untested translation`](http://pastebin.com/hVH0nTNj) of that code. But I would rather trust to [`this project`](http://www.codeproject.com/Articles/19620/LP-TrayIconBuster). – TLama Sep 25 '14 at 16:12
  • Deanna and @TLama, I was able to fix the problem using other means besides clearing the icon tray. I have not tested that code translation TLama, but thanks for posting. I am going to save it in my personal stash. – ees Sep 26 '14 at 12:21
  • That's the best you could do. Still I'm wondering why MS do not fix this problem if it's known at least since Windows XP, or at least provide a function for manual cleaning of those orphan icons. – TLama Sep 26 '14 at 12:25

0 Answers0