Recent

Author Topic: Transparent Canvas Desktop bug  (Read 3025 times)

M[a]nny

  • Full Member
  • ***
  • Posts: 130
  • Dreamer
Transparent Canvas Desktop bug
« on: November 03, 2012, 01:51:56 am »
Small application that draws text with transparent background to desktop and after some time it dissapears.
Make an application with one button and make OnClick event:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
   Dc: HDC;
   ACanvas: TCanvas;
begin
   Handle := GetDesktopWindow;
   Dc := GetWindowDC(Handle) ;
   ACanvas := TCanvas.Create;
   try
     ACanvas.Handle := DC;
     BeginPath(ACanvas.Handle);

     ACanvas.Font.Color := clGreen;
     ACanvas.Font.Name := 'Sample text';
     ACanvas.Font.Size := 20;

     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
     ReleaseDC(Handle, ACanvas.Handle) ;
     ACanvas.Free;
   end;

   Sleep(500);
   InvalidateRect(0, nil, false);
end; 

Now, run the application. If you have Windows 7, it will not work properly with AERO template. Let's see what it does with and without AERO theme.

With AERO: http://img22.imageshack.us/img22/7549/blamb.png
And without AERO (any other theme on Windows 7): http://img203.imageshack.us/img203/1192/beznzvupi.png

How to fix this?
Bad news: Time flies.
Good news: You are the pilot.

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

 

TinyPortal © 2005-2018