0
votes

I've created a screen saver in Delphi 10 Lite, using diffrent descriptions about this question, available on the web. Now, the screen saver works well, one thing is missing: a good working preview on the Screen Saver Settings dialog box. How can it be created? I've read this description: how to make a screen saver preview in Delphi? but I'd like something more specific, maybe with an example. I'm using Windows 7 Ultimate SP1. Thanks.

2
How your screen saver implemented, exactly?OnTheFly
What is unclear about the instructions on that other question? You have to implement the /p command-line argument to accept an HWND as input. If provided, you simply render your screensaver normally using that HWND as the parent window for your screensaver's UI, otherwise you create your own full-screen HWND as the parent window instead.Remy Lebeau
There's no such thing as Delphi 10 Lite. What version of Delphi are you really using?David Heffernan

2 Answers

5
votes

The Embarcadero site, provides a fully functional screen saver sample, which includes the normal execution (run), preview, password setting and so on. Try this article Random Images Screen Saver - a complete screen saver example, the source code can be downloaded from here.

0
votes

Here's what I did in my little scrub screen saver test (done to see how one works more than it be polished):

WinHandle is the window id passed during the /P switch. I rigged things (the screen saver just puts up a defined text in different colors with a defined delay between them) for the screen saver to act on a window handle so I didn't have to duplicate the screen saver code itself. SS_Init initializes things for the screen saver, SS_Start does one step of it, SS_End wraps things up.

if program_state = Preview then  // code before indicates /P was passed
  begin
    { spindle off messages until window is visible }
    while not IsWindowVisible(WinHandle) do
      Application.ProcessMessages;
    { initialize and do screen saver draw }
    start_time := WinMSSinceStart; // timeGetTime
    SS_Init(WinHandle);
    while IsWindowVisible(Winhandle) do
      begin
        if (WinMSSinceStart - Start_Time) >= config_rec.Delay then
          begin
             SS_Start(WinHandle);
             start_time := WinMSSinceStart;
          end;
        Application.ProcessMessages;
        sleep(10);
      end;
    SS_End(Winhandle);
end;

Here's how you set up the TCanvas to draw on the window handle that is passed (this is in SS_Init (but not the whole thing). MyCanvas is a property I have defined in line with this code:

  { get window dimensions and set up TCanvas }
  GetClientRect(WinHandle, WinRect);
  MyCanvas := TCanvas.Create;
  MyCanvas.Handle := GetDC(Winhandle);

Then when you're done (this is my whole SS_End function):

  ReleaseDC(WinHandle, MyCanvas.Handle);
  MyCanvas.Free;

Hope that helps out.