Connect with Expertise | Find Experts, Get Answers, Share Insights

Detecting the ScreenSaver State

Anthony
 
Posts: n/a
#1: Nov 16 '05
In C++ you can detect the screensaver state by using something like:

BOOL b=SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, NULL, &bOn, FALSE);

Is there an equivalent method that I can use in C#? If not, how can I
determine the state of the screen saver?

--
-Anthony

Ahmed Qurashi
 
Posts: n/a
#2: Nov 16 '05

re: Detecting the ScreenSaver State


This is from one of the forums, so you can test it yourself, but the idea is
to use interop to get the state from the SPI enum:

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SystemParametersInfo(int uAction,
int uParam, ref int lpvParam, int fuWinIni);

const int SPI_GETSCREENSAVERRUNNING = 114;
int screenSaverRunning = -1;

// is the screen saver running?

int ok = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, ref
screenSaverRunning, 0);

if (ok == 0)
{
Console.WriteLine("Call to SystemParametersInfo failed.");
}

if (screenSaverRunning != 0)
{
// screen saver is running

}

ok,
aq

"Anthony" <Anthony@discussions.microsoft.com> wrote in message
news:F396F6C6-7993-445D-B470-E6033666CAB0@microsoft.com...[color=blue]
> In C++ you can detect the screensaver state by using something like:
>
> BOOL b=SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, NULL, &bOn, FALSE);
>
> Is there an equivalent method that I can use in C#? If not, how can I
> determine the state of the screen saver?
>
> --
> -Anthony[/color]


Anthony
 
Posts: n/a
#3: Nov 16 '05

re: Detecting the ScreenSaver State


Thanks!!! This is what I need

"Ahmed Qurashi" wrote:
[color=blue]
> This is from one of the forums, so you can test it yourself, but the idea is
> to use interop to get the state from the SPI enum:
>
> [DllImport("user32.dll", CharSet=CharSet.Auto)]
> public static extern int SystemParametersInfo(int uAction,
> int uParam, ref int lpvParam, int fuWinIni);
>
> const int SPI_GETSCREENSAVERRUNNING = 114;
> int screenSaverRunning = -1;
>
> // is the screen saver running?
>
> int ok = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, ref
> screenSaverRunning, 0);
>
> if (ok == 0)
> {
> Console.WriteLine("Call to SystemParametersInfo failed.");
> }
>
> if (screenSaverRunning != 0)
> {
> // screen saver is running
>
> }
>
> ok,
> aq
>
> "Anthony" <Anthony@discussions.microsoft.com> wrote in message
> news:F396F6C6-7993-445D-B470-E6033666CAB0@microsoft.com...[color=green]
> > In C++ you can detect the screensaver state by using something like:
> >
> > BOOL b=SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, NULL, &bOn, FALSE);
> >
> > Is there an equivalent method that I can use in C#? If not, how can I
> > determine the state of the screen saver?
> >
> > --
> > -Anthony[/color]
>
>
>[/color]
Closed Thread