• 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

    • You pay just $100 per TB with this rare 4TB PCIe Gen4 NVMe SSD deal by Sayan Sen SSDs and GPUs are incredibly hard to get nowadays due to high pricing. Discounts are quite rare which is why we report on them as soon as we spot a good deal. For example AMD's new 9070 GRE was finally up for sale at a very good price of just $500 thanks to a special coupon. Sadly that deal is gone but if you happen to be looking for a 4TB NVMe SSD and can spend around $400 there is a really good offer on sale that you should not miss out on as TeamGroup's 4TB G50 model is on sale for that that price which means you are only paying $100 per TB, a very good deal in the current market (purchase link under the specs table down below). The TeamGroup T-FORCE G50 NVMe SSD is a PCIe Gen4 drive and as such it promises to deliver sequential read speeds of up to 5,000 MB/s, helping accelerate game loading, file transfers, and everyday computing tasks. Since this is a 4TB drive you can use it for a gaming library to take advantage of things like DirectStorage. The SSD features an InnoGrit controller and SLC caching technology to support consistent performance. An ultra-thin, patented graphene heatsink is included to aid in heat dissipation. Get it at the link below: Team Group T-FORCE G50 4TB Internal SSD (TM8FFE004T0C129): $449.99 + $50 off w/ promo code SSF69668, limited offer => $39.99 (Sold and Shipped by Newegg US) Good to know This Amazon deal is U.S. specific, and not available in other regions unless specified. We only use first-party seller links (at the time of article publishing); ensure that you purchase from a first-party seller link only. Check out Today's Deals on Amazon | or our recent tech deals. Become a Prime member (for Students or SNAP) via Neowin Get Prime Access - Prime for half price (for qualifying Medicaid, EBT, SNAP) Subscribe to Prime Video, Audible Plus, Music Unlimited or Kindle Unlimited via Neowin As an Amazon Associate, we earn from qualifying purchases.
    • I agree. I also think Phil stayed too long. They should definitely fire whoever thought all a console platform needed was Call of Duty, Elder Scrolls, and Fallout to survive. Asha and crew are still saying they need more Elder Scrolls and Fallout games. They simply don't get it.
    • Macbook Air is an appealing option, as are plethora of Windows devices with various different CPU's
    • Mozilla highlights Firefox Nova 2026 redesign and more upcoming features with new roadmap by Sayan Sen Last month Mozilla confirmed that Firefox was set to get a major redesign this year. Dubbed "Project Nova", it can already be tested and will roll out to all users later this year.The idea is to keep the browser competitive in a rapidly evolving internet landscape. As such the revamp focuses on improving privacy, usability, performance, accessibility, and customization. Key privacy features including the built-in VPN, private browsing mode, and Enhanced Tracking Protection, will be more visible and easier to manage, while users will have the option to disable AI features entirely through a dedicated kill switch. Additionally, the redesign promises faster page loading, the return of Compact mode, expanded personalization options, and stronger accessibility support. You can find the full details in the dedicated piece linked above. In a new blog post today the company once again reiterated on Nova and also emphasized other new and upcoming features like the settings revamp that is intended to make it easier for users to understand browser settings. In order to make it simpler for users to keep up with such features Mozilla today is launching Firefox roadmap. Hence enthusiasts and interested users will be able to check out what's cooking and also share feedback about the upcoming additions. Alongside the roadmap announcement, Mozilla also highlighted what's new in Firefox 152. One of the biggest additions is the arrival of Tab Groups on Android. The feature, which has already been helping desktop users organize large numbers of tabs, is now beginning to roll out on mobile. Users will be able to group related tabs together, assign names and colors to them, and return to them later. Mozilla says support for iOS will arrive later this year. Firefox 152 also introduces the aforementioned redesigned Settings experience. The company says the changes are meant to make controls easier to find and help users discover features they may not have previously known about. Existing preferences are not changing, though they are now better organized. Another notable addition is the new Blocked Tracker Widget, which provides a visual overview of Firefox's privacy protections by showing how many trackers have been blocked over time and the types of tracking activity the browser has stopped. Looking ahead, Mozilla revealed several upcoming roadmap features. They include customizable keyboard shortcuts, as well as enhanced PDF editing tools that will allow documents to be split, merged, and reorganized directly within Firefox. The company is also working on bringing Multi-Account Containers into the native Firefox experience thus removing the need for a separate extension. Meanwhile Firefox's built-in VPN is set to expand to mobile devices. Mozilla is also developing AI-powered features like Quick Answers, which can provide concise responses to voice queries, and Smart Window, its optional AI browsing experience that is now available without a waitlist. Finally, a new Power Saving Mode is in the works and will help reduce the impact of resource-heavy tabs on mobile devices in order to extend battery life. The video below summarizes the upcoming changes in an easy to understand format: You can find the announcement blog post here on Mozilla's official website.
  • Recent Achievements

    • One Year In
      Console General earned a badge
      One Year In
    • One Year In
      Twozo Technologies earned a badge
      One Year In
    • One Month Later
      Twozo Technologies earned a badge
      One Month Later
    • Week One Done
      Twozo Technologies earned a badge
      Week One Done
    • Veteran
      branfont went up a rank
      Veteran
  • Popular Contributors

    1. 1
      +primortal
      513
    2. 2
      +Edouard
      196
    3. 3
      PsYcHoKiLLa
      109
    4. 4
      Steven P.
      89
    5. 5
      Nick H.
      71
  • Tell a friend

    Love Neowin? Tell a friend!