Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Desktop Text Display 4

Status
Not open for further replies.

MerryMadDad

Programmer
Dec 11, 2001
47
GB
Hello, I would like to display a line of text from a list on the desktop, one line at a time with the option to choose the position of the text on the desktop. The text must be 'always on top' without any background, border, form, etc just the text itself. I would aslo like to change the font/colour of the text in case the desktop is the same colour as the text. Each line should display for a short time then disappear to be replaced by the next line in the list and continue in a loop.
I am using Delphi 4.

any help much appreciated

Thanks in advance

 
As a starting point, try this link describing how to implement transparent forms (if you are using Delphi 6 or newer):

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Hi Clive, I am using Delphi 4 and do not want to use a form
Thanks
 
May be using an API window (a window created using the Windows API) and making it "stay on top"... but transparency will be a real pain if your program is running in win9x/NT. W2K/XP have transparency as an option, but in win9x you'll need to resort to regions.

Asking in an API forum (like Win API here in Tek-Tips) will bring better answers.

buho (A).
 
MerryMadDad, I do apologise - I read your post in haste and didn't see that you were using Delphi 4!

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Only to clarify: alpha blending is what I called "transparency" in my post above. W2K/XP only, no matter what version of Delphi you are using.

buho (A).


 
does this help

Code:
Transparent text on desktop
Use GetDesktopWindow and GetWindowDC functions to find attributes of desktop for further using. And set background mode by using GetBKMode function.
Change 10,10 for different screen possitions, 

procedure TForm1.Button1Click(Sender: TObject);
var
  Desktop: THandle;
  MyCanvas: TCanvas;
  DesktopDC: HDC;
begin
  Desktop:=GetDesktopWindow;
  DesktopDC:=GetWindowDC(Desktop);

  MyCanvas:=TCanvas.Create;
  MyCanvas.Handle:=DesktopDC;

  SetBkMode(MyCanvas.Handle, TRANSPARENT);
  MyCanvas.TextOut(10,10, 'Hello');
end;

Aaron Taylor
John Mutch Electronics
 
Hi Aaron, thanks very much for your post, it does exactly what I want, but as I have not used Windows API's before , could you help me clear the text after it displays and also I read something in the Delphi help that says HDC should be freed - how do I do that ?

Kind Regards

Robert (in Scotland) :)
 
If you write to the desktop it will not be "always on top" as you asked.

You don't need to release this HDC, as you are not creating it but using an existing one.

To clear the text, read the background area in a TBitmap and repaint it after.

buho (A).
 
Hi Aaron, thanks again for the information, the text displays on top of whatever window is present at the selected position - which is good enough for me. Will take your advice about clearing the text.

Kind regards

Robert
 
If you write "on top of a window" and your text is going to be there for more than a couple secs (may be less) you are going to get a lot of trouble.

For start, your text will be gone if the user closes the windows or Windows itself repaints it in any way (due to moving, rezing or whatever).

Worse than that, if you try to "clear" the text using a background area, it is pretty possible your background area being incorrect. Say, Notebook is open, you read some part of the Notebook window, after that Notebook closes and you write your "Notebook background area" over another window or over the wall paper. Same if the user moves the window, resizes it (the background image is now wrong), open another window on top, closes it, etc.

To write and clear a text directly in the desktop you need to be sure you are writing over the wallpaper (that is what I say it is not going to be "always on top"), and to clear it you need to be sure no window is covering the target area. Other way you are severely messing the user interface.

buho (A).


 
Hi Aaron, thanks again for the additional help, I am having difficulty clearing the text as you say - if an additional windows is open, the text could display in part on one window and the rest on the desktop - so I don't know what to select for the background :( Is there a way to force a screen refresh for everything that is displayed on the screen and that way get rid of the text ? that should not interfere with what the user is doing (I hope)

Kind Regards

Robert
 
I'm going to post some messages discussing the issue. I think you are taking the wrong approach here and getting in deep trouble. I'm going to make more than one post to keep things clear.

(BTW, I'm not Aaron, I'm Buho). :)

buho (A).
 
Approach I: Writting to the desktop.

The only way to write to desktop and not break the hell open in the user interface is writing in a fixed area (say x1, y1, x2, y2) and being sure the area is not covered by any object (window).

a) You assure yourself the area is free where your program starts and copy the background. If the area is not free, temporarily minimize the covering windows and restore them after. (See later)

b) Before writing, you assure yourself the area is free. Temporarily minimize the involved windows if not.

c) Before cleaning you again assure yourself the area is free. Temporarily minimize the involved windows if not.

Note your text will not be "always on top" due to you writing in the wallpaper. Any windows going over your area will hide the text.

How to know if the area is covered? You need to check all the windows to see their coordinates intercept your area coordinates. You can use the API FindWindow family functions for this (search in this forum or google the net, it is plenty of examples).

How to temporarily minimize a window? Use the ShowWindow API function. Same to restore it.

Not only the process is a nuissance from the programmer point of view, it is a pain for the user too, who see his windows being minimized and restored. I doubt a program like that will survive more than five minutes in may machines.
 
Approach II: The API window.

Back to my first post here. Use an API window. If your program is running only in W2K/XP making your window transparent is a cake. In 9x/NT you need to resort to regions; not easy but better than minimizing and restoring the user windows.

 
Approach III: The systray app.

Make a systray app. Any time you need to notificate something, flash the icon and pop a tooltip (like Win XP uses to do).
 
All in all:

a) The "writing to desktop" is a very bad approach, as it is cumbersome and mess the user interface. Carefully choosing the area can help... but little (all desktops areas have the same likelihood of having a window covering it, as most users uses maximized windows).

b) The transparent "always on top" window is way better (a little difficult to implement in 9x/NT). Anyway, forcing an "stay on top" message on top the window the user is working on is not friendly. Carefully choosing the area can really help here, as popping a message in a corner is less disturbing than popping it in the middle of the user text editor window (or game!). Important question: how your windows will be closed? It will have a close button or it will stay there messing with the user work?

c) The systray app is the way to do things today. I think it is the better approach.

HTH.
buho (A).
 
A very well developed and comprehensive answer buho! A star for you.

Robert,
As a user, I too would get very frustrated with any program that operated using the first approach. I would also vote for the third option.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Having followed this thread with interest, I agree with Stretchwickster, definitely a star for you buho - an excellent well reasoned answer.

[vampire][bat]
 
Thanks you, guys!

Very kind of yours.

buho (A).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top