0

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.

Community
  • 1
  • 1
  • 1
    How your screen saver implemented, exactly? – OnTheFly Apr 23 '13 at 16:53
  • 2
    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 Apr 23 '13 at 17:34
  • 2
    There's no such thing as Delphi 10 Lite. What version of Delphi are you really using? – David Heffernan Apr 23 '13 at 17:50

2 Answers2

5

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.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • I don't know what's happening, but I can't properly open the source code: difrent error messages appears. Now I will take a look to the website to see if I can find something useful. Thank you, anyway. – Laszlo Balazs Apr 23 '13 at 19:36
  • @LaszloBalazs - I confirm. As usual, the Embarcadero site is broken (The connection has timed out). – Gabriel Sep 22 '17 at 08:52
0

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.

Glenn1234
  • 2,542
  • 1
  • 16
  • 21