Delphi source code :

Hide your application from the TaskBar


In the following source code snips, we show you how to hide your Delphi application from Windows' TaskBar.

With the function ShowWindow( HWND, CmdShow ) you can set how a window is shown. The parameters are:

  • HWND: handle of the window
  • CmdShow: "show state". There are several possible values (see the Help files), but for our purpose we are interested in only these two:
      SW_HIDE : hides the window
      SW_SHOW : displays the window

Here's the Delphi source code for hiding your application's "button" from the TaskBar:

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

You can again show your application on the TaskBar:

procedure TForm1.Button2Click(Sender: TObject);
begin
  ShowWindow(Application.Handle, SW_SHOW);
end;

You can also completely hide your program from view:

    1. Hide the application window from the TaskBar
    2. Hide the window of the main form

In our example below, we show both windows again after 5 seconds. Think about what would happen otherwise...

procedure TForm1.Button3Click(Sender: TObject);
begin
  ShowWindow(Application.Handle, SW_HIDE);
  Hide;        // hide Form1  
  Sleep(5000); // wait 5 seconds
  Show;        // show Form1
  ShowWindow(Application.Handle, SW_SHOW);
end; 

Finally, it's also possible to hide your application from the TaskBar immediately after the start of the program. Just create an OnActivate event handler for the application's main form and complete the code as follows:

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

Related articles:

Hiding the Taskbar
Hide/show Windows' taskbar.


 

TOP :: Source Code and Tutorials :: Crash Course Delphi :: Forum
DelphiLand Club :: :: DC Library :: Tips :: Downloads :: Links

© Copyright 1999-2016 
Studiebureau Festraets