I am trying to adapt a sample screen saver project I found so it just displays an image of the desktop (aim is to get any image)
The original took a snapshot of the desktop and used this to create a moving 'spot' but had no commenting at all!!.
I have tried to remove the 'spot' stuff and get just the desktop image but just get a blank screen.
This is my revised code there is more to it than this but I think the problem lies somewhere in here.
The project file seems to make a copy of the desktop into the variable desktopbitmap and this seems to be loaded into the main image at formactivate, but I must be missing something (simple)?
Project source
Main file
Steve: Delphi a feersum engin indeed.
The original took a snapshot of the desktop and used this to create a moving 'spot' but had no commenting at all!!.
I have tried to remove the 'spot' stuff and get just the desktop image but just get a blank screen.
This is my revised code there is more to it than this but I think the problem lies somewhere in here.
The project file seems to make a copy of the desktop into the variable desktopbitmap and this seems to be loaded into the main image at formactivate, but I must be missing something (simple)?
Project source
Code:
program Simple;
uses
Forms, SysUtils, Windows, Graphics, Classes,
Ssave in 'SSave.pas' {Scrn},
Ssetup in 'SSetup.pas' {Setup},
Globals in 'Globals.pas';
{$E SCR}
{$R *.RES}
var
MySem : THandle;
Arg1, Arg2 : String;
DemoWnd : HWnd;
MyRect : TRect;
MyCanvas : TCanvas;
x, y,
dx, dy : Integer;
MyBkgBitmap,
InMemBitmap : TBitmap;
ScrWidth,
ScrHeight : Integer;
begin
Arg1 := UpperCase(ParamStr(1));
Arg2 := UpperCase(ParamStr(2));
if (Copy(Arg1,1,2) = '/P') or (Copy(Arg1,1,2) = '-P') or
(Copy(Arg1,1,1) = 'P') then
SSMode := ssPreview;
if (Copy(Arg1,1,2) = '/C') or (Copy(Arg1,1,2) = '-C') or
(Copy(Arg1,1,1) = 'C') or (Arg1 = '') then
SSMode := ssConfig;
MySem := CreateSemaphore(nil,0,1,'SimpleSaverSemaphore');
if ((MySem <> 0) and (GetLastError = ERROR_ALREADY_EXISTS)) then
begin
CloseHandle(MySem);
Halt;
end;
Application.Initialize;
if SSMode = ssPreview then
begin
DemoWnd := StrToInt(Arg2);
while not IsWindowVisible(DemoWnd) do
Application.ProcessMessages;
GetWindowRect(DemoWnd,MyRect);
ScrWidth := MyRect.Right-MyRect.Left+1;
ScrHeight := MyRect.Bottom-MyRect.Top+1;
MyRect := Rect(0,0,ScrWidth-1,ScrHeight-1);
MyCanvas := TCanvas.Create;
MyCanvas.Handle := GetDC(DemoWnd);
MyCanvas.Pen.Color := clWhite;
x := (ScrWidth div 2)-16;
y := (ScrHeight div 2)-16;
dx := 1;
dy := 1;
MyBkgBitmap := TBitmap.Create;
with MyBkgBitmap do
begin
Width := ScrWidth;
Height := ScrHeight;
end;
MyBkgBitmap.Canvas.FillRect(Rect(0,0,ScrWidth-1,ScrHeight-1));
InMemBitmap := TBitmap.Create;
with InMemBitmap do
begin
Width := ScrWidth;
Height := ScrHeight;
end;
while IsWindowVisible(DemoWnd) do
begin
InMemBitmap.Canvas.CopyRect(MyRect,MyBkgBitmap.Canvas,MyRect);
InMemBitmap.Canvas.Draw(x,y,Application.Icon);
MyCanvas.CopyRect(MyRect,InMemBitmap.Canvas,MyRect);
Sleep(10);
Application.ProcessMessages;
if (x = 0) or (x = (ScrWidth-33)) then
dx := -dx;
if (y = 0) or (y = (ScrHeight-33)) then
dy := -dy;
x := x + dx;
y := y+dy;
end;
MyBkgBitmap.Free;
InMemBitmap.Free;
MyCanvas.Free;
CloseHandle(MySem);
Halt;
end;
DesktopBitmap := TBitmap.Create;
with DesktopBitmap do
begin
Width := Screen.Width;
Height := Screen.Height;
end;
// copy desktop into desktopbitmap
BitBlt(DesktopBitmap.Canvas.Handle,0,0,Screen.Width,Screen.Height,
GetDC(GetDesktopWindow),0,0,SrcCopy);
if SSMode = ssConfig then
begin
Application.CreateForm(TSetup, Setup);
end
else
Application.CreateForm(TScrn,Scrn);
Application.Run;
DesktopBitmap.Free;
CloseHandle(MySem);
end.
Code:
procedure TScrn.FormActivate(Sender: TObject);
var
Dummy : Boolean;
begin
if LoadingApp then
begin
LoadingApp := False;
Scrn.Top := 0;
Scrn.Left := 0;
Scrn.Width := Screen.Width;
Scrn.Height := Screen.Height;
// Image becomes desktop snapshot??
Scrn.Image1.Picture.Bitmap := DesktopBitmap;
Mouse.X := -1;
Mouse.Y := -1;
Application.OnIdle := Trigger;
SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE + SWP_NOMOVE);
SystemParametersInfo(SPI_SCREENSAVERRUNNING,1,@Dummy,0);
CursorOff;
Scrn.Visible := True;
SetCapture(Scrn.Handle);
end;
end;
Steve: Delphi a feersum engin indeed.