Recent

Author Topic: Drawing to the Windows Desktop  (Read 6963 times)

M[a]nny

  • Full Member
  • ***
  • Posts: 130
  • Dreamer
Drawing to the Windows Desktop
« on: October 30, 2012, 04:07:20 pm »
Hello!

I am drawing to the windows desktop by this way:
Code: [Select]
var
   Handle: HWND;
   Dc: HDC;
   ACanvas: TCanvas;
   Text: string;
begin
   Text := 'Some text to show';

   Handle := GetDesktopWindow;
   Dc := GetWindowDC(Handle) ;
   ACanvas := TCanvas.Create;
   try
     ACanvas.Handle := DC;
     BeginPath(ACanvas.Handle) ;
     ACanvas.Font.Color := clRed;
     ACanvas.Font.Name := Text;
     ACanvas.Font.Size := 32;
     SetBkMode(ACanvas.Handle, TRANSPARENT) ;
     EndPath(ACanvas.Handle) ;

     ACanvas.TextOut( Round((Screen.Width/2)-(ACanvas.TextWidth(Text)/2)), Round((Screen.Height/2)-(ACanvas.TextHeight(Text)/2)), Text) ;
   finally
     ACanvas.Free;
   end;

It works perfectly but how can i clear that text?

I tried:
Code: [Select]
InvalidateRect(0, nil, false);
But it didn't work in all situations.
Is there any other way to clear my drawings on desktop?
Bad news: Time flies.
Good news: You are the pilot.

Don't try to be perfect, just be unique.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Drawing to the Windows Desktop
« Reply #1 on: October 30, 2012, 06:05:04 pm »
You can read the pixels behind your text before drawing. Clearing would then mean drawing the earlier read pixels back on top.

Naturally it is as silly idea as the original code  ;)  Move any window on top of your drawing and you'll make a big mess. You should draw to your own application form mainly, even if it means making it partially or fully transparent first. Old operating systems won't support it though.

M[a]nny

  • Full Member
  • ***
  • Posts: 130
  • Dreamer
Re: Drawing to the Windows Desktop
« Reply #2 on: October 30, 2012, 06:17:54 pm »
So another question. Is there any way how to make Form (and all of its content) clickable-through? Imagine transparent Form with some labels and you are able to click and make mouse actions behind the Form. Is it possible?
Bad news: Time flies.
Good news: You are the pilot.

Don't try to be perfect, just be unique.

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Drawing to the Windows Desktop
« Reply #3 on: October 30, 2012, 09:38:08 pm »
Quote
Is there any way how to make Form (and all of its content) clickable-through?

First set the AlphaBlend property of the Form to true, for an effect also set the AlphaBlendValue to say 128.

And now to make the Form clickable-through. ->
Code: [Select]
uses ..,...,LCLType;

 protected
    procedure CreateParams(var Params: TCreateParams); override; 
    ..

implementation

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT;
end;

M[a]nny

  • Full Member
  • ***
  • Posts: 130
  • Dreamer
Re: Drawing to the Windows Desktop
« Reply #4 on: November 03, 2012, 01:41:56 am »
Thank you it works ! :)
Bad news: Time flies.
Good news: You are the pilot.

Don't try to be perfect, just be unique.

M[a]nny

  • Full Member
  • ***
  • Posts: 130
  • Dreamer
Re: Drawing to the Windows Desktop
« Reply #5 on: January 11, 2013, 12:01:55 am »
You can read the pixels behind your text before drawing. Clearing would then mean drawing the earlier read pixels back on top.

Naturally it is as silly idea as the original code  ;)  Move any window on top of your drawing and you'll make a big mess. You should draw to your own application form mainly, even if it means making it partially or fully transparent first. Old operating systems won't support it though.
I tried to draw to Form but when I set background to transparent color, it was messed up when you have Windows 7 with Aero Template. It worked well with another template. I really don't know why but it seems Windows 7 has different modes of drawing depending on which template is active.

You can try it by yourself. Make Form transparent and place there Label with transparent background... or you can use TCanvas to draw text - the result is still the same.
Bad news: Time flies.
Good news: You are the pilot.

Don't try to be perfect, just be unique.

 

TinyPortal © 2005-2018