I have now created a nice screensaver based on the TI3335 screensaver.
It uses the following lines to get the desktop as a bitmap:
DesktopBitmap := TBitmap.Create;
DesktopBitmap.Width := Screen.Width;
DesktopBitmap.Height := Screen.Height;
BitBlt(DesktopBitmap.Canvas.Handle, 0, 0, Screen.Width, Screen.Height,
GetDC(GetDesktopWindow), 0, 0, SrcCopy);
However, this only gets the desktop wallpaper, not the actual desktop
as
it is when the screensaver kicks in after the timeout specified in
the
screensaver settings in the display properties. It does get the actual
wallpaper when you run the screensaver from Delphi, or when you are
testing it from Display Properties.
The lines of code above are the first lines of code in the application.
Does anyone know how can I get the actual desktop, not just the
wallpaper?
----------
This will copy the deskop to the clipboard :
keybd_event(VK_SNAPSHOT, 1, 0, 0);
and this will assign to an TImage the contents of the clipboard :
if Clipboard.HasFormat(CF_BITMAP) then
Image1.Picture.Assign(Clipboard);
you'll have to add the clipbrd unit to the uses clause.
--------
Using a value of 1 for the hardware scan code only captures the active
window.
Use 0 (zero) for the whole desktop..
--------
You've got that wrong David.
keybd_event(VK_SNAPSHOT, 1, 0, 0);
captures the full screen and
keybd_event(VK_SNAPSHOT, 0, 0, 0);
captures only the active screen.
--------
Then the Win32 Help dated 5/8/97 is wrong..
--------
That is not true! The Win32 help file has this backwards: value
1
gives the entire screen, 0 gives the active window.
It might be better to use CreateDC("DISPLAY", NULL, NULL, NULL)
to get a device
context of the screen, then give that DC to a TBitmap. keybd_event
fools with
the clipboard, which you don't want to do without an explicit user
command. The
user won't like his carefully prepared clipboard image data without
warning.
--------
I agree with Rory about messing with the clipboard so here is an other
alternative.....
function TMainForm.GetDeskTopImageFile : String;
var
Bitmap : TBitmap;
DeskTopCanvas : TCanvas;
begin
Bitmap := TBitmap.Create;
DeskTopCanvas := TCanvas.Create;
Try
Try
DeskTopCanvas.Handle :=
GetDC(Hwnd_Desktop);
Bitmap.Width := Screen.Width;
Bitmap.Height := Screen.Height;
Bitmap.Canvas.CopyRect(Bitmap.Canvas.ClipRect,DesktopCanvas,DesktopCanvas.ClipRect);
DeleteFile('C:\Desktop.bmp');
Bitmap.SaveToFile('C:\Desktop.bmp');
ReleaseDC(Hwnd_Desktop,DeskTopCanvas.Handle);
Finally
Bitmap.Free;
DesktopCanvas.Free;
end;
Except
end;
end;
Here I'm saving the desktop image to a disk file but onne could pretty much do what one wants with it once it's in a bimap object.