2006. szeptember 30., szombat

How to draw on the Desktop


Problem/Question/Abstract:

I'd like to draw on the screen, and not necessarily in the application form. Example: When the application is running but the form is minimized, I'd like to be able to draw a circle on the desktop.

Answer:

procedure THovedForm.Tegn1ButtonClick(Sender: TObject);
var
  DesktopDC: HDC;
  Rectangle: TRect;
  pcTekst: PChar;
begin
  DesktopDC := GetWindowDC(GetDesktopWindow);
  MoveToEx(DesktopDC, 0, 0, nil);
  LineTo(DesktopDC, Screen.Width, Screen.Height);
  MoveToEx(DesktopDC, 0, Screen.Height, nil);
  LineTo(DesktopDC, Screen.Width, 0);
  pcTekst := 'Finn Tolderlund';
  SetTextColor(DesktopDC, clBlue);
  Rectangle.Left := 150;
  Rectangle.Top := 250;
  Rectangle.Right := 150 + 100;
  Rectangle.Bottom := 250 + 100;
  SetBkMode(DesktopDC, Transparent);
  DrawTextEx(DesktopDC, pcTekst, -1, Rectangle, DT_CENTER or DT_NOCLIP, nil);
  ReleaseDC(GetDesktopWindow, DesktopDC);
end;

Nincsenek megjegyzések:

Megjegyzés küldése