Wednesday, March 28, 2012

Hide Application Task Bar Button from Windows Taskbar

// ******************************************************* //
// Hide Application Taskbar Button for Delphi <=2006
// ******************************************************* //

procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowWindow(Application.Handle, SW_HIDE) ;
  SetWindowLong(Application.Handle, GWL_EXSTYLE, getWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW) ;
  ShowWindow(Application.Handle, SW_SHOW) ;
end;

// above code doesn't work on Delphi >=2007


// ******************************************************* //
// Hide Applicaton Taskbar Button for Delphi >=2007
// ******************************************************* //

// Menu->Project->View Source
program Project1;

uses
  Vcl.Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := False;   // Change True to False, Default is True
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

// on Unit1.pas
procedure TForm1.FormActivate(Sender: TObject);
begin
  ShowWindow(Application.Handle, SW_HIDE);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  ShowWindow(Application.Handle, SW_HIDE);
end;