Author: Jonas Bilinkevicius
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:
1 procedure THovedForm.Tegn1ButtonClick(Sender: TObject);
2 var
3 DesktopDC: HDC;
4 Rectangle: TRect;
5 pcTekst: PChar;
6 begin
7 DesktopDC := GetWindowDC(GetDesktopWindow);
8 MoveToEx(DesktopDC, 0, 0, nil);
9 LineTo(DesktopDC, Screen.Width, Screen.Height);
10 MoveToEx(DesktopDC, 0, Screen.Height, nil);
11 LineTo(DesktopDC, Screen.Width, 0);
12 pcTekst := 'Finn Tolderlund';
13 SetTextColor(DesktopDC, clBlue);
14 Rectangle.Left := 150;
15 Rectangle.Top := 250;
16 Rectangle.Right := 150 + 100;
17 Rectangle.Bottom := 250 + 100;
18 SetBkMode(DesktopDC, Transparent);
19 DrawTextEx(DesktopDC, pcTekst, -1, Rectangle, DT_CENTER or DT_NOCLIP, nil);
20 ReleaseDC(GetDesktopWindow, DesktopDC);
21 end;
|