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 yyy Posted August 25, 2004 Author Share Posted August 25, 2004 :laugh: :D :p ;) :happy: :yes: :rofl: :) Thanks weenur. Your way works. The_Decryptor - thanks too but weenur does it easier :) Link to comment Share on other sites More sharing options...
0 yyy Posted August 25, 2004 Author Share Posted August 25, 2004 (edited) Do you know how can I get the name of a screen saver? I want to have a combo box with screen savers names like in the screen savers menu. For example, my screen saver is "c:\windows\system32\myss.scr" - Can I get its name ? Edited August 25, 2004 by yyy Link to comment Share on other sites More sharing options...
0 nkorls Posted August 26, 2004 Share Posted August 26, 2004 Do you know how can I get the name of a screen saver? I want to have a combo box with screen savers names like in the screen savers menu. For example, my screen saver is "c:\windows\system32\myss.scr" - Can I get its name ? You can search all files with ".src" in x:\win\system32 But this will spend times.l Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 26, 2004 Share Posted August 26, 2004 you can get the name from the string table of the screensaver's resources. I'll work up some code for you. Link to comment Share on other sites More sharing options...
0 yyy Posted August 26, 2004 Author Share Posted August 26, 2004 You can search all files with ".src" in x:\win\system32But this will spend times.l I know - I already do this and it is fast :laugh: But I want to have the actual name of the screen saver. Link to comment Share on other sites More sharing options...
0 yyy Posted August 26, 2004 Author Share Posted August 26, 2004 you can get the name from the string table of the screensaver's resources. I'll work up some code for you. Thanks :laugh: Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 26, 2004 Veteran Share Posted August 26, 2004 (edited) Aww, my code isn't needed anymore :( But i will check out the problem with it not killing the screensaver, it works perfectly here. Edit: Yeah, weenur, i looked at your code and it's superior than mine, at least my code was good for something Also, my code is killing the screen saver here, so who knows. Edited August 26, 2004 by The_Decryptor Link to comment Share on other sites More sharing options...
0 yyy Posted August 26, 2004 Author Share Posted August 26, 2004 Don't be disapointed - somewhere in my code I tried to use weenur way but it didn't work :rolleyes: so I used your code instead and it works :laugh: I use both yours and weenur codes :D Thank you ! Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 26, 2004 Veteran Share Posted August 26, 2004 Lol, i was just going to post that i got weenur's code and improved on it (sorry weenur) It's all Object Orientated now, so you call new on the module, supply the file name and Control to paint it on (and it's overloaded with directories to) Then it has the Functions: ShowScreenSaver ShowScreenSaverConfig ShowScreenSaverPreview KillScreenSaver Ill post it if you want, but if it's working in your code i wouldn't mess with it. Link to comment Share on other sites More sharing options...
0 yyy Posted August 26, 2004 Author Share Posted August 26, 2004 Thanks - but I think that wuneer code is ok for now :) If I'll need something else I'll ask you. Do you know how to get the name of a screen saver from its *.scr file ? Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 26, 2004 Veteran Share Posted August 26, 2004 (edited) I have absolutely no idea, but ill start working on it now. Also, just wondering, what is this program your working on? Edit: Okay, worked out how windows get's the name, it reads the name from the first string resource in the first string table in the file, now lets see how to access resources from managed code. Edited August 26, 2004 by The_Decryptor Link to comment Share on other sites More sharing options...
0 yyy Posted August 26, 2004 Author Share Posted August 26, 2004 Actually its a plugin for a program called Desktop Sidebar. It puts a toolbar on the side of the screen and allows you to launch programs, see video, mail and it has also an RSS aggresor... Great program (I suggest anyone to use it :) ). So I develop a plugin for it. I've already distrobuted the beta verion here. This is a plugin which allows users to see their screen savers on the desktop sidebar program. Already has about 47 downloads :laugh: Hope you can find the code about the resources. Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 26, 2004 Veteran Share Posted August 26, 2004 That sounds cool, it would also be a cool tile for the longhorn sidebar if your ever going to do that. Also, i have a general idea on how to do it, im just looking to see if their is already code on the net that does the hard work ;) Link to comment Share on other sites More sharing options...
0 yyy Posted August 26, 2004 Author Share Posted August 26, 2004 No - I use only Desktop Sidebar - I think it is better than Lonhorn's sidebar. :laugh: Thanks for looking for a code for me. :) Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 26, 2004 Veteran Share Posted August 26, 2004 Im working on code now, it will either work or cause a bsod, cross your fingers! Edit: hmm, didnt work but didnt not work either, i had a System.NullReferenceException, i might be doing something wrong. Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 26, 2004 Veteran Share Posted August 26, 2004 (edited) Im on a roll lately, here is the code to get the name of the screen saver (again, sorry it's in vb) API Declarations ? ?Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Integer) As Integer ? ?Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Integer ? ?Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal hInstance As Integer, ByVal wID As Integer, ByVal lpBuffer As String, ByVal nBufferMax As Integer) As Integer Code (Note, i made this as a function so it's easier to work with) ? ?Public Function GetScreenSaverName() As String ? ? ? ?Dim ScreenSaverHandle As Integer ? ? ? ?Dim ScreenSaverName As String = New String(Chr(0), 255) ? ? ? ?ScreenSaverHandle = LoadLibrary(scrFolder & scrPath) ? ? ? ?LoadString(ScreenSaverHandle, 1, ScreenSaverName, 255) ? ? ? ?FreeLibrary(ScreenSaverHandle) ? ? ? ?Return ScreenSaverName.Trim(Chr(0)) ? ?End Function the bit of code that says "scrFolder & scrPath" in the function LoadLibrary is the path to the .scr file (e.g. C:\WINDOWS\System32\logon.scr) Edit: just changed the code a bit Edited August 26, 2004 by The_Decryptor Link to comment Share on other sites More sharing options...
0 The_Decryptor Veteran Posted August 26, 2004 Veteran Share Posted August 26, 2004 (edited) This is just to show that the code works now, this is my ScreenSaver Shower Thingy updated to use the object orientated ScreenSaver class i based off weenur's code, and my code to get the name Notice the word Flurry in the caption of the group box Edited August 26, 2004 by The_Decryptor Link to comment Share on other sites More sharing options...
0 yyy Posted August 26, 2004 Author Share Posted August 26, 2004 :laugh: :) :D ;) :happy: :yes: :rofl: :p :cool: :woot: Thank you very very very much ! That's exactly what I needed. I hope that you'll also use DS - that's a great program. Thanks for helping some of the users in DS forums. Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 26, 2004 Share Posted August 26, 2004 Cool! Nice work T_D. I wasn't trying to make it OO(not even close), but just give an example of how to do it. Link to comment Share on other sites More sharing options...
0 yyy Posted August 26, 2004 Author Share Posted August 26, 2004 It doesn't work for me :no: Can you convert it to c#? I only need Public Function GetScreenSaverName() As String Dim ScreenSaverHandle As Integer Dim ScreenSaverName As String = New String(Chr(0), 255) ScreenSaverHandle = LoadLibrary(scrFolder & scrPath) LoadString(ScreenSaverHandle, 1, ScreenSaverName, 255) FreeLibrary(ScreenSaverHandle) Return ScreenSaverName.Trim(Chr(0)) End Function this. My converter doesn't conver Chr(0). I tried to replace it with something else but all I get is a blank string. Can you do it ? Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 26, 2004 Share Posted August 26, 2004 (edited) It doesn't work for me :no: Can you convert it to c#? I only need Public Function GetScreenSaverName() As String Dim ScreenSaverHandle As Integer Dim ScreenSaverName As String = New String(Chr(0), 255) ScreenSaverHandle = LoadLibrary(scrFolder & scrPath) LoadString(ScreenSaverHandle, 1, ScreenSaverName, 255) FreeLibrary(ScreenSaverHandle) Return ScreenSaverName.Trim(Chr(0)) End Function this. My converter doesn't conver Chr(0). I tried to replace it with something else but all I get is a blank string. Can you do it ? public string GetScreenSaverName() { int scrHandle; string scrName = new string( '\0', 25 ); // note that according to the specs of a screensaver, the name can never be longer than 25 chars. scrHandle = LoadLibrary( scrFolder + scrPath ); LoadString( scrHandle, 1, scrName, 25 ); FreeLibrary( scrHandle ); return scrName.Trim(); } Edited August 26, 2004 by weenur Link to comment Share on other sites More sharing options...
0 yyy Posted August 26, 2004 Author Share Posted August 26, 2004 Still doesn't work. All I get is a numbers or that it tells me - "Failed to load resources from resource file". Can you show it to me with the API declerations? Maybe that's wrong. Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 26, 2004 Share Posted August 26, 2004 I get the same thing. Wierd. HMODULE LoadLibrary(LPCTSTR lpModuleName) BOOL FreeLibrary(HMODULE hModule) int LoadString(HINSTANCE hInst, UINT uid, LPTSTR lpBuffer, int nBufferMax) <edit> Fixed it. I was passing in by reference. pass in the string by val to the LoadString function. Link to comment Share on other sites More sharing options...
0 yyy Posted August 26, 2004 Author Share Posted August 26, 2004 I don't understand - I use this: [System.Runtime.InteropServices.DllImport("kernel32")] private static extern int FreeLibrary(int hLibModule); [System.Runtime.InteropServices.DllImport("kernel32", EntryPoint="LoadLibraryA")] private static extern int LoadLibrary(string lpLibFileName); [System.Runtime.InteropServices.DllImport("user32", EntryPoint="LoadStringA")] private static extern int LoadString(int hInstance, int wID, string lpBuffer, int nBufferMax); public string GetScreenSaverName() { int scrHandle; string scrName = new string( '\0', 25 ); scrHandle = LoadLibrary( @"c:\windows\system32\3d maze.scr" ); LoadString( scrHandle, 1, scrName, 25 ); FreeLibrary( scrHandle ); return scrName.Trim(); } And I can't see anything but a blank text :( What am I do wrong ? Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 26, 2004 Share Posted August 26, 2004 Don't set your entry points to a specific version of the function. Let the interop determine which is best. Set CharSet=CharSet.Auto, instead. The default is Unicode on NT and above, and ANSI on 98 and ME. [DllImport("kernel32.dll", CharSet=CharSet.Auto)] 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