Program in the Tray



  • 1. Helpful hint
    Just upgraded to Delphi 7 Pro. When I opened a project (> 400 units), the Project Viewer displayed the units unsorted. I tried to find some option to set to sorted (like D5) - no fun. 1) Make a copy of the project 2) Add a unit and place a listbox 3) Set listbox Sorted property to True 4) View source and _Copy_ just the units. Leave Forms. Note the last unit has a semicolon 5) Paste into the Listbox Items 6) Select all lines and copy 7) Paste back into the project source 8) Change the semicolon after the old last unit to a comma 9) Change the comma after the new last unit to a semicolon 10) Delete the original unsorted 'uses' 11) Save All, exit and reenter the project I like to cut/paste the main and data units to the top. That way I get the best of both worlds. D5 always sorted, & direct edits to the project source often broke the project. I'm sure someone else has done this but I couldn't find it. cheers - Dave
  • 2. LTP port with win 2000 ?
    How to write datas to the port LPT1 under win 2000 ? Can you help me please ?
  • 3. Capturing stdin/stdout for called processes
    Has Anyone found a stable way of capturing the sdtout stream from a called process? For example, when calling another command line app, in C++ it's pretty trivial to catch the stdout with a pipe, but I can't seem to get it to work in Delphi, and I've tried getOverlapped read, pipes and threaded access, to no avail. I either seem to get nothing, or hung. Thanks for any advice or examples. (Please excuse the 3-way x-post, and CC replies to mrcookies at yahoo)
  • 4. PDF Parser ?
    I am trying to import simple graphics and text from PDF files and draw/write them on a Delphi canvas. Does anyone have code or links to achieve that ? Thanks, Jacques

Program in the Tray

Postby Fons » Fri, 15 Jun 2007 05:42:59 GMT

I found an example of how to run a program with an icon in the tray and 
not with a bar next to the bars of the other programs running. As long 
as the program runs without displaying a window, it can run "invisible". 
I have written a small clock program; just to display the time. The 
problem is that when a program in the tray also displays a window, it 
also gets a bar next to the other applications. You probably now what my 
question is; can I make a program run with only an icon in the tray and 
a window visible ?


Re: Program in the Tray

Postby Rob Kennedy » Fri, 15 Jun 2007 06:49:31 GMT

What you're asking is how to prevent a window from appearing as a button 
on the taskbar. Now that you know the terminology, searching should be 
easier. You're asking for anything that hasn't been done a hundred times 

 http://www.**--****.com/ +window+taskbar+button&as_ugroup=*delphi*

The fact that you have an icon in the shell notification area is 
completely irrelevant.


Re: Program in the Tray

Postby Fons » Fri, 15 Jun 2007 08:05:27 GMT

Yes, I was thinking like a human being and not like a programmer; it's 
not "moving" from taskbar to tray, it's removing one and creating a new 
one. But 5 minutes Googling gave me:

   procedure TFormMain.FormActivate(Sender: TObject);
     showwindow(application.handle, sw_hide);

Giving me that code would've saved you some typework ;-p

And make me lazier.

Thanks for the Google,

Re: Program in the Tray

Postby Heinrich Wolf » Fri, 15 Jun 2007 17:01:35 GMT

I also made such a program some years ago.
Look at  http://www.**--****.com/ 
-> Technical info and free software
-> Download outline
-> TxtClock.exe


Re: Program in the Tray

Postby Fons » Sun, 17 Jun 2007 01:58:22 GMT

Taskbar and tray are solved. But the icon in the "alt-tab-menu" is still 
visible. (How) can I remove this ? No; Google didn't help. That there is 
no link between taskbar and tray is clear. But that the list in the 
taskbar differs from the list in the "alt-tab-menu" ?


Re: Program in the Tray

Postby John Dough » Sun, 17 Jun 2007 15:58:44 GMT

On Fri, 15 Jun 2007 18:58:22 +0200, Fons

To accomplish what you're describing, you have to run your application
strictly inside the icon tray.  Otherwise, whenever your main form is
active, you will have the application's icon visible in the ALT-TAB
list.  As far as I know, there is no way to prevent this.  Or maybe
there is, but I haven't come across it, nor have I ever needed to. tell your application to go into the icon tray, you have to
intercept the form's close event and put your code in there.

The simplest way to demonstrate this is to put a checkbox on your
form.  Then you assign an OnCloseQuery event for your main form.

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose:
  canclose := (not checkbox1.Checked);
  if not canclose then
      application.mainform.visible := false;
      if iswindowvisible(application.handle) then

If the checkbox is empty, then your application will close (terminate)

If the checkbox is checked, then when you close your application, it
will go into the icon tray instead of actually shutting down.  You can
verify this by using the task manager in Windows to see that your
application is still running (or if you're running from inside the
IDE, then you'll see that the control isn't returned to Delphi).

Re: Program in the Tray

Postby Fons » Mon, 18 Jun 2007 04:33:54 GMT

The problem is that I want a small window (it's a simple program) always 
being visible without the application being visible in taskbar, tray or 
alt-tab menu. If you want to edit: click in the window. If you want to 
close the program: double-click.

But the fact that it's not in the taskbar and tray is most of what I 
wanted but I was surprised by the fact that it wasn't in the taskbar but 
still visible in the alt-tab menu.


Re: Program in the Tray

Postby Jamie » Mon, 18 Jun 2007 09:35:36 GMT

  Try this.
    Override the CreateParams for the main form, change the
class of the window which signals it to show as an icon when
    Look up CreateWindowEx and check out the creation flags.
  Remove the WS_EX_APPWINDOW flag.
  You may even be able to do this using the Class functions also with
out overriding.

"I'm never wrong, once i thought i was, but was mistaken"
Real Programmers Do things like this.

Re: Program in the Tray

Postby John Dough » Mon, 18 Jun 2007 11:43:41 GMT

On Sat, 16 Jun 2007 21:33:54 +0200, Fons

I don't think there's a way around that.  The way that Windows is
designed, you will always see your application in the ALT-TAB list as
long as it has an active window on the desktop.

On my computer, I have 5 programs running in the icon tray.  None of
them are visible with ALT-TAB, but as soon as I double-click on one of
them to bring up their main form, the application immediately becomes
visible in ALT-TAB (which is how it should be).

In any case, why is it important for you to make it so that your
application will not be visible in the ALT-TAB list?

Re: Program in the Tray

Postby Rob Kennedy » Mon, 18 Jun 2007 13:03:52 GMT

That's not true. Ever used Winamp? Or the Office toolbar? Or Google Desktop?

Supposedly the code in the following message will remove a window from 
the Alt+Tab list and from the taskbar.



Re: Program in the Tray

Postby John Dough » Mon, 18 Jun 2007 14:05:49 GMT

On Sat, 16 Jun 2007 23:03:52 -0500, Rob Kennedy < XXXX@XXXXX.COM >

Yes, I use it all the time, and yes, it's visible in the ALT-TAB list.

Haven't used it since they discontinued it as a default install option
(back in '98 I think).

No, I don't allow unnecessary {*filter*}onto my system.

The code listed on that link does absolutely nothing useful, unless
you click on the Minimize button of your application, in which case
you've minimized your app, and your form is no longer visible.  I've
already given him a routine to do this in an earlier post which would
send his program to the icon tray in an "invisible" state.

But what he wants is to have his application's main form visible,
WHILE it's hidden on both the taskbar and the ALT-TAB list.

Re: Program in the Tray

Postby Rob Kennedy » Tue, 19 Jun 2007 03:19:24 GMT

Only because you have that option set. Play with the "show Winamp in" 
section of the "general preferences" page for other combinations.

OK. I didn't try the code. I just repeated what the message's text said.

Anyway, it's entirely possible for a visible window to have no button on 
the taskbar and no icon in the Alt+Tab list. In fact, the code from the 
article I cited does exactly that for the application window. Do the 
same thing for the main form, and you're all set. For example, override 
the form's CreateParams method like so:

   Params.ExStyle := Params.ExStyle or ws_ex_ToolWindow and not 


Re: Program in the Tray

Postby Fons » Tue, 19 Jun 2007 05:51:04 GMT

What I wrote is almost nothing :-) A window (no borders) with one label 
that shows the time. One click and it shows a calendar. Double-click and 
it closes. It is always on top of other windows. That's it. So I don't 
want it to be "in the way" of other application windows. And I never 
want to alt-tab to it.


Re: Program in the Tray

Postby Fons » Tue, 19 Jun 2007 06:02:24 GMT

I tried this but it doesn't work ...

... in my program.


Similar Threads:

1.program in system tray - when to define owner?

Hi all. My program starts minimized to system tray, so the mainform 
event show is not activated till later. I suspect that if I create 
another form in mainform.formcreate, with the owner as mainform that 
does not seem to be a reliable construct as the mainform owner is not 
created yet right?
If what I suspect is right, since the form is not shown after create, 
what would be the best event to place the newform.create with owner as 

2.Detecting if a tray icon program is running.


If I am running a program called 'trayprog.exe' in the tray icon area,
how can I detect it is running through another program?


3.Delphi Program Launching VB Program

This is a VB question, really.

I inherited a Delphi program (Program A) which launches another Delphi
(Program B) and then quits.  When Program B is finished, it re-launches
Program A and then quits.  (There's a reason Program A and B quit when
finished.)  I assume they're using the ShellExecute API to launch each

I'm replacing Program B with a VB program, (Program C).  I give it the same
name as Program B so that it gets launched automatically by Program A
instead of Program B.  This works, no problem.  Then Program C will
re-launch Program A, using WinAPI ShellExecute.

However, at this point, Program A (Delphi) is not able to launch Program C
(VB) again.  No error messages are created.  There is no indication of any
problem at all.

This all works fine when both programs are Delphi, and when both programs
are VB.  I don't know Delphi and don't have access to a Delphi compiler.  I
do have access to the source code if necessary, but couldn't change it.  I
inherited the Delphi stuff and it's working, but I need to replace the one
component and my choice is to use VB.

Any ideas why there might be a problem re-launching the VB program from the
Delphi program the second time?  The is very re-creatable.  Whenever the VB
program has launched the Delphi program, the Delphi program is not able
re-launch the VB program.

Any help would be greatly appreciated.


4.Parallel program to on-line program

I'd like to write a program that runs at the same time as an on-line 
program. It should be able to read the messages that are sent to the on-line 
program. By on-line program I mean one that receives input from a web 
connection. I suppose I'd have to discover what port was being used, by 
trial and error, but I have no idea how to go about the job. Any ideas? 

5.Characterizing a .NET program vs. an EXE program

6. Message map - older program needs to call new program

7. Tray Icon disappears when changing formstyle

8. Tray Icon disappears when changing formstyle (2)

Return to delphi


Who is online

Users browsing this forum: No registered users and 79 guest