• 0

C# Screen saver?


Question

Recommended Posts

  • 0

I sort of found out the problem

When you call Process.Start, it calles the Open procedure of the file (so if you told it to open a word doc, it would do the same code as if you double clicked on it) so when the function is called instead of passing the proper commands it passes a /S instead

example

C:\Windows\system32\login.scr /S

instead of

C:\Windows\system32\login.scr /P Handle

It does the same thing when i call ShellExecute through interop

Looks like we have to find a command that doesn't call it like that.

  • 0

In my last post, i discovered the problem, in this post i worked it out

You shouldn't call Process.Start or ShellExecute, you should call WinExec as the Delphi example does, that will leave you with this.

Edit: it should work with picture boxes to, i just haven't tried it. but make sure the picture box isn't re-sizable, that could cause problems

Also, here is the code (sorry it's in vb, i dont know much c#, but it's easy to convert)

Whack this is the declarations bit

Private Declare Function WinExec Lib "kernel32" (ByVal lpCmdLine As String, ByVal nCmdShow As Integer) As Integer

call this to load the screen saver, the 1 at the end is for the constant SW_SHOW in Delphi and SW_SHOWNORMAL in vb

Also, the Flurry screen saver is just on my system, but it's cool and i recommend getting it.

WinExec("C:\Windows\system32\Flurry.scr /p " & Me.Handle.ToString, 1)

post-47-1093403729.png

Edited by The_Decryptor
  • 0

And here it is in a picture box

here's what i changed

Old

WinExec("C:\Windows\system32\Flurry.scr /p " & Me.Handle.ToString, 1)

New

WinExec("C:\Windows\system32\Flurry.scr /p " & PictureBox1.Handle.ToString, 1)

Also, rajputwarrior, i know, i got it on my eMac :yes:

Edit: darkmark327, it doesn't look like it needs your code to work, what was the problem that needed you to make it?

post-47-1093404645.png

  • 0
And here it is in a picture box

here's what i changed

Old

WinExec("C:\Windows\system32\Flurry.scr /p " & Me.Handle.ToString, 1)

New

WinExec("C:\Windows\system32\Flurry.scr /p " & PictureBox1.Handle.ToString, 1)

Also, rajputwarrior, i know, i got it on my eMac :yes:

Well, congrats.

When I was using ShellNotifyIcon (for balloon tips in weathalert), it takes a handle to the window--but NotifyIcons have their own hidden windows, so passing my window handle didn't work. I failed to realize that's not an issue for you because you're using the picturebox itself rather than its window handle.

Edited by darkmark327
  • 0

Thanks

Also, i haven't really played around with the Shell_NotifyIcon API's in .net i have used the NotifyIcon component more, so i haven't come across your problem before.

Edit: i hadn't heard of your program before, but i have to say it's mighty nice :yes:

  • 0

In some cases, the problem was that there was no .net equivalent for the WinExec function (that i know of) if there was this might have been solved a bit quicker.

Edit: I'm going now, i was only supposed to be on the net for 10 mins, that was a hour ago, so ill be back on in a few hours.

Edited by The_Decryptor
  • 0

Well, the screen saver should detect for the app's windows to be closed or destroyed, that what happens when the display control panel is closed, so the scr will exit, but in your case (and i think how ms does it) you should check to see if the screen saver is changed, when it is kill the screen saver process, then reload the new screen saver, ill look for code for you to do it, i havent tried it before so i have to idea.

Edit: You're welcome :)

Edited by The_Decryptor
  • 0

I already have working code, but it's just to general (it could stop alot of programs instead of just the screen saver :no: )

I'm just working on making it better (and faster, the code returns a array, it takes a while to gather (like 2 or 3 seconds))

  • 0

Ok, i have fully working (and safe hopefully) code, i was having a problem, i was checking for the file name, but windows was returning the path and file name, i fixed that, Also, i have attached the whole program i wrote, not just posted code, i dont know if you have vb installed, if you dont just tell me and i'll put up the code.

ScreenSaver_Shower_Thingy.rar

  • 0

OK. The_Decryptor's mentioning of not using shell execute set it off for me. I've got it with native .NET code.

Create a class level variable to store the process that you create so you can kill it when you need to. In this case, it's called _currentScr.

// member var
Process _currentScr;
...

// the code you'd use to load the screensaver
 	 string scrPath;
 	 if( openFileDialog1.ShowDialog(this) == DialogResult.OK )
 	 {
    scrPath = openFileDialog1.FileName;
    if( _currentScr != null )
    {
   	 _currentScr.Kill();
   	 _currentScr = null;
   	 pictureBox1.Invalidate();
    }

    ProcessStartInfo psi = new ProcessStartInfo( scrPath, "/p " + pictureBox1.Handle.ToString() );
    psi.UseShellExecute = false;
    _currentScr = Process.Start( psi );
 	 }

Just call _currentScr.Kill() to end the process.

BTW, it's the UseShellExecute = false that makes the difference. It's true by default.

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

    • No registered users viewing this page.
  • Posts

    • Not even an OLED display on the laptops. Also it seems that the laptop design isn't the same as the Surface Ultra model. Looks like bargain bin at high prices.
    • VirtualBox 7.2.10 by Razvan Serea VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Targeted at server, desktop and embedded use, it is now the only professional-quality virtualization solution that is also Open Source Software. Presently, VirtualBox runs on Windows, Linux, macOS, and Solaris hosts and supports a large number of guest operating systems including but not limited to Windows (NT 4.0, 2000, XP, Server 2003, Vista, 7, 8, Windows 10 and Windows 11), DOS/Windows 3.x, Linux (2.4, 2.6, 3.x, 4.x, 5.x and 6.x), Solaris and OpenSolaris, OS/2, OpenBSD, NetBSD and FreeBSD. Some of the features of VirtualBox are: Modularity. VirtualBox has an extremely modular design with well-defined internal programming interfaces and a client/server design. This makes it easy to control it from several interfaces at once: for example, you can start a virtual machine in a typical virtual machine GUI and then control that machine from the command line, or possibly remotely. VirtualBox also comes with a full Software Development Kit: even though it is Open Source Software, you don't have to hack the source to write a new interface for VirtualBox. Virtual machine descriptions in XML. The configuration settings of virtual machines are stored entirely in XML and are independent of the local machines. Virtual machine definitions can therefore easily be ported to other computers. VirtualBox 7.2.10 changelog: VMM: Fixed issue when CentOS 10 VM was not booting due to the message "Fatal glibc error: CPU does not support x86-64-v3" (​github:gh-642) Devices/EFI: Fixed booting issue when ARM VM had less than 1024 MiB of RAM assigned (​github:gh-679) USB: Fixed issue when it was not possible to attach USB device to headless VM on Apple Silicon/macOS 26.4.1 (​github:gh-631) Storage: Fixed issue when VIRTIO-SCSI device was not recognized as SSD device by guest system (​github:gh-634) Network: Fixed issue in E1000 emulation code which triggered debug log creation (​github:gh-645) Network: Fixed issue in E1000 emulation code which prevented OS/2 guest from booting (​github:gh-683) Linux Host: Fixed issue when VMs could not be started due to kernel oops (​github:gh-639) Linux Host and Guest: Fixed issue when kernel modules were failing to build with openSUSE 16.0 kernel Linux Host and Guest: Added initial support for kernel 7.1 Linux Host and Guest: Added extra fixes for RHEL 9.8 kernel (​github:gh-676) Linux Host and Guest: Added possibility to build source code using NASM instead of YASM as the assembler (​github:gh-520) Linux Guest Additions: Added initial support for Extended Data Control Protocol for clipboard sharing with Plasma on Wayland guests (​github:gh-33) Linux Guest Additions: Added extra fixes for preventing vboxvideo kernel module build with kernel version 7.0 and newer (​github:gh-655) OS/2 Guest Additions: Fixed issue when Shared Folders automount and clipboard sharing stopped working (​github:gh-551) Download: VirtualBox 7.2.10 | 170.0 MB (Open Source) Download: VirtualBox 7.2.10 Extension Pack | 19.1 MB View: VirtualBox Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • OK, now ask yourself how are they going to enforce that law? By requiring every single adult to prove their age and provide their legal identity documents to an UNREGULATED 3rd party company that already has a long track record of multiple data breaches. Not to mention, parliament have voted AGAINST this ban, twice, and Starmer is going ahead anyway. So, where's the democracy here, because that looks like dictatorship to me. The solution here is parental responsibility, not government control. Run some public service announcements on TV and UK social media teaching parents how to setup parental controls. That's already been proven to actually work. But the, this is not and has NEVER been about keeping kids safe. It's about control and monitoring. Watching what you're doing online and controlling what you can see and what you can say.
    • Interesting read. I knew the adware was quite controversial at the time, however never realised to the point The Guardian wrote an article about Patchou. I just said no and enjoyed his creation, I’d probably be a lot more wary of something like that today though.
  • Recent Achievements

    • One Month Later
      Prasann earned a badge
      One Month Later
    • Week One Done
      Prasann earned a badge
      Week One Done
    • First Post
      Dys Topia earned a badge
      First Post
    • Collaborator
      vjlex earned a badge
      Collaborator
    • Reacting Well
      Dys Topia earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      525
    2. 2
      +Edouard
      180
    3. 3
      PsYcHoKiLLa
      105
    4. 4
      Steven P.
      89
    5. 5
      ATLien_0
      70
  • Tell a friend

    Love Neowin? Tell a friend!