• 0

C# Screen saver?


Question

Hi,

I'm trying to develop a program that shows the user's current screen saver in it,just like the screen saver tab in the display menu.I'm using c# but I don't know how to do it.

Please help me.Thanks in advance ;) .

Link to comment
Share on other sites

Recommended Posts

  • 0

(using Microsoft.Win32)

string screenSaver

try
{
    screenSaver = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop").GetValue("SCRNSAVE.EXE").ToString();
}
catch
{
    // no screensaver selected
}

This gets the filename of the current screensaver. I don't know how to get the 'friendly' name of the screensaver, though.

Link to comment
Share on other sites

  • 0

Ok,cool :cool:

Thanks.

But I want to know also how to show it in a small area like in the Screen Saver tab which is in the Display menu.How can I do it?

Edited by yyy
Link to comment
Share on other sites

  • 0

Ok, now I understand what you are trying to do. I'm not sure how to do it, though. It's probably quite complicated.

You could execute the screensaver using the System.Diagnostics.Process class but you will have to redirect the ouput somehow (maybe it requires unmanaged code?).

Link to comment
Share on other sites

  • 0

Yes,exactly.Actually I think there's another way to activate the screen saver but that doesn't allow me to show it in a small area.If I could somehow shrink the size of the screen saver to a small square inside my application it can be great :yes: But how can I do this?

Link to comment
Share on other sites

  • 0

Oh, no :no: That's not what I wanted - it only shows how to make a screen saver open in preview mode, but I want it to show any screen saver as a preview. Is there a way I can activate a screensaver in preview mode and show it in my application ?

Link to comment
Share on other sites

  • 0

Sure, you'll have to create a picturebox or some control to use for the surface, and then just do Process.start("screensaver", new string[]{"/p", pictureBox1.Handle.ToString()}); so basicly just pass /p for preview mode, and then pass a handle to a control.

Dan

Link to comment
Share on other sites

  • 0

But the structure of the start method is start(string,string); I tried to do what you wrote but it tells me: "Cannot implicity convert string[] to string". How can I pass a handle to a picturebox? Is there another way to do it?

Link to comment
Share on other sites

  • 0

Are you doing this? (from that page I linked to)

Note the string[] cmdList. It splits off of a space. Also note that if the cmdList[1] is "/p" then cmdList[2] is the handle to the parent.

static void Main()

{

       string[] cmdList = Environment.CommandLine.Split(' ');



       // First command-line param is the exe name, second param is the mode



       if (cmdList.Length >= 2) {

              if (cmdList[1].IndexOf("/c") >= 0) {        // Configuration mode

                     Application.Run(new OptionsForm());

                     return;

              }



              parentHwnd = IntPtr.Zero;

                          

              if (cmdList[1] == "/p") {               // Preview mode

                     previewMode = true;



                     // Handle to preview dialog box is next command-line param

                     parentHwnd = (IntPtr) uint.Parse(cmdList[2]);

              }

       }



       Application.Run(new ScreenSaverForm());

}

Link to comment
Share on other sites

  • 0

The site you gave me shows how to create a new custom screen saver. I want to be able to show the current user's screen saver inside my application. The example you give refers only to a real screen saver. It doesn't show how to show any screen saver in preview mode. Do you know how to do that ?

Link to comment
Share on other sites

  • 0

I think I can figure it out.

[edit] or, at least I can tell you if you can do it or not.(without having to write a C-Dll) :D

Edited by weenur
Link to comment
Share on other sites

  • 0

A dll written in c

I have tried playing around with stuff in screen-savers, i don't know how windows gets the name, i have found string resources in the scr's resources section, but they are only used when the screen-savers files are in the 8.3 format (i think, it's been a while, it got me fed up so i stopped)

Link to comment
Share on other sites

  • 0

The problem with doing this is that a screen saver is an exe, not a dynamic linking library(dll). You can't really use platforrm invoke with an exe. You have to invoke the ScreenSaverProc of the scr file, passing in the WM_CREATE message along with the handle to the picturebox that you want to have it previewed in.

If someone wrote a dll that exported a screensaver loader function, then you could do it easily... I may just do that as I'm in project burn out mode at the moment. I doubt it would take that long.(famous last words)

Link to comment
Share on other sites

  • 0
Oh, thanks. What do you mean how windows gets the name ? I know how to get the current screen saver :)

The name that appears in the combo-box in the display properties window.

Also, i think exe files can have functions exported, i think i can remember doing it with a linker override thing in vb6

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.