Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
To turn on screen saver programmatically, I found the following code(C# .NET framework 3.5) by Googling
C#
[DllImport("User32.dll")]
public static extern int SendMessage
(IntPtr hWnd,
uint Msg,
uint wParam,
uint lParam);
public const uint WM_SYSCOMMAND = 0x112;
public const uint SC_SCREENSAVE = 0xF140;
public enum SpecialHandles
{
HWND_DESKTOP = 0x0,
HWND_BROADCAST = 0xFFFF
}
public static void TurnOnScreenSaver()
{
SendMessage(
new IntPtr((int)SpecialHandles.HWND_BROADCAST),
WM_SYSCOMMAND,
SC_SCREENSAVE,
0);
}

This code works fine to turn on screen saver.

I need another method like TurnOnScreenSaver() that stops the screen saver. I wanna turn on the screen saver first (already done) then on a specific condition I wanna turn off the screen saver and continue the process(on and off). I don't wanna use Timer.
Posted
Updated 11-Oct-10 20:48pm
v2
Comments
Sandeep Mewara 12-Oct-10 2:49am    
Using PRE tags to format code part makes the question readable.

1 solution

Check this[^] link out.
 
Share this answer
 
Comments
akul123 13-Oct-10 1:58am    
Thanks. i visited the page that you referred. But i think it is not so easy as the following method

public static void TurnOnScreenSaver()
{
SendMessage(
new IntPtr((int)SpecialHandles.HWND_BROADCAST),
WM_SYSCOMMAND,
SC_SCREENSAVE,
0);
}

If i could modify this method to turn off screen saver, it would be very much effective.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900