Solved

Hide program from taskbar

Posted on 1999-01-04
21
595 Views
Last Modified: 2010-04-04
How do I hide my program from the taskbar, I have used
ShowWindow(Application.Handle, SW_Hide) (or something like that).
It dosn't work 100%, when I start the program, the icon is showed in the taskbar for a short moment and then removed, how do I prevent this.
0
Comment
Question by:koger
  • 10
  • 7
  • 2
  • +1
21 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 1354551
To remove the window from the taskbar:
Add this to formcreate event

ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
  GetWindowLong(Application.Handle, GWL_EXSTYLE)
    or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);

Regards Barry
0
 
LVL 3

Expert Comment

by:williams2
ID: 1354552
You cannot hide the applications tottally (Task Manager), but you should be able to pretty much hide it by doinf the following:

//This should be done at least from the Form OnActivate event
procedure TForm1.FormActivate(Sender: TObject);
begin
  //This Will hide the button on the Taskbar
  ShowWindow(Application.Handle, SW_Hide);
  //This will hide the visible window (Without exceptions)
  ShowWindow(WindowHandle, SW_Hide);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  //This will do that you won't see a "glitch" of the form before it activates. You can get even better results by setting Formstyle := bsNone.
  SetBounds(0,0,0,0);
end;

Regards,
Williams
0
 
LVL 17

Expert Comment

by:inthe
ID: 1354553
sorry Koger you'll need to reject this i read the title and started typing :-)
this is extremely small flicker even on p11 450 it flickers for a small time ,i have tried other things and cant get it any better maybe someone knows another way  
Regards Barry
0
 
LVL 3

Expert Comment

by:williams2
ID: 1354554
Hi Barry, I didn't see this way of doing it. have you tried setting the setbounds(0,0,0,0)? and if that doesn't work you should maybe try to set Formstyle:=bsNone at first?

Though I must admit, that I cannot get your code to work, maybe I'm doing something wrong?

Regards,
Williams
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1354555
koger,

I'm not sure what you're trying to do: Do you want to show a window without that there's a button in the taskbar or are you trying to avoid even to show a window at all?

In the first case I think that Barry's answer is correct (hi Williams, what does not work?). In the second case: Have you tried "Application.ShowMainForm:=false;"?

Regards, Madshi.
0
 
LVL 3

Expert Comment

by:williams2
ID: 1354556
I guess that you are right Madshi, I haven't tried the Application.ShowMainForm, but maybe it's because I first learned to do it by using the Windows.ShowWindow method.

I apologize, I didn't actually look close enough on Barry's example. I see the difference is that the space of the application button is also removed from the Taskbar.

regards,
Williams
0
 
LVL 17

Expert Comment

by:inthe
ID: 1354557
hi all,
Application.ShowMainForm:=false; does not work for what he wants i tried that and form style bsnone etc .on execution the forms icon on button thingy still is visible on taskbar for a small second .this has never been a prob for me i set taskbar to autohide in propertys so i never notice this before
i also tried SetBounds(0,0,0,0); but that makes no form at all.
i think we need to somehow capture the button thingy even before  the form is created.
or i suppose koger could always hide then restore  taskbar itself with:

procedure TForm1.FormCreate(Sender: TObject);
var
Taskbar : Hwnd;
begin
Taskbar:=FindWindow(pchar('Shell_Traywnd'),Nil);
showwindow(taskbar,SW_HIDE);
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
  GetWindowLong(Application.Handle, GWL_EXSTYLE)
    or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
  Sleep(200);
 ShowWindow(Taskbar,SW_RESTORE);

This works just makes the taskbar blink when it restores theres no application icon tere -nice effect i think :-)
Regards Barry
 


0
 

Author Comment

by:koger
ID: 1354558
Madshi:

Do you want to show a window without that there's a button in the taskbar

Right

williams2:

You can hide the program completely, try checking the screensavers that comes with Windows, they know the trick.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1354559
koger
what do you mean screensavers know the trick ?
they just hide the taskbar as in my last comment then instead of restoring it striaghtaway ,they restore it on formclose event.
Regards Barry
0
 
LVL 3

Expert Comment

by:williams2
ID: 1354560
Hmmm.. :-)) ..I just got a very nasty idea hehe

This is a VERY HUGE hack:

How about making an API window on top of the taskbar at creation time and copy the taskbar area on top of the window, then remove the window at Form.OnShow time to cover the "blink"

I know this is not a popular way of doing it hahahaha

Tell me guys, is this humor? :-)

Cheers,
Williams
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 17

Expert Comment

by:inthe
ID: 1354561
hey williams
thats humor alright have you ever tried ths before ?
how about redraw the taskbar onto form .
are these be possible???
Regards Barry

0
 
LVL 3

Expert Comment

by:williams2
ID: 1354562
This was actually what I ment :-)

Ready for some fun ? :-)

Here's an example:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
    ox,oy,ow,oh: Integer;
    CheatEnabled: Boolean;
  public
    { Public declarations }
    BitMap: TBitmap;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  Taskbar : Hwnd;
  TaskDC: hDC;
  TaskRect: TRect;
begin
  CheatEnabled:= True;
  ox:= Left;
  oy:= Top;
  ow:= Width;
  oh:= Height;

  SetWindowLong(Application.Handle, GWL_EXSTYLE,
    GetWindowLong(Application.Handle, GWL_EXSTYLE)
      or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);

  Taskbar:=FindWindow(pchar('Shell_Traywnd'),Nil);
  TaskDC:= GetWindowDC(Taskbar);

  GetWindowRect(Taskbar,TaskRect);
  SetBounds(TaskRect.Left,TaskRect.Top,TaskRect.Right-TaskRect.Left,TaskRect.Bottom-TaskRect.Top);
  BitMap:= TBitmap.Create;
  Bitmap.Width:= Width;
  Bitmap.Height:= Height;

  BitBlt(Bitmap.Canvas.Handle,0,0,Width,Height,TaskDC,0,0,SRCCOPY);

  ReleaseDC(TaskBar,TaskDC);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  If CheatEnabled then
    BitBlt(Canvas.Handle,0,0,Width,Height,Bitmap.Canvas.Handle,0,0,SRCCOPY);
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  If CheatEnabled then
  begin
    ShowWindow(Application.handle,SW_HIDE);
    CheatEnabled:= False;
    Bitmap.free;
    SetBounds(ox,oy,ow,oh);
  End;
end;

end.

Cheers,
Williams
0
 
LVL 3

Expert Comment

by:williams2
ID: 1354563
..sorry, I didn't get rid of a single blink, but I guess that's what you can expect from this :-)

but of course there's also a way to get to hook up the Taskbars OnPaint routine, I just don't feel like it - got things to do..


Regards,
Williams
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1354564
Hmmm, I don't see any flickering with that:

program Project1;

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

{$R *.RES}

begin
  Application.Initialize;
  SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Or do I need glasses?

Regards, Madshi.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1354565
hi Madshi,williams
hey madshi do you know opticion called dolland and aitchens
i hear they quite good LoL HEHEHEHAHAAHHOHOHO
 No really it is still flickering even when do it straighjt after application.initialize ,but not all the time if i do test it 10 times it will flicker about 4 times
it is pretty insignifigant flicker though why does this matter koger??? is a screen saver what you are making?? i running out of ideas to stiop flicker completely :-(
 B.T.W nice coding williams :-)
Regards Barry


0
 
LVL 3

Expert Comment

by:williams2
ID: 1354566
Hi Barry :-)

It was intended to be some sort of a joke hehehe

I will NOT be responsible for any unfortunate behaviors :-)

Actually the Application object creates a button on the taskbar when the application object is first created (calling the handleNeeded method, but you won't see that!)

But you can also try putting the

  SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);

before the application.initialize is called, this might solve it (I cannot see if it works :-( )

Regards,
Williams
0
 
LVL 17

Expert Comment

by:inthe
ID: 1354567
williams you genius you
thats it ,it works hurrah  at last a solution
i did'nt think was possible to code before application.initialize;
i tried it bout 50 times and no flicker ,at all, not once, Nil;
i suggest put as answer
Regards Barry
 -00-
koger here is answer:
put this BEFORE application.initialize;
 and add windows to uses clause :

 SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
0
 
LVL 3

Accepted Solution

by:
williams2 earned 50 total points
ID: 1354568
Alright then:

To everybody following this thread. I find it hard to decide who actually deserve the right answer, since I guess we all learned a great deal from each other, and so therefore I owe you a great deal of my respect.

But I guess I was lucky in my try to obtain the correct answer to this (I really thought the taskbar button was genereated as soon as the application handle was generated as before initialization)

But to make things clear to any newcomers in this thread, the project source should look like this:

program Project1;

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

{$R *.RES}

begin
  SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Regards,
Williams
0
 

Author Comment

by:koger
ID: 1354569
Sorry I havn't been able to come with inputs in a while.

I tried the code in Delphi 2.0, and nothing happends, then I tried in Delphi 4.0 and it works just fine. I'm still using Delphi 2.0, because of the compiled file size which is much smaller.
0
 
LVL 3

Expert Comment

by:williams2
ID: 1354570
What is the error you are getting? ..Then I could provide you an example of how to import the commands from the Windows API

Regards,
Williams
0
 
LVL 3

Expert Comment

by:williams2
ID: 1354571
Ok, with this you can imnport the functions you will need to have this working in Delphi 2:

Just paste this into the project source after starting a new application:

program Project1;

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

Const
  GWL_WNDPROC = -4;
  GWL_HINSTANCE = -6;
  GWL_HWNDPARENT = -8;
  GWL_STYLE = -16;
  GWL_EXSTYLE = -20;
  GWL_USERDATA = -21;
  GWL_ID = -12;

  { Extended Window Styles }
  WS_EX_DLGMODALFRAME = 1;
  WS_EX_NOPARENTNOTIFY = 4;
  WS_EX_TOPMOST = 8;
  WS_EX_ACCEPTFILES = $10;
  WS_EX_TRANSPARENT = $20;
  WS_EX_MDICHILD = $40;
  WS_EX_TOOLWINDOW = $80;
  WS_EX_WINDOWEDGE = $100;
  WS_EX_CLIENTEDGE = $200;
  WS_EX_CONTEXTHELP = $400;

  WS_EX_RIGHT = $1000;
  WS_EX_LEFT = 0;
  WS_EX_RTLREADING = $2000;
  WS_EX_LTRREADING = 0;
  WS_EX_LEFTSCROLLBAR = $4000;
  WS_EX_RIGHTSCROLLBAR = 0;

  WS_EX_CONTROLPARENT = $10000;
  WS_EX_STATICEDGE = $20000;
  WS_EX_APPWINDOW = $40000;
  WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE or WS_EX_CLIENTEDGE);
  WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE or WS_EX_TOOLWINDOW or WS_EX_TOPMOST);

Type

THandle = Longint;

function GetWindowLongA(hWnd: THandle; nIndex: Integer): Longint; stdcall; external 'user32.dll' name 'GetWindowLongA';
function GetWindowLongW(hWnd: THandle; nIndex: Integer): Longint; stdcall; external 'user32.dll' name 'GetWindowLongW';
function GetWindowLong(hWnd: THandle; nIndex: Integer): Longint; stdcall; external 'user32.dll' name 'GetWindowLongA';
function SetWindowLongA(hWnd: THandle; nIndex: Integer; dwNewLong: Longint): Longint; stdcall; external 'user32.dll' name 'SetWindowLongA';
function SetWindowLongW(hWnd: THandle; nIndex: Integer; dwNewLong: Longint): Longint; stdcall; external 'user32.dll' name 'SetWindowLongW';
function SetWindowLong(hWnd: THandle; nIndex: Integer; dwNewLong: Longint): Longint; stdcall; external 'user32.dll' name 'SetWindowLongA';

{$R *.RES}

begin
  SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Regards,
Williams
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now