• 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

    • Marshall Major V Bluetooth headphones are now up to 47% off on Amazon by Ivan Jenic The Marshall Major V in Midnight Blue is currently $89.99 on Amazon, down from $169.99. That's 47% off and $80 saved on a pair of wireless on-ear headphones from one of the most recognizable names in audio. The Major V is Marshall's take on a long-lasting everyday headphone. The headphones deliver 100+ hours of wireless playtime, which puts them in a completely different category from most Bluetooth headphones that hover around 30-40 hours. You’re charging this thing once a week at most, and with wireless charging supported, you don’t have to worry about additional cables. Marshall promises its signature sound profile, with strong bass, smooth mids, and clear highs. There’s a customizable M-button, which you can set to quickly access Spotify Tap, your EQ settings, or a voice assistant. The design is foldable and lightweight at 186 grams, so it’s easy to pack for travel. And finally, the faux leather finish gives the Major V a sleek, premium look. At $89.99, the Major V Midnight Blue is a genuinely strong buy for anyone who wants a reliable daily headphone without paying premium prices. It’s also worth mentioning that the Cream and Brown variants are also discounted to $89.99, though from a lower original price of $99.99. Marshall Major V Midnight Blue - $89.99 | 47% off on Amazon This Amazon deal is US-specific and not available in other regions unless specified. This is a first-party seller link (at the time of article publishing); ensure that you also purchase from a first-party seller link only. If you don't like it or want to look at more options, check out the previous deals that we have covered, OR you can also visit Amazon US deals page. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • +1 on XVI. I still use it. 
    • Age 16, old enough to get a full-time job, your own bank account, a passport, get married, even join the military and go to war. But talking to your friends on the internet? Oh hell no!
    • I remember when all games had demos; it was a normal thing, not a limited time promotion.
    • Forza Horizon 6 gets big bug-fixing and balancing update by Taras Buria Today, Playground Games released a big Forza Horizon 6 update with a long list of fixes, patches, and balancing tweaks that the studio promised earlier. Version 375.327 is now available on Steam, Microsoft Store, and Xbox, offering users improvements for AI, audio, design, performance, road discovery, upgrades, visuals, online play, and more. Some of the most notable changes in the Series 2 update include rebalanced drivatars, particularly their difficulty and race start behavior. As such, the game should be more balanced on higher difficulty levels, and AI cars should not shoot out when the race starts as if they have rocket boosters. Speaking of difficulty, developers nerfed Drag Tires physics for a more expected and realistic behavior. They are no longer the go-to option for record-breaking times in road racing, and all leaderboard entries with drag tires will be removed. Completionists will also be glad to get a new feature that lets you see road discovery percentage in each region, which should make discovering all roads easier while keeping it quite challenging and interesting (I spent quite a long time finding the last road). Festival Playlist is also getting some much-needed fixes, including patches for bugs that allowed completing Seasonal Jobs ahead of time or where weekly challenges would not unlock for some players. Developers will retroactively give reward points to all who could not complete all challenges due to these bugs. Other changes include changes to Horizon Play progression so that it is easier to reach Level 100, audio improvements on lower-spec devices, fixes for visual glitches, including pixelated smoke, and more. Developers also addressed the currently non-working Eliminator, an online mode gamers used to farm credits with a Hummer EV exploit. Playground Games plans to re-enable it soon. As a gesture of goodwill, players will get a free McLaren Sabre. Those who used the exploit will not be banned, but developers plan to roll back credits to a maximum of 10M for all who farmed credits using the exploit. You can find the complete changelog for the latest Forza Horizon 6 update here.
  • Recent Achievements

    • First Post
      Cosminus earned a badge
      First Post
    • One Year In
      ThatGuyOnline earned a badge
      One Year In
    • 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
  • Popular Contributors

    1. 1
      +primortal
      484
    2. 2
      +Edouard
      185
    3. 3
      PsYcHoKiLLa
      122
    4. 4
      Steven P.
      83
    5. 5
      neufuse
      73
  • Tell a friend

    Love Neowin? Tell a friend!