Author: Jonas Bilinkevicius
How to capture the Desktop and shade it
Answer:
This unit takes the Desktop and makes it look like it does when you select Shutdown
from the Start menu. You need a TForm with BorderStyle set to bsNone and a TImage
component set to alClient.
1 procedure TForm1.FormShow(Sender: TObject);
2
3 procedure Veil;
4 var
5 BrushBmp: TBitmap;
6 X, Y: Integer;
7 begin
8 BrushBmp := TBitmap.Create;
9 with BrushBmp do
10 begin
11 Width := 8;
12 Height := 8;
13 for X := 0 to 7 do
14 for Y := 0 to 7 do
15 if Odd(X + Y) then
16 Canvas.Pixels[X, Y] := clWhite
17 else
18 Canvas.Pixels[X, Y] := clBlack;
19 end;
20 Image1.Canvas.Brush.Bitmap := BrushBmp;
21 {The PatBlt function paints the given rectangle using the brush that is
22 currently selected into the specified device context.
23 The brush color and the surface color(s) are combined by using the
24 given raster operation.}
25 PatBlt(Image1.Canvas.Handle, 0, 0, Image1.Width, Image1.Height, $000A0329);
26 BrushBmp.Free;
27 end;
28
29 var
30 ScreenDC: HDC;
31 tmpRect: TRect;
32 tmpBitmap: TBitmap;
33 begin
34 {Set the form bounds}
35 SetBounds(0, 0, Screen.Width, Screen.Height);
36 {get our screen device context}
37 ScreenDC := GetDC(0);
38 {create our bitmap}
39 tmpBitmap := TBitmap.Create;
40 {get the screen area}
41 tmpRect := Rect(0, 0, Screen.Width, Screen.Height);
42 {set the bitmap to the screen area}
43 tmpBitmap.Width := tmpRect.Right - tmpRect.Left;
44 tmpBitmap.Height := tmpRect.Bottom - tmpRect.Top;
45 try
46 {transfer the screen pixels to the bitmap}
47 BitBlt(tmpBitmap.Canvas.Handle, tmpRect.Left, tmpRect.Top, tmpBitmap.Width,
48 tmpBitmap.Height, ScreenDC, tmpRect.Left, tmpRect.Top, SRCCOPY);
49 {assign the bitmap image to our TImage}
50 Image1.Picture.Bitmap.Assign(tmpBitmap);
51 finally
52 {free our bitmap}
53 tmpBitmap.Free;
54 {release our screen device context}
55 ReleaseDC(0, ScreenDC);
56 end;
57 Veil;
58 end;
59
60 end.
|