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.

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

829 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