• 0

C# Screen saver?


Question

Recommended Posts

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

  • 0

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 by The_Decryptor
  • 0

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.

  • 0

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 by The_Decryptor
  • 0

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.

  • 0

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 by The_Decryptor
  • 0

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

post-47-1093528664.png

Edited by The_Decryptor
  • 0

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 ?

  • 0
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 by weenur
  • 0

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.

  • 0

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 ?

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

    • No registered users viewing this page.
  • Posts

    • Marshall Major V Bluetooth headphones are now up to 47% off on Amazon by Ivan Jenic The Marshall Major V in Midnight Blue is currently $89.99 on Amazon, down from $169.99. That's 47% off and $80 saved on a pair of wireless on-ear headphones from one of the most recognizable names in audio. The Major V is Marshall's take on a long-lasting everyday headphone. The headphones deliver 100+ hours of wireless playtime, which puts them in a completely different category from most Bluetooth headphones that hover around 30-40 hours. You’re charging this thing once a week at most, and with wireless charging supported, you don’t have to worry about additional cables. Marshall promises its signature sound profile, with strong bass, smooth mids, and clear highs. There’s a customizable M-button, which you can set to quickly access Spotify Tap, your EQ settings, or a voice assistant. The design is foldable and lightweight at 186 grams, so it’s easy to pack for travel. And finally, the faux leather finish gives the Major V a sleek, premium look. At $89.99, the Major V Midnight Blue is a genuinely strong buy for anyone who wants a reliable daily headphone without paying premium prices. It’s also worth mentioning that the Cream and Brown variants are also discounted to $89.99, though from a lower original price of $99.99. Marshall Major V Midnight Blue - $89.99 | 47% off on Amazon This Amazon deal is US-specific and not available in other regions unless specified. This is a first-party seller link (at the time of article publishing); ensure that you also purchase from a first-party seller link only. If you don't like it or want to look at more options, check out the previous deals that we have covered, OR you can also visit Amazon US deals page. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • +1 on XVI. I still use it. 
    • Age 16, old enough to get a full-time job, your own bank account, a passport, get married, even join the military and go to war. But talking to your friends on the internet? Oh hell no!
    • I remember when all games had demos; it was a normal thing, not a limited time promotion.
    • Forza Horizon 6 gets big bug-fixing and balancing update by Taras Buria Today, Playground Games released a big Forza Horizon 6 update with a long list of fixes, patches, and balancing tweaks that the studio promised earlier. Version 375.327 is now available on Steam, Microsoft Store, and Xbox, offering users improvements for AI, audio, design, performance, road discovery, upgrades, visuals, online play, and more. Some of the most notable changes in the Series 2 update include rebalanced drivatars, particularly their difficulty and race start behavior. As such, the game should be more balanced on higher difficulty levels, and AI cars should not shoot out when the race starts as if they have rocket boosters. Speaking of difficulty, developers nerfed Drag Tires physics for a more expected and realistic behavior. They are no longer the go-to option for record-breaking times in road racing, and all leaderboard entries with drag tires will be removed. Completionists will also be glad to get a new feature that lets you see road discovery percentage in each region, which should make discovering all roads easier while keeping it quite challenging and interesting (I spent quite a long time finding the last road). Festival Playlist is also getting some much-needed fixes, including patches for bugs that allowed completing Seasonal Jobs ahead of time or where weekly challenges would not unlock for some players. Developers will retroactively give reward points to all who could not complete all challenges due to these bugs. Other changes include changes to Horizon Play progression so that it is easier to reach Level 100, audio improvements on lower-spec devices, fixes for visual glitches, including pixelated smoke, and more. Developers also addressed the currently non-working Eliminator, an online mode gamers used to farm credits with a Hummer EV exploit. Playground Games plans to re-enable it soon. As a gesture of goodwill, players will get a free McLaren Sabre. Those who used the exploit will not be banned, but developers plan to roll back credits to a maximum of 10M for all who farmed credits using the exploit. You can find the complete changelog for the latest Forza Horizon 6 update here.
  • Recent Achievements

    • First Post
      Cosminus earned a badge
      First Post
    • One Year In
      ThatGuyOnline earned a badge
      One Year In
    • 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
  • Popular Contributors

    1. 1
      +primortal
      484
    2. 2
      +Edouard
      185
    3. 3
      PsYcHoKiLLa
      122
    4. 4
      Steven P.
      83
    5. 5
      neufuse
      73
  • Tell a friend

    Love Neowin? Tell a friend!