• 0

C# Screen saver?


Question

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
  • 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

  • 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 ?

  • 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
  • 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.

  • 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.

  • 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
  • 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.

  • 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)

  • 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.

  • 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.

  • 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?

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

    • No registered users viewing this page.
  • Posts

    • Anyway to download these versions without being on the Experimental builds?
    • Nothing is stopping you from continuing with your testing cadence. If updates are released every 2 weeks instead of 4, and you test once every 4 weeks, the exact same amount of patches will still be available for you in those 4 weeks. For example: Before 4th week - patch 1, 2, 3, 4 After 2nd week - patch 1 and 2 4th week - patch 3 and 4 Still the same amount after 4.
    • Everyone else has said it. I'm gonna say it - you don't know what you're talking about. I do. I have two laptops. One work, one personal. I have access to two more laptops - both personal. At home I manually update my personal laptop when I see on Neowin that there is an update - I carry on and only apply the updates when I am ready. My work one only updates when my workplace decides to send it - I carry on and only apply the updates (when they actually arrive, which is usually days after the release) when I switch off the laptop at the end of the day as usual. The two other personal laptops only get updated when I get to it which is rarely - the people who own them carry on using them until I get to it and update them. All of the browsers on all laptops are configured to restore the tabs when launched. Google and Microsoft have changed from 6 weeks to 4, and it looks like it's going to move to 2. None of these changes affect how any of these browsers on the laptops are used. Not one jot. My advice to you is stop panicking whenever you see an update. Just carry on with what you're doing. This even benefits you in a way - from your comment you sound like you don't like the changes or the frivolous new features - great - then carry on as before!
    • AMAZON needs to take total accountability for this.
    • Server Summit had a heap of announcements, ADCS changes are baller.
  • 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
      509
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      138
    4. 4
      ATLien_0
      90
    5. 5
      Steven P.
      80
  • Tell a friend

    Love Neowin? Tell a friend!