• 0

C# Screen saver?


Question

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.

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

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

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

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

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

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

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

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

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

    • No registered users viewing this page.
  • Posts

    • I totally disagree. Very little good comes out of governments all around the world manipulating everything they can and usually the people are not the benefactors. What you say about being restricted and expensive sounds almost like the arguments against firearms and why banning them will protect people as if making something illegal somehow will prevent the criminals from having and using them. AI being far less mainstream could simply mean the average person will not benefit, but "big brother" and the corporations will benefit, which is almost for sure NOT a good thing.
    • I do apologize to the author Mr. Sen for my rude comment, questioning his knowledge of the subject. It is I whom lacked knowledge of the subject. Sorry!
    • Hello All Have a MSI Pro B650 VC Wifi Rev 1.0 motherboard Ryzen 7 7700X Radeon 7800XT OC 16GB 32GB Teamgroup DDR 5 5600mhz Samsung 990 Pro 1TB Boot NVMe Samsung 990 Pro 2TB Game NVMe Lian Li Lancool Black ARGB 216 Case Seasonic Focus GX 750 Watt Power supply   Wondering today what is best spot to plug in the following items on system for performance and not bottle neck anything if i can help it Creative Pebble Pro USB C or A Speakers, ((Powered by External USB C to C PD Adapter)  Logitech G513 USB Gaming Keyboard Logitech G502X Wired Gaming Mouse Cyberpower UPS USB Cable for UPS Power Management/System shutdown External drives connected occasionally are as follows---WD My Book 8TB (primary backup drive)   Seagate 8TB in External USB 3.0 Enclosure,  Seagate Portable 1TB USB 3.0 drive,   WD My Passport (Blue) 2TB, and WD My Passport (Red) 2TB,    WD Elements 500GB USB 2.0 External (Oldest one, Christmas 2003)       **Do have a 7 Port Powered  USB Hub as well, but when i use that--that leaves only the USB Flash spot for something to directly connect to system if needed.    Rear USB C 2x2 unused right now as moved the Creative speakers off it to USB A port next to it, with a USB C to A Cable, as figured speakers didn't near audio from USB C port and tie up the high speed port**   Front Ports trying to limit use of, so i don't have Front I/O port go bad again, already had it replaced once by Lian Li support all the way from Taiwan over night ((Do get extra nervous at times on things,  so i might just be extra nervous for nothing lol))
    • "connect with audiences" is the most obvious corporate speak you can think of. I only bought Need for Speed from EA because it was the only racing game with cops in existence and I dig that. Now that they killed off NFS franchise, I have nothing to spend money on. EA is officially dead for me, just like Ubisoft which I've been boycotting for some 20 years now...
  • Recent Achievements

    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      494
    2. 2
      +Edouard
      203
    3. 3
      PsYcHoKiLLa
      127
    4. 4
      Steven P.
      82
    5. 5
      ATLien_0
      79
  • Tell a friend

    Love Neowin? Tell a friend!