• 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
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

Ok, the screensaver's name is less important to me. If any one else konw a better way to do it please tell me.

Link to comment
Share on other sites

  • 0

hijack time. anyone know how to change the context menu links so that when you right click on the desktop and select properties. instead of it pointing to the control panel program it would launch another executable or cpl (but i think cpl is just arenamed exe)

Link to comment
Share on other sites

  • 0
hijack time. anyone know how to change the context menu links so that when you right click on the desktop and select properties. instead of it pointing to the control panel program it would launch another executable or cpl (but i think cpl is just arenamed exe)

a cpl file is a dll file with a function called cpl exported. it takes care of telling windows it's name, description and icon, and launching it when it's double-clicked.

Link to comment
Share on other sites

  • 0

This is quite stupid... a screen saver should support the /p <hwnd> command line. I've tried everything I could think of to get this to work, including the C-dll to no avail. Maybe there is some obscure/unknown issue with .NET interop and screensavers, though I wouldn't think so.

Link to comment
Share on other sites

  • 0

Hello everyone

I am a chinese and I slept away my english lessons for all time that i can't understand English sentence exactly

But could that code can helps you?

using System.Drawing;
.
.
.

IDataObject d=Clipboard.GetDataObject();
if(d.GetDataPresent(DataFormats.Bitmap))
{
Bitmap B=(Bitmap)d.GetData(DataFormats.Bitmap);
}

Now you get a bitmap-type object " B" which contains a picture, namely,The Sreansaver.

Link to comment
Share on other sites

  • 0
But how does it get the screen saver ?

Use Print Screen Button!

That's easy.But you must know API Program.

Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Then you can press that button "Print Screen Sys Rq"

Call keybd_event(VK_SNAPSHOT, 1, 0, 0)
DoEvents//Must do this or Windows will do nothing on Runtime

Then that button will be pressed really!

This is VB.net style.

You can write it in C# like:

using System.Runtime.InteropServices;
.
.
.
.
[DllImport("user32.dll")]
public static extern void keybd_event (Byte bVk, Byte bScan , Long dwFlags ?, Long dwExtraInfo )

then use that method to press any Keys like "Print Sreen"

Oh!

I forgot it!

VK_SNAPSHOT is a Byte '&H2C'

It's the number of the Key(Print Screen)

Edited by nkorls
Link to comment
Share on other sites

  • 0

But I want to show the screen saver in preview mode? Why would I need to press the print screen key ? I want it to act like in the screenshot. The screen saver is shown inside the computer image. I want to do the same.

post-47-1093346893.png

Link to comment
Share on other sites

  • 0

Oh my Muh!!

I am wrong in the begining..

it looks as I had better study English hard

you can use this

PostMessage(WM_SYSCOMMAND,SC_SCREENSAVE,0);

to act current ScreenSaver

I think you want to get current Screen picture at the begining.

faint~

this is the code;

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
 ? ?Private Const HWND_BROADCAST = &amp;HFFFF&amp;
 ? ?Private Const WM_SYSCOMMAND = &amp;H112
 ? ?Private Const SC_SCREENSAVE = &amp;HF140&amp;

 ? ?Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 ? ? ? ?SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_SCREENSAVE, 0)
 ? ?End Sub

I use VB more than C#.

So this code is in VB style.

Edited by nkorls
Link to comment
Share on other sites

  • 0

But this just activates the screensaver. I want to show it as a preview. Like in the screenshot. I don't want to show the screen saver on the full screen but just in a picture box. I want to show the screensaver in preview mode inside the picture box. How can I do it? Please try to write in c#. Otherwise I have to use a special program to conver it to c# :no:

Link to comment
Share on other sites

  • 0
But this just activates the screensaver. I want to show it as a preview. Like in the screenshot. I don't want to show the screen saver on the full screen but just in a picture box. I want to show the screensaver in preview mode inside the picture box. How can I do it? Please try to write in c#. Otherwise I have to use a special program to conver it to c#  :no:

So you can use Command Line to run the ScreenSaveer file like this

c:\winnt\system32\mysc.msc /p <HWND>

<HWND> is the window to display the Preview

How to get the HWND?

You can Use this API:

?[DllImport("user32.dll")]
 ?public static extern int FindWindow(String lpClassName,String lpWindowName);

lpClassName is the name of the class

lpWindowName is the name of the title bar

and run it like

System.Diagnostics.Process.Start(@"C:\winnt\system32\ss3dfo.scr /p "+FindWindow(classname,windownname).toString());

Edited by nkorls
Link to comment
Share on other sites

  • 0
If I want to show the screensaver in a picturebox, can't I use pictureBox1.Handle.ToString() to find the HWND ?

HWND Must be a handle of a Window

Someone told me that in MSDN.

and the preview window is the Child-Window of the HWND-window.

That is a Chinese article,I am not a translator,I hope you can understand those word

Edited by nkorls
Link to comment
Share on other sites

  • 0

OK, so if I have a picture box called picturebox1 - how do I show the screensaver in it? Do I need its HWND ? How can I get it?

And what do I have to write in classname and windownname?

Edited by yyy
Link to comment
Share on other sites

  • 0
OK, so if I have a picture box called picturebox1 - How do I find its HWND?

And what do I have to write in classname and windownname?

Write it like : FindWindow(null, "Form1")

That is.

I don't remember how to find the handle of a control,I am in my Friend's home and there is No .net Framework on her computer now,So you can search the result on google.com or MSDN yourself.

Time to bed now,bye-bye

By the way: how about my English expression?

I Join this English forum is for studing English mostly.

Link to comment
Share on other sites

  • 0

Im working on it now, if i can work out what format windows sends the command arguments in i might be able to make it work

Edit: I wrote a program a while ago that only shows the command line arguments passed to it (to work out i problem i was having with Microangelo Studio, fixed now) it says that windows is passing "/p 4720014" (on my system anyway) for the preview window

Edit 2: i told my test program to load my test app (or scr) it told me i was passing /S to it, but this is my code

Process.Start("C:\Windows\system32\Thingy.scr", "/p " &amp; Me.Handle.ToString)

Edited by The_Decryptor
Link to comment
Share on other sites

  • 0

Thanks you very much for helping me :laugh: I really appreciate this :yes:

I hope you can find the solution. Although AFAIK I need to find the handle of the picturebox.

Link to comment
Share on other sites

  • 0

The problem with your approach to the window handle is that .net controls are separate, hidden windows, so you can't use this.Handle. I had the same problem trying to use shell_notifyicon. Use this to get the window handle of your picturebox:

Type t = yourPictureBox.GetType();

IntPtr window = ((NativeWindow)t.GetField("window",System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(yourPictureBox)).Handle;

That should get you your handle.

Link to comment
Share on other sites

  • 0

I tried this:

Type t = pictureBox1.GetType();
 IntPtr window = ((NativeWindow)t.GetField("window",System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(pictureBox1)).Handle;


 System.Diagnostics.Process.Start(sc , "/p " + window.ToString());

sc is the path to the screen saver.

But it still shows it in full mode.

Link to comment
Share on other sites

  • 0

I just used Spy++ to get some window handles and ran a screen saver from the command line and it worked. I had a screen saver running as my desktop back ground. lol! I'll see what else works.

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.