koger
asked on
Screensaver preview:
How do I create a preview of my screensaver in the screensaver properties, I need some samples that aren't to hard to understand.
When previewing, The preview window calls your program (with SCR extension) with two commandline parameters the first is a "p" and the second one is the handle of the preview window.
I'll paste here some code I used for a screensaver I made.
-----------------begin of code------------
unit Unit_InitProcs;
interface
uses Windows, extctrls, Classes, Graphics, SysUtils, Messages;
procedure ExecPreview;
var
SaverMode: Integer; {one of the consts above}
ParamHandle: THandle; {the Handle passed on command line as parameter}
ConfigParent: hWnd; {the parent window for config-dialog}
PrevRect: TRect;
MyBmp: TBitmap;
PreviewCanvas : TCanvas;
R: TRect;
implementation
{this is the window-proc for the preview window, it only implements 3 messages}
function MyWndProc (Wnd : HWnd; Msg : Integer; wParam : Word; lParam : Integer) : Integer; far; stdcall;
var
x,y,cx,cy: Integer;
begin {I don't know if it is ok to quit on WM_CLOSE, but I had no problems doing so}
if (Msg = WM_DESTROY) or (Msg = WM_CLOSE) then
PostMessage (Wnd, WM_QUIT, 0, 0);
if Msg = WM_PAINT then begin
x:=Round((PrevRect.Right-R .Right)/2) ;
y:=Round((PrevRect.Bottom- R.Bottom)/ 2);
cx:=x + R.Right-R.Left;
cy:=y + R.Bottom-R.Top;
PreviewCanvas.CopyRect(Rec t(x,y,cx,c y),MyBmp.C anvas,R);
end;
DefWindowProc (Wnd, Msg, wParam, lParam);
end;
{This executes the preview window,
and goes in a message loop to keep it running}
procedure ExecPreview;
var
WndClass : TWndClass;
Atom : TAtom;
DC : hDC;
MyWnd : hWnd;
Msg : TMsg;
begin
{create a new window class}
with WndClass do begin
style := CS_PARENTDC;
lpfnWndProc := @MyWndProc;
cbClsExtra := 0;
cbWndExtra := 0;
hIcon := 0;
hCursor := 0;
hbrBackground := 0;
lpszMenuName := nil;
lpszClassName := 'Delphi2ScreenSaverPreview ';
end;
WndClass.hInstance := hInstance;
Atom := Windows.RegisterClass (WndClass);
{get some info on parent window}
GetWindowRect (ParamHandle, PrevRect);
PrevRect.Right := PrevRect.Right - PrevRect.Left;
PrevRect.Bottom := PrevRect.Bottom - PrevREct.Top;
PrevRect.Left := 0;
PrevRect.Top := 0;
{and now create the window as child of the window given in ParamHandle}
MyWnd := CreateWindow ('Delphi2ScreenSaverPrevie w', 'FunSaver',
WS_CHILD or WS_DISABLED or WS_VISIBLE, 0, 0, PrevRect.Right,
PrevRect.Bottom, ParamHandle, 0, hInstance, nil);
{get the DC for the new created window}
DC := GetDC (MyWnd);
PreviewCanvas := TCanvas.Create;
PreviewCanvas.Handle := DC;
MyBmp:=TBitmap.Create;
MyBmp.LoadFromResourceName (hInstance ,'INQUILIN O');
R:=Rect(0,0,MyBmp.Width,My Bmp.Height );
{and now do the message loop, I think I cannot use any predifined loop here}
while GetMessage(Msg, 0, 0, 0) do begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
MyBmp.Free;
PreviewCanvas.Free;
ReleaseDC(0,DC);
{I don't care about other resources here, as my app terminates immediately and
Win95 cleans up after me}
end;
----------------end of code-------------
This block of code makes use of some unusual-in-Delphi functions and structures but it's not so hard to understand. In fact, we only create a new window and we make it a Child of the preview dialog box. Our window doesn't have a border and this is the window we will use to draw our screensaver.
Just tell me when you encounter any problem or if you have any question.
Trillo
I'll paste here some code I used for a screensaver I made.
-----------------begin of code------------
unit Unit_InitProcs;
interface
uses Windows, extctrls, Classes, Graphics, SysUtils, Messages;
procedure ExecPreview;
var
SaverMode: Integer; {one of the consts above}
ParamHandle: THandle; {the Handle passed on command line as parameter}
ConfigParent: hWnd; {the parent window for config-dialog}
PrevRect: TRect;
MyBmp: TBitmap;
PreviewCanvas : TCanvas;
R: TRect;
implementation
{this is the window-proc for the preview window, it only implements 3 messages}
function MyWndProc (Wnd : HWnd; Msg : Integer; wParam : Word; lParam : Integer) : Integer; far; stdcall;
var
x,y,cx,cy: Integer;
begin {I don't know if it is ok to quit on WM_CLOSE, but I had no problems doing so}
if (Msg = WM_DESTROY) or (Msg = WM_CLOSE) then
PostMessage (Wnd, WM_QUIT, 0, 0);
if Msg = WM_PAINT then begin
x:=Round((PrevRect.Right-R
y:=Round((PrevRect.Bottom-
cx:=x + R.Right-R.Left;
cy:=y + R.Bottom-R.Top;
PreviewCanvas.CopyRect(Rec
end;
DefWindowProc (Wnd, Msg, wParam, lParam);
end;
{This executes the preview window,
and goes in a message loop to keep it running}
procedure ExecPreview;
var
WndClass : TWndClass;
Atom : TAtom;
DC : hDC;
MyWnd : hWnd;
Msg : TMsg;
begin
{create a new window class}
with WndClass do begin
style := CS_PARENTDC;
lpfnWndProc := @MyWndProc;
cbClsExtra := 0;
cbWndExtra := 0;
hIcon := 0;
hCursor := 0;
hbrBackground := 0;
lpszMenuName := nil;
lpszClassName := 'Delphi2ScreenSaverPreview
end;
WndClass.hInstance := hInstance;
Atom := Windows.RegisterClass (WndClass);
{get some info on parent window}
GetWindowRect (ParamHandle, PrevRect);
PrevRect.Right := PrevRect.Right - PrevRect.Left;
PrevRect.Bottom := PrevRect.Bottom - PrevREct.Top;
PrevRect.Left := 0;
PrevRect.Top := 0;
{and now create the window as child of the window given in ParamHandle}
MyWnd := CreateWindow ('Delphi2ScreenSaverPrevie
WS_CHILD or WS_DISABLED or WS_VISIBLE, 0, 0, PrevRect.Right,
PrevRect.Bottom, ParamHandle, 0, hInstance, nil);
{get the DC for the new created window}
DC := GetDC (MyWnd);
PreviewCanvas := TCanvas.Create;
PreviewCanvas.Handle := DC;
MyBmp:=TBitmap.Create;
MyBmp.LoadFromResourceName
R:=Rect(0,0,MyBmp.Width,My
{and now do the message loop, I think I cannot use any predifined loop here}
while GetMessage(Msg, 0, 0, 0) do begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
MyBmp.Free;
PreviewCanvas.Free;
ReleaseDC(0,DC);
{I don't care about other resources here, as my app terminates immediately and
Win95 cleans up after me}
end;
----------------end of code-------------
This block of code makes use of some unusual-in-Delphi functions and structures but it's not so hard to understand. In fact, we only create a new window and we make it a Child of the preview dialog box. Our window doesn't have a border and this is the window we will use to draw our screensaver.
Just tell me when you encounter any problem or if you have any question.
Trillo
ASKER
I have got this sample from somewhere (can't remember where) but I still don't get it, could you perhaps create a quick sample that would e.g. display an image.
Supose you want to preview a screen saver in a panel named panel1:
var
s:string;
begin
s:='c:\windows\system\Your ScrName.sc r /P '+trim(IntToStr(panel1.han dle));
WinExec(pchar(s),0);
end;
var
s:string;
begin
s:='c:\windows\system\Your
WinExec(pchar(s),0);
end;
ASKER
This is not what I'm looking for I don't have a preview in my screensaver.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
just what I needed
I don't know how to do a stamp preview. But a full-screen preview is very easy:
var si : TStartupInfo;
pi : TProcessInformation;
begin
ZeroMemory(@si,sizeOf(si))
if CreateProcess(nil,'c:\wind
CloseHandle(pi.hThread); CloseHandle(pi.hProcess); // Never forget to close handles...
end;
Regards, Madshi.