Preventing Screen Saver from Windows Forms application

K

KK

Dear All
I want to prevent the screen saver getting activated when my application is
running.
I have the following code, but still screen saver is activated. What
corrections I should make to prevent screen saver running to the following
code.

public class MainForm : System.Windows.Forms.Form
{
private static readonly int SC_SCREENSAVE = 0xF140;
private static readonly int WM_SYSCOMMAND = 0x0112;
private static readonly int WM_CLOSE = 0x0010;
protected override void WndProc(ref Message m)
{
if (WM_SYSCOMMAND == m.Msg && SC_SCREENSAVE == (int)m.WParam)
{
m.Result = (IntPtr)(-1);
System.Diagnostics.Trace.WriteLine("Screen Saver event handled");
return;
}
base.WndProc(ref m)
}
}

Krishna Rao K Lucid Software Ltd 104, NSIC STP Complex | Guindy Industrial
Estate | Ekkattuthangal | Chennai 600032 ' +91 44 2225 2273 / 76 , +91 98407
28998
 
M

Michael Nemtsev, MVP

Hello KK,

Make P/Invoke call to SystemParametersInfo with SPI_SETSCREENSAVEACTIVE,
setting uiParam = false to disable, true to activate

http://pinvoke.net/default.aspx/user32/SystemParametersInfo.html

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


K> Dear All
K> I want to prevent the screen saver getting activated when my
K> application is
K> running.
K> I have the following code, but still screen saver is activated. What
K> corrections I should make to prevent screen saver running to the
K> following code.
K>
K> public class MainForm : System.Windows.Forms.Form
K> {
K> private static readonly int SC_SCREENSAVE = 0xF140;
K> private static readonly int WM_SYSCOMMAND = 0x0112;
K> private static readonly int WM_CLOSE = 0x0010;
K> protected override void WndProc(ref Message m)
K> {
K> if (WM_SYSCOMMAND == m.Msg && SC_SCREENSAVE == (int)m.WParam)
K> {
K> m.Result = (IntPtr)(-1);
K> System.Diagnostics.Trace.WriteLine("Screen Saver event
K> handled");
K> return;
K> }
K> base.WndProc(ref m)
K> }
K> }
K> Krishna Rao K Lucid Software Ltd 104, NSIC STP Complex | Guindy
K> Industrial Estate | Ekkattuthangal | Chennai 600032 ' +91 44 2225
K> 2273 / 76 , +91 98407 28998
K>
 
K

KK

Hi Nemtsev
Thank you very much. i have small doubt.
When we call SystemParametersInfo as suggested, what's the scope of this
method call.
I mean will it disable the screen saver completly or only during the life
time of my application?
Thanks once again.
 
G

Guest

Well, it should be pretty easy to try it and find out, yes? Let us know.

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



KK said:
Hi Nemtsev
Thank you very much. i have small doubt.
When we call SystemParametersInfo as suggested, what's the scope of this
method call.
I mean will it disable the screen saver completly or only during the life
time of my application?
Thanks once again.

Hello KK,

Make P/Invoke call to SystemParametersInfo with SPI_SETSCREENSAVEACTIVE,
setting uiParam = false to disable, true to activate

http://pinvoke.net/default.aspx/user32/SystemParametersInfo.html

---
WBR, Michael Nemtsev [.NET/C# MVP] :: blog:
http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

K> Dear All
K> I want to prevent the screen saver getting activated when my
K> application is
K> running.
K> I have the following code, but still screen saver is activated. What
K> corrections I should make to prevent screen saver running to the
K> following code.
K> K> public class MainForm : System.Windows.Forms.Form
K> {
K> private static readonly int SC_SCREENSAVE = 0xF140;
K> private static readonly int WM_SYSCOMMAND = 0x0112;
K> private static readonly int WM_CLOSE = 0x0010;
K> protected override void WndProc(ref Message m)
K> {
K> if (WM_SYSCOMMAND == m.Msg && SC_SCREENSAVE == (int)m.WParam)
K> {
K> m.Result = (IntPtr)(-1);
K> System.Diagnostics.Trace.WriteLine("Screen Saver event
K> handled");
K> return;
K> }
K> base.WndProc(ref m)
K> }
K> }
K> Krishna Rao K Lucid Software Ltd 104, NSIC STP Complex | Guindy
K> Industrial Estate | Ekkattuthangal | Chennai 600032 ' +91 44 2225
K> 2273 / 76 , +91 98407 28998
K>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top