Delphi Programming question

Posted on 1997-07-09
Last Modified: 2010-04-06
Question by:mobius
  • 3
  • 2

Expert Comment

ID: 1338504
Hi Catherine,

Here is a (short) explanation:

Screensavers are executed by Windows in two ways: either when an interval of inactivity causes Windows to execute the screensaver, or when it is being configured in Control Panel. In Windows 95, screensavers have four modes of execution and these are selected by command line parameters:

1. Preview mode.

When you select the saver in Control Panel, Windows sends two parameters, /p HWND, to select preview mode and to pass the handle of the preview window.

2. Configuration mode.

When you click Settings, Windows sends a parameter, /c, to select configuration mode. The saver responds by presenting a configuration dialogue.

3. Password mode.

When you click to change the password, Windows sends two parameters, /a HWND, to select password mode and to pass the handle of the parent window for your password dialogue.

4. Start mode.

When you click Preview, or when the saver is called for real, Windows sends a parameter, /s, to select start mode.

The application should check the command line parameters to see whether it should draw in the preview window or present a configuration dialogue. Screensaver security is treated in different ways by Windows 95 and Windows NT. Under Windows 95, most screensavers call the Windows Master Password Router. This is a DLL called MPR.DLL which exports password functions like PwdChangePassword. They are usually called via another DLL, PASSWORD.CPL, which works as an extension to the Control Panel. Neither of these libraries are fully documented in the Windows SDK, but some have worked out how to use them. The alternative is to implement your own password checking and throw up your own password dialogue when the saver is called in password mode. Windows NT is different. Passwords for NT screensavers are the same as those used for logging on to Windows. The Control Panel marks a registry entry to indicate a secure screensaver:
Finally, there is the matter of the description line. Confusingly, Microsoft has devised three ways of identifying this. Originally, it was the module description entry, which had to be of the form
“SCRNSAVE : My Description.”
Under Windows 95 and NT it became a resource string with an ID of 1 — and yes, Delphi can use standard Windows resources. This is the documented way; but actually, Windows 95 does not use it. It simply uses the long filename, less the .SCR extension. By the way, Windows will find any screensaver, identified by a .SCR extension, in the Windows or System folders, so at least installation is easy.

I hope this will help you and that your problems will be solved !

See ya,


Author Comment

ID: 1338505
Thanks Cyberwolf.

I'm not rejecting your reply because I don't like it (which I do, I think it's very good indeed!), but simply to keep the question 'open'. BTW, how long is the long explanation?

I didn't know about the other parameter options, so now I can build them into the main form, but as my savers work by having a full-screen-size form on which everything is drawn, how can this be re-directed to the handle of the preview window so the output appears there? I admit this isn too great an issue for me as I'm more interested in getting the savers to work properly to begin with, but it would be nice

My final question: what is the resource string you're referring to in the last paragraph and where is it located in the .dpr/.pas?



Expert Comment

ID: 1338506
There is a good example at:

It might help.

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Accepted Solution

CyberWolf earned 0 total points
ID: 1338507
Hi Catherine,

This time a very very short explanation:

To use the hwnd parameter for the preview, I recommend not to use a TForm. It's a large dcu (150 K) entirely linked to your executable. If you use the windows API, everything you need will be done with less than 15 K. (Instead of 150K !!)

Using the windows API seems a bit difficult in the beginning, but I can tell you that it's easier than it sounds !

Of course, you can use some trick to overcome this problem. You can simply paint a static bitmap on the small preview window. (Just retrieve the hdc and associate it with a TCanvas handle. Then simply draw a bitmap on it as you usualy do !) The use of a TForm for the full screen window will no longer be a problem.

Ok, now your question about the resource string.

Each delphi file is linked with a file that has the same name as the original but with the extension turned into 'res'. (Ex.:main.pas main.res) 'Res' stands for resource. However, these resource files are already compiled. (They can hold bitmaps,videos,version information,... and also strings !)

You can also create your own resource files. (.rc files that you compile with brcc32.exe located in the bin dir) You can use a simple text editor such as notepad to create them. Here is an example of what you should need:


     1,"Replace this in order to get a decent name for your screensaver"

generating myscreensavercustomresource.res --> brcc32 -r myscreensavercustomresource.rc

linking with delphi project --> add the following line to your dpr : {$R myscreensavercustomresource.res}

(I don't want you to know how the long explanation can be ... so I won't cover this more in detail, but if you want some additional information on how to write rc files, simply ask and I'll be there for you ...)

See ya,



Author Comment

ID: 1338508
Thanks Cyberwolf.
As you probably realised I'm still quite new to all this, and yes, everything I've done so far is on a TForm. The resource string description has gone straight over my head at the moment, but it will probably make sense once I've tried it.
I'm still having trouble with the /c option, as even though it's parsed correctly and works as a parameter from file manager to display the saver's controls, as soon as the .scr file is accessed by desktop\screensavers\configure, all that happens is the screen blinks. There's obviously a fundamental flaw in my program somewhere, as everyone else's work OK, but you've been very helpful and I don't want to impose too much.
Thanks again for the help,

Expert Comment

ID: 1338509
Hi Catherine,

It was a pleasure to me to help you. If you want, I have some examples of screensavers and a help file which explains screen savers in detail. I will send them to your mailbox if you give me your e-mail address. If you want I can also explain you how to deal with resources more in detail ?

See ya,

CyberWolf (

P.S.:Please, send me a copy of your screensaver when it's finished !

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question