yyy Posted August 11, 2004 Share Posted August 11, 2004 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 More sharing options...
0 azcodemonkey Posted August 24, 2004 Share Posted August 24, 2004 OK. When I use Spy++ to find the handle for a running .NET form and it's picture box, the screen saver works with that handle. You're going to have to use something different to get you handle. I'd try FindWindow and FindWindowEx. Lame, I know, but it should work. Link to comment Share on other sites More sharing options...
0 yyy Posted August 24, 2004 Author Share Posted August 24, 2004 Here's a delphi code that does it : http://www.undu.com/Articles/990527a.html Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 25, 2004 Veteran Share Posted August 25, 2004 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. Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 25, 2004 Veteran Share Posted August 25, 2004 (edited) 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) Edited August 25, 2004 by The_Decryptor Link to comment Share on other sites More sharing options...
0 darkmark327 Posted August 25, 2004 Share Posted August 25, 2004 Use that in conjunction with my PictureBox handle thing (a Panel would probably be superior) and it should work perfectly. Link to comment Share on other sites More sharing options...
0 rajputwarrior Posted August 25, 2004 Share Posted August 25, 2004 that flurry is the mac screensaver, im using it on my ibook now, its owns Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 25, 2004 Veteran Share Posted August 25, 2004 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? Link to comment Share on other sites More sharing options...
0 darkmark327 Posted August 25, 2004 Share Posted August 25, 2004 (edited) And here it is in a picture boxhere'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 August 25, 2004 by darkmark327 Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 25, 2004 Veteran Share Posted August 25, 2004 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: Link to comment Share on other sites More sharing options...
0 nkorls Posted August 25, 2004 Share Posted August 25, 2004 finally. So API is more powerful. hehe Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 25, 2004 Veteran Share Posted August 25, 2004 (edited) 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 August 25, 2004 by The_Decryptor Link to comment Share on other sites More sharing options...
0 yyy Posted August 25, 2004 Author Share Posted August 25, 2004 YES !!! I made it :laugh: :) :happy: :D Thank you very very much - you are great. You are the best. Thanks The_Decryptor, nkorls, darkmark327 and weenur Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 25, 2004 Veteran Share Posted August 25, 2004 I'm glad your happy, I'm happy to, it's always good to work out a problem. Link to comment Share on other sites More sharing options...
0 yyy Posted August 25, 2004 Author Share Posted August 25, 2004 Do you know how can I stop the screen saver? I want to be able to replace the screen saver so if the user changes it, he can see the new one. Like in the screensaver tab when you cchange the screen saver. How can I do it? Link to comment Share on other sites More sharing options...
0 yyy Posted August 25, 2004 Author Share Posted August 25, 2004 I'm glad your happy, I'm happy to, it's always good to work out a problem. Yes you right :laugh: I couldn't have done this without you. Can you answer my other question above? (If your'e not exhosted from the last one :laugh: ) Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 25, 2004 Veteran Share Posted August 25, 2004 (edited) 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 August 25, 2004 by The_Decryptor Link to comment Share on other sites More sharing options...
0 yyy Posted August 25, 2004 Author Share Posted August 25, 2004 (edited) Thank you very much :) I don't know how to stop the screen saver. That's the problem. Hope you can find something. It is not so urgent though. Edited August 25, 2004 by yyy Link to comment Share on other sites More sharing options...
0 yyy Posted August 25, 2004 Author Share Posted August 25, 2004 Sorry I posted the same message twice :rolleyes: Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 25, 2004 Veteran Share Posted August 25, 2004 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)) Link to comment Share on other sites More sharing options...
0 yyy Posted August 25, 2004 Author Share Posted August 25, 2004 Thanks :) Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 25, 2004 Veteran Share Posted August 25, 2004 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 Link to comment Share on other sites More sharing options...
0 yyy Posted August 25, 2004 Author Share Posted August 25, 2004 WOW :laugh: I don't know how to thank you. You are great :) I don't have any rar program so I'm downloading one now. I hope I can understand the code. Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 25, 2004 Veteran Share Posted August 25, 2004 vb .net is easy to read, it's almost English, it should be easy to read the code, and port it to C# And thank you, i only ever hear I'm great every few days :D Link to comment Share on other sites More sharing options...
0 yyy Posted August 25, 2004 Author Share Posted August 25, 2004 It doesn't work. The screen saver still plays even after I run that code. What am I doing wrong ? Can't I stop the screen saver by using an API ? Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 25, 2004 Share Posted August 25, 2004 (edited) 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 August 25, 2004 by weenur Link to comment Share on other sites More sharing options...
Question
yyy
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
150 answers to this question
Recommended Posts