Detecting the ScreenSaver State

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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
 
Thanks!!! This is what I need

Ahmed Qurashi said:
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 said:
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?
 
Back
Top