Text in the system tray

Is it possible to put text into the system tray like the system clock does ? If it is, then how ?  
LVL 1
Dazza051197Asked:
Who is Participating?
 
zacCommented:
Dazza,

Firstly I make three assumptions:

1) You're using delphi (doh)
2) You have access to RXlib (http://rx.demo.ru)
3) You can sucessfully put an icon on the task bar

By far and away the simplest way to perform the task of text on the taskbar is to dynamically create an icon with text in it....

The first step is to create a TBitmap of the correct size and colour depth.  Then simply use

myBitmap.Canvas.TextOut(x, y, myTime);

To write the text to the bitmap.  Now you could manually copy the data bits from the bitmap into an array create the mask and call the API CreateIcon...

However the nice guys who wrote rxlib provided us with the fantastic:

CreateIconFromBitmap(myBmp, myIcon, clWhite);
               Bitmap--^  Icon-^      ^---- Transparent Colour

Now you have an Icon with your text in it, now just change the icon on the system tray and Bobs your uncle..... You have text in the system tray.

Given the size of system tray icons the performance hit of this conversion should not be significant, and may even prove more efficient than a straight text route as the final display is buffered theorectically allowing windows to blit it straight to the screen.

I think this should solve your problem, but if you have any further questions let me know....
Enjoy..

Zac
0
 
venksCommented:
I presume you are talking about the status bar on the bottom of the screen
If it is try the following
Use ANY TRAY ICON COMPONENT and add a hint to it.You can also use popup menus with it.
For eg try the tray icon component that is avilable with RX library downloadable from Delphi Super Page
regards
venks
0
 
Dazza051197Author Commented:
I want to be able to display a clock like the system clock, but show something like the time in Australia.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
ZifNabCommented:
Hi Dazza,

 I don't think it's that easy, perhaps impossible...

 What you can do is make little icons and then combine the to the correct hour. Change every 1/60 hour the icon....

Zif.
0
 
Dazza051197Author Commented:
oh, ok, pity as it would of been nice for me to have the time in Australia then my icons then my local time.  Might get round to doing it as separate icons if I get the time. duh, get the time.!!
0
 
ZifNabCommented:
Dazza,

 Get the time? What so difficult on that?

Zif.
0
 
Dazza051197Author Commented:
Joke, I meant get the time as in I'm too busy, but as it was the time I needed anyway.  I guess I need double time, ie time to find the time and display the time.  But never mind, British sense of humour.
0
 
Gerhard100198Commented:
Dazza,

You might not be able to do it in the system tray but it's easy enough to do it in the taskbar. All you need to do is run your program minimized (you can prevent the user from miximizing it) and the display the time in t the form's caption.
0
 
bomeCommented:
Gerhard, I think it should be in Application 's title property to be displayed in the task bar.

bome
0
 
Gerhard100198Commented:
Bome,

You are 100% correct, it should be Application.Title.
0
 
BlackDeathCommented:
hi, dazza.
hi, zif.
hi, all.

zif - it is not only, well, let's say "ugly", to show the time in the systray via combined icons. but i must admit, that was my first thought, too. especially because the clock seems to take exactly the space of two icons...

i was already wondering if ms did it the same way (you never know...)!

but on the other hand:

change the font for your desktop items.
and you'll see: the clock is affected: it's displayed in the selected font.

that makes it impossible to act properly when realizing via icons.
why?
everybody can create her/his own fonts. and surely you won't have the appropriate icons then to display the clock in this typeface.
apart from that: it's scalable...

the win32.hlp tells us that we have to use Shell_NotifyIcon. which is designed for icons. as the name says. (Edited by Computer101).

i also wanna know how to do this. let us all try to figure this out. it would be a nice component if we made it.


rex,

Black Death.
0
 
erajojCommented:
Hi,
There must are other ways. If you spy on the SYSTRAY with spy++ or other spy-app, you will discover that the clock i a child of the SYSTRAY. So... what you have to do is add a child window to the SYSTRAY in the same way the clock does.
Sorry to say, I don't know how, but I will try and find out.
Ask this question in the MFC group and you will probably get an answer from the guys who wrote the stuff (Mike Blaszczak for instance).

/// John
0
 
ZifNabCommented:
interesting comments!
0
 
BlackDeathCommented:
:-??????????)))...
0
 
bomeCommented:
just another cent regarding putting it as an icon:
I usually have my task bar 2 units of height. This way, the icons are displayed in 2 rows, which would make it unpredictable whether 2 icons are placed next to each other.

Apart of different icon sizes, also the task bar may be moved to the left or right border...(drag it there).

So, I think the icon solution is no way.

bome
0
 
bomeCommented:
Maybe one could use a hook to get into the process of the systray program. From there the child window could be changed...

bome
0
 
erajojCommented:
"There must are..."? - Who touched my keyboard while I was dozing off??? %-6

/// John
0
 
ZifNabCommented:
what about getting the handle of the taskbar, making a childwindow and do all the stuff?
0
 
erajojCommented:
Tried that... NO success. But I guess I'm just stupid. There has to be a simple way. I scrutinized MSDN and came up with... NOTHING! Darn MS! Still think the MFC-gurus are better equipped for finding this kind of stuff in the Explorer-dung. They all seem to have elbow-long rubbergloves. ;-)

/// John
0
 
BoRiSCommented:
Dazza

Here is a short program I wrote to put the time on the caption of a DC, maybe you can modify this to the systemtray as I'm sure it's a DC

this put's the time on the desktop title bar, what title bar you may ask just run this and see...

var
  Form1: TForm1;
  Dc: hDC;
implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
var
  TheTime: array[0..80] of char;
begin
  StrPCopy(TheTime, TimeToStr(time));
  TextOut(Dc, width DIV 2, 5, TheTime, StrLen(TheTime));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
DC := GetWindowDc(GetDeskTopWindow);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ReleaseDc(GetDesktopWindow, dc);
end;

Later
BoRiS
0
 
BlackDeathCommented:
hey, that one's cool -
"says red zac".

zac, that one's really good!

cheerio,

Black Death.

0
 
Dazza051197Author Commented:
Yeh, neat, not what I was after but a lot better than using Icons in the taskbar.  I'll use it though so I've graded your answer.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.