• 0

C# Screen saver?


Question

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

Recommended Posts

  • 0

Sorry for the problems in my code, i didnt even think that c# might not have a chr() function, i also keep forgetting about unicode and ansi (im to used to xp now), i have to start remembering that.

Also, i'm not at my house, so i dont have any code with me, but when i get home i'll upload my class, but i will paste some code from memory, this is just how to load my oo class

It's called ScreenSaverProcess because of an name conflict with another class

Starts a new class, this has to be called after the controls are added to the form or else you get a error

Dim ScreenSaver as ScreenSaverProcess = New ScreenSaverProcess("logon.scr",Panel1)

This gets the name

ScreenSaver.GetScreenSaverName()

This starts the configuation

ScreenSaver.StartScreenSaverConfig()

This starts the preview in the control specified in the new function

ScreenSaver.StartScreenSaverPreview()

This starts the screensaver full screen

ScreenSaver.StartScreenSaver()

This kill's the screensaver

ScreenSaver.KillScreenSaver()

Also, the GetScreenSaverName and New functions are overloaded, so you can specify a filename and directory for each function, e.g. ScreenSaver.GetScreenSaverName("logon.scr") or ScreenSaver.GetScreenSaverName("C:\Windows\System32","logon.scr") (Cause i dont have the code i cant remember if i append the trailing \ on the path)

Also, i hopefully will stop giving VB code soon, i want to start learning more of C#, i sort of know the syntax, but i would like to know more.

Edit: Thanks weenur, i didnt know that screensaver names cant be longer than 25 characters, i set it to 255 just to be safe (the code sample i looked at to fix the problems i was having (i had to fill the string with the 0 character first) was using 512 characters, so i dropped it down a bit)

Edited by The_Decryptor
Link to comment
Share on other sites

  • 0

Ok, im home now, i changed my class to use DllImport so i can overcome the ANSI and Unicode stuff, and i limited the name of the screensaver to 25 characters, i think every thing is okay now

I have attached the whole ScreenSaver Shower Thingy to show off my class, and show how to use it.

ScreenSaver_Shower_Thingy.rar

Link to comment
Share on other sites

  • 0

Thanks The_Decryptor :laugh: But I the code you gave is enough for now :)

Do you know how to change the time that Windows waits until it starts the screen saver? I tried to change ScreenSaveTimeOut which is in CurrentUser\\Control Panel\\Desktop in the registry, but it doesn't work. Do you know how can I change it ?

Link to comment
Share on other sites

  • 0

I think it's a api call, i have a starter book on vb6 (it's old now though), it shows how to change the wallpaper and other things through a api call, so it might affect screen-savers to, ill start palying around with it now.

Also, the code was more for weenur, cause he said he wanted to see the oo class i based on his.

Edit: Yep, i was right, it's a api call, im just working on some code now.

Edited by The_Decryptor
Link to comment
Share on other sites

  • 0

Ok, im done, i have code that can set and retrieve the time-out, i was going to post it earlier, but my browser crashed and i decided to change some stuff.

Declarations:

? ?<DllImport("user32", CharSet:=CharSet.Auto)> _
 ? ?Private Shared Function SystemParametersInfo(ByVal uAction As Integer, ByVal uParam As Integer, ByRef lpvParam As Integer, ByVal fuWinIni As Integer) As Integer
 ? ?End Function

 ? ?Private Const SPI_GETSCREENSAVETIMEOUT = 14
 ? ?Private Const SPI_SETSCREENSAVETIMEOUT = 15
 ? ?Private Const SPIF_UPDATEINIFILE = &H1
 ? ?Private Const SPIF_SENDWININICHANGE = &H2

Code:

? ?Public Function GetScreenSaverTimeOut() As Integer
 ? ? ? ?Dim lRet As Integer
 ? ? ? ?Dim lSeconds As Integer

 ? ? ? ?lRet = SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, lSeconds, 0)
 ? ? ? ?If lRet > 0 Then
 ? ? ? ? ? ?GetScreenSaverTimeOut = lSeconds / 60
 ? ? ? ?Else
 ? ? ? ? ? ?GetScreenSaverTimeOut = -1
 ? ? ? ?End If
 ? ?End Function

 ? ?Public Function SetScreenSaverTimeOut(ByVal NewValueInMinutes As Integer) As Boolean
 ? ? ? ?Dim lRet As Integer
 ? ? ? ?Dim lSeconds As Integer
 ? ? ? ?lSeconds = NewValueInMinutes * 60
 ? ? ? ?lRet = SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, lSeconds, Nothing, SPIF_UPDATEINIFILE + SPIF_SENDWININICHANGE)
 ? ? ? ?SetScreenSaverTimeOut = lRet <> 0
 ? ?End Function

It's pretty much self explanatory.

Also, yyy, if you want to see the similarities between vb.net and c#, i recommend you get a copy of .NET Reflector, it's a fully working Disassembler and De-compiler for .net, it allows you to choose from multiple languages, e.g. De-compile a vb app into c#, or vice-versa, it's really good.

Also 2, since you and weenur have been so good, and since im feeling generous, pm me if you:Dant a gmail account (I'm feeling generous because i got 6 invites today :D )

Edit: I'll need your names and e-mail address's to send the invites.

Link to comment
Share on other sites

  • 0

Thanks :) There aren't enough smilies in here to show how happy I am. I just hope it will work for me :laugh: I convert it with SharpDevelop and most of the time it is good. Thanks for offering me another way.

Thanks also for the G-mail offer :laugh: but sorry - I am satisfy with my 10 MB account :laugh: 6 invites :o wow that's a lot. People sell those in E-bay :laugh: You are generous.

Thanks again.

Link to comment
Share on other sites

  • 0

It should work, it's working flawlessly here (i put it in a loop that added 10 minutes to my time out then popped up a message box with the new time)

That's okay about the gmail account, im not actully using mine much (most of my e-mail still goes to hotmail) in case google shut's it down (it shouldn't happen, but i cant be to careful), but i probably wont sell them in ebay, i heard google is cracking down on people who sell them, and i dont want to cross google (they know my name and address :ninja: )

Also, with sharpdevelop. i was trying to convert my Certificate 3 teacher (who just happened to be a developer to) to it, i downloaded it, installed it on to his laptop just to find that there was no windows forms support (i.e. no gui), did i just miss something or is there no gui support for windows forms?

Also, the offer still stands weenur!

Edit: i wont be on for almost 24 hours from now, it's 2AM here and i have to go with my mum to the city (I'm in the suburbs) early tomorrow (she's getting a tattoo, and then we have to go baby-sit my cousin.)

Edited by The_Decryptor
Link to comment
Share on other sites

  • 0

I didn't know that they don't allow to sell them :rolleyes: Whatever.

Except a few bugs I don't have any problems with SharpDevelop. It has windows forms designer if that's what you mean. That's a nice program if you need a free one.

Link to comment
Share on other sites

  • 0

Tha main reson i would be using SharpDevelop is for Mono development (i heard a version exists), for Windows im using Visual Studio .NET Enterprise Architect 2003, it's fairly good :D

Anyway, at the moment im doing my dev stuff on a OSX machine with a mono port on it, and for any thing graphical or windows only, i use a vnc client to connect to the pc.

Link to comment
Share on other sites

  • 0
Also, the code was more for weenur, cause he said he wanted to see the oo class i based on his.

I did? Ah, no matter. I appreciate that you've helped yyy in ways I couldn't. I'm always pressed for time, so I never get to give thorough examples.

I think I may take you up on that GMail invite. :) Thanks for that. (Y)

Link to comment
Share on other sites

  • 0

Really? :laugh: I have lots of problems since I started programming in c# just about 5 months ago. I saw that these forums has a big amount of members so I decided to ask here and I was right - there are great people here like you and The_Decryptor :)

Link to comment
Share on other sites

  • 0

Thanks, most of the time people are calling me stupid, but for somebody to say I'm great is a nice change

Also, weenur, i got your pm, i sent the invite to the bumpmapboy account, if you want me to send it to a different one just tell me.

Link to comment
Share on other sites

  • 0
Thanks, most of the time people are calling me stupid, but for somebody to say I'm great is a nice change

Also, weenur, i got your pm, i sent the invite to the bumpmapboy account, if you want me to send it to a different one just tell me.

You? Stupid? :no: :no: :no: You found the code for almost all of my program. You are really great :laugh: Good work :) Couldn't do it without you and weenur.

Link to comment
Share on other sites

  • 0

Again, thanks

It's mostly caused by me posting the wrong info, people jump on me and instead of telling me im wrong just call me stupid, by the time i find out im wrong, people dont care, i have been branded.

Link to comment
Share on other sites

  • 0

Nobody is prefect. People can be wrong sometimes. Even I don't always right although I find the solutions eventually.

By the way, are you sure that your method of finding the screen savers name is ok? I can't see the names of some screen saver like the "Flying Windows" screen saver of Windows. Maybe I do something wrong.

Link to comment
Share on other sites

  • 0
By the way, are you sure that your method of finding the screen savers name is ok? I can't see the names of some screen saver like the "Flying Windows" screen saver of Windows. Maybe I do something wrong.

It is working for every screensaver i try it on here, and i based the code on documentation from the msdn stuff (it just says that the name of the screensaver has to be the first string resource in the file) so it should work

But, i dont have the flying windows screensaver on xp, does it happen for any other screensavers?

Link to comment
Share on other sites

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

    • No registered users viewing this page.