• 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

    • Firefox 152.0 by Razvan Serea Firefox is a fast, full-featured Web browser. It offers great security, privacy, and protection against viruses, spyware, malware, and it can also easily block pop-up windows. The key features that have made Firefox so popular are the simple and effective UI, browser speed and strong security capabilities. Firefox has complete features for browsing the Internet. It is very reliable and flexible due to its implemented security features, along with customization options. Firefox includes pop-up blocking, tab-browsing, integrated Google search, simplified privacy controls, a streamlined browser window that shows you more of the page than any other browser and a number of additional features that work with you to help you get the most out of your time online. Firefox key features Enhanced Tracking Protection (ETP) – Blocks trackers, cookies, cryptominers, and fingerprinters by default. Private Browsing Mode – Deletes history, cookies, and temporary files when closed. Lightweight & Fast Performance – Optimized memory usage with efficient page loading. Cross-Platform Sync – Sync bookmarks, passwords, history, and open tabs across devices. Customizable Interface – Toolbars, themes, and extensions can be tailored to user needs. Strong Privacy Controls – Options to manage cookies, permissions, and site data easily. Reader Mode – Strips away clutter for distraction-free reading. Pocket Integration – Save and read articles offline with Pocket built into Firefox. Picture-in-Picture (PiP) – Watch videos in a floating window while multitasking. Extensions & Add-ons – Vast library for productivity, security, and personalization. Built-in PDF Viewer – No need for external software to view PDFs. Firefox Monitor – Alerts users if their email is part of a known data breach. Multi-Account Containers – Isolate browsing sessions (e.g., work, personal, shopping). Performance & Resource Efficiency – Uses fewer system resources than some competitors. Open Source & Community-Driven – Transparent development with global contributions. Download: Firefox 64-bit | Firefox 32-bit | ARM64 | ~70.0 MB (Freeware) Download: Firefox for MacOS | 145.0 MB View: Firefox Home Page | Release Notes Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Microsoft Visio 2024 Professional for Windows is still at 90% off by Steven Parker Created by ChatGPT Today's highlighted Neowin Deal comes from our Apps & Software section of the Neowin Deals store, where you can save 90% on Microsoft Visio 2024 Professional for Windows [Digital License]. Microsoft Visio: Turn Complex Ideas into Clear Visuals Microsoft Visio 2024 is a robust diagramming software designed to empower individuals and businesses to visually represent complex data, processes, and workflows. With a host of advanced features, it caters to professionals from various industries, including IT, engineering, business, and architecture. Visio 2024 makes it easy for individuals and teams to create and share clear, professional diagrams that simplify complex information. It offers updated shapes, templates, and styles, along with a new search bar to improve your experience. Visio 2024 also has a fresh design that matches other Office apps you use. Create stunning diagrams Extensive Diagramming Capabilities: Visio 2024 offers a wide array of diagram types, including flowcharts, process maps, floor plans, network diagrams, and organizational charts. The software comes with a comprehensive set of pre-built templates and shapes, making it easier to get started on projects quickly. Professional Templates and Shapes: The software includes over 250,000 shapes across multiple diagram types, ensuring that users from any field-whether creating a simple flowchart or a complex engineering design-have the tools they need to represent their ideas visually. Data-Linked Diagrams: One of the most powerful features of Visio 2024 is its ability to link data to diagrams, allowing users to visualize real-time data directly within their diagrams. Whether you're pulling data from Excel, SQL Server, or other databases, the software ensures that your diagrams are automatically updated as data changes, giving users better insights and control. Advanced Formatting Options: Visio 2024 comes equipped with a range of formatting tools to create highly customized diagrams. These include shape formatting, text adjustments, and the ability to apply various themes, ensuring diagrams not only serve their functional purpose but also look professional. Enhanced Visual Styles: This version of Visio includes new visual styles and layouts that make complex diagrams easier to interpret. Whether you're designing an IT network, a business process flow, or a floor plan, the enhanced visual options improve clarity and presentation quality. Easy, secure collaboration Real-Time Collaboration: With Visio 2024's improved collaboration tools, multiple users can work on the same diagram simultaneously from anywhere, with changes being tracked in real-time. This makes it a highly efficient tool for teams working remotely or across different locations. Mobile and Cloud Access: Users can view and edit diagrams on the go with the Visio web app. This ensures that even when you're away from your desktop, you can access and make critical changes to diagrams via mobile devices. Integration with Microsoft 365: Visio 2024 integrates seamlessly with the Microsoft 365 suite, allowing users to easily embed diagrams into PowerPoint presentations, Word documents, or Teams chats. You can also store diagrams in OneDrive or SharePoint for easy sharing and access from any device. Security and Compliance: Built with enterprise-grade security, Visio 2024 ensures that your diagrams are protected. Microsoft's trusted cloud infrastructure means that your data is encrypted and safeguarded, with compliance with international standards. Good to know Length of access: lifetime Redemption deadline: redeem your code within 7 days of purchase Access options: desktop Bound to account - Limited to one device activation at a time Only available to existing and new users Version: 2024 Updates included Click here to verify Microsoft partnership Microsoft Visio 2024 Professional for Windows normally costs $579.99, but it can be yours for just $39.97 for a limited time, that's a saving of $520 (90%). For terms, specifications, and license info please click the link below. Microsoft Visio 2024 Professional for Windows for $54.97 (was $579.99) Although priced in U.S. dollars, this deal is available for digital purchase worldwide. Support queries If you have queries or need support for any of the Neowin Deals, please use the contact form here. Neowin Deals are managed and sold by StackCommerce who represent Neowin on an affiliate basis. Why we post these deals We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. So for those that keep moaning and complaining, be thankful we're still online for you to even do that. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • 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))
  • 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
      499
    2. 2
      +Edouard
      201
    3. 3
      PsYcHoKiLLa
      127
    4. 4
      Steven P.
      82
    5. 5
      ATLien_0
      77
  • Tell a friend

    Love Neowin? Tell a friend!