title: How can I stop my application showing on the taskbar?
body: <p>My application has an option for the users to run it only in the system tray, and not in the task bar.  This worked fine when my application was built by Delphi 6.  After switching to Delphi XE2 it no longer functions.</p>
  
  <p>I've messed with it some, and I have this working for Windows 7, but when running on Windows XP I still have a problem.  The application correctly hides from the task bar, and shows in the system tray.  But when I create and show any additional form, the icon shows up in Windows XP.</p>
  
  <pre><code>procedure TfrmAppointment.HideWindowFromTaskbar;
  var
     TaskbarList: ITaskbarList;
  begin
  Application.MainFormOnTaskBar := False;
  
  // Windows 7 seems to behave differently.  This seems to fix it.
  if (CheckWin32Version(6, 1)) then
      begin
      // We are in Win7, and we requested the tray.
      TaskbarList := CreateComObject(CLSID_TaskbarList) as ITaskbarList;
      TaskbarList.HrInit;
      TaskbarList.DeleteTab(Application.Handle);
      end
  else
     begin
     // Previous code from D6 days
     ShowWindow(Application.Handle, SW_HIDE);
     SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
     ShowWindow(Application.Handle, SW_SHOWNOACTIVATE);
     end;
  end;
  </code></pre>
  
  <p>That code is ran if the user chooses the option to show the application in the system tray.  It works fine on all versions of Windows I've tested on.  On Windows XP, however, when I show any child form, the application instantly shows up in the taskbar.  In Windows 7 all is fine.</p>
  
  <p>Any ideas what I'm missing?</p>
  
  <p>I should add that I know this is likely the same question as <a href="https://stackoverflow.com/questions/681621/hide-the-main-form-in-a-delphi-2009-application?rq=1">Hide the Main Form in a Delphi 2009 Application</a>, however I already have the MainFormOnTaskBar being set, so that answer does not seem to apply.</p>
  
  <p>[EDIT:]  To be more specific, I'm adding additional information here.  This application has two modes: Show in task bar, and show in system tray.  </p>
  
  <p>The first mode is the same as any normal application.  The application exists only in the task bar.  It minimizes to the task bar.  It restores from the task bar.  </p>
  
  <p>The second mode behaves exactly the same, BUT that task bar icon instead exists in the system tray only.  So, when a user minimizes the application, I intercept that message, grab the TRect for 'Shell_TrayWnd'/'TrayNotifyWnd', and call DrawAnimatedRects() to simulate the minimize to the tray.  Then I hide the main form.  On message from the system tray I draw the same animation rects in reverse, and make it visible again.  While the form is visible it does not show in the task bar.  </p>
  
  <p>This all works perfectly fine in all Windows versions.  </p>
  
  <p>The specific issue I am having is that when any other form gets shown, Windows XP is creating the application icon in the task bar.  Windows 7 does not do this.  So if a Windows XP user only uses the application main form, no problems arise and both viewing modes work fine.  If they open another window, the application icon appears, and stays there even after that window closes.  Windows 7 does not do this, and the icon stays gone.</p>