Wake monitor from sleep... updated method
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: Wake monitor from sleep... updated method

  1. #1
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Wake monitor from sleep... updated method

    Hi everyone:


    I need to wake a system monitor from sleep (when it was turned off automatically by OS after a certain time of inactivity). Is there any documented way to do it under Windows 7?

    PS. There's a lot on this subject on this forum but most of it is stuff written for Windows XP or earlier.

  2. #2
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Wake monitor from sleep... updated method

    Any ideas, guys???

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,070

    Re: Wake monitor from sleep... updated method

    These two ways seem working fine in my Win 7. Though I'm not sure (or better, don't care) whether these are documented/recommended for Win 7.

    1) Set up monitor to power down in 1 min. Build the app, run it and leave the system idle. In 1 min the monitor goes off, 1 min later it wakes up.
    2) Click the window, and monitor goes off. 10 seconds later it wakes up.

    For the first case I tested this having the app foreground/background, and all the times it worked fine.
    Attached Files Attached Files
    Best regards,
    Igor

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,101

    Re: Wake monitor from sleep... updated method

    OK, firstly don't shoot me, I come in peace

    What if we can totally prevent the PC from going into sleep mode, throughout the use of our application? What I'm trying to say is that you can use the SetThreadExecutionState Api with the ES_DISPLAY_REQUIRED + ES_CONTINUOUS constants to ensure that the monitor doesn't go into sleep mode while your program is running. Then, whilst exiting your app, you could use the same API only with the ES_CONTINUOUS constant

    Just an idea....

  5. #5
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Wake monitor from sleep... updated method

    Quote Originally Posted by Igor Vartanov View Post
    These two ways seem working fine in my Win 7.
    Thanks. I was really amazed at how you were able to strip down the MFC code down to a bare minimum. Very professional...

    As for the code to wake the screen and to turn it off, I see that you're using an older technique. But honestly, I'm really leery about using it these days. Here's the result of my tests and two very serious flaws:
    (So I'm curious if you addressed it in your software if you use it there as well?)

    1. I ran it on my Dell Inspiron 1750 laptop of 1.5 years with Vista Home installed and although the code to turn off the screen does the job, it works only for a short while and the screen comes back on again in a second or so. I spent a good deal of time trying to understand why this happens, and... I have no clue. But, on the side note, that OS... I don't know how is it still around...

    2. I also ran it on my desktop with Windows 7 Ultimate installed and it worked as you intended except for one very essential situation when a user had a password protected screensaver. In that case your code to turn on screen did nothing. As I suspected they upped security on password protected screensaver that is now running in its own isolated session with virtually no privileges and ignores pretty much all messages that could be sent to it (as was used in almost all previous approaches of canceling it in Windows XP). Again, I tried to fix it but couldn't....


    Quote Originally Posted by HanneSThEGreaT View Post
    What if we can totally prevent the PC from going into sleep mode, throughout the use of our application?
    This is a very wrong approach and I hope that you don't use it in your software! Doing that will totally circumvent any power saving settings that a user might have set up. From my own experience as a software user, if I see a piece of code messing with my screen saver, or any other power saving settings, that code goes straight into trash.

    My intentions here are just to wake the screen up to show a quick note for a user and I'm not intending to keep the screen on afterwards.

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,101

    Re: Wake monitor from sleep... updated method

    Quote Originally Posted by ahmd View Post
    This is a very wrong approach and I hope that you don't use it in your software! Doing that will totally circumvent any power saving settings that a user might have set up. From my own experience as a software user, if I see a piece of code messing with my screen saver, or any other power saving settings, that code goes straight into trash.

    My intentions here are just to wake the screen up to show a quick note for a user and I'm not intending to keep the screen on afterwards.
    Technically, it is what exactly you're doing now: messing with the screen saver ( power saver settings ) in this situation, strange...

    There are plenty of major programs from major software vendors doing exactly as I have described, an example would be most setup applications - some would keep the screen "active" until the installation has been successfully done, then only, "deactivate" the screen, and programs such as Nero and DVD fab. Seen it a million times, and counting

    I was just trying to help with a possible solution, that is all I was trying to do

    Hannes

  7. #7
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Wake monitor from sleep... updated method

    Quote Originally Posted by HanneSThEGreaT View Post
    Technically, it is what exactly you're doing now
    OK, Hannes, I evidently misunderstood you and I apologize. Yes, any program that performs a lengthy operation that involves a hard drive, a CD, DVD or a download must hold off computer's automatic power saving settings. But that is not what I was trying to achieve. In my case all I need is to wake up the screen (note, temporarily) to display a quick message for a user.

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,101

    Re: Wake monitor from sleep... updated method

    No problem at all

  9. #9
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,553

    Re: Wake monitor from sleep... updated method

    Quote Originally Posted by ahmd View Post
    ... In my case all I need is to wake up the screen (note, temporarily) to display a quick message for a user.
    If the user has password-protected screen lock, he is likely NOT in front of his monitor. Who do you think will read your message then?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,070

    Re: Wake monitor from sleep... updated method

    As for the code to wake the screen and to turn it off, I see that you're using an older technique.
    As for waking monitor up (as the subject asks for) I doubt if it matters somehow how old the techniques are. What really matters is if they work.

    it worked as you intended except for one very essential situation
    Yeah, and you said nothing about the situation before.

    Besides, showing messages on a logon screen (or unlocking the desktop, or stopping screensaver) has nothing to do with waking monitor from sleep.
    Best regards,
    Igor

  11. #11
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Wake monitor from sleep... updated method

    Waking up the monitor just for the message seems not so good idea, if the user is there he/she will anyway wakeup the monitor by pressing keys and then automatically see the message. So I would suggest going with not allowing the power down while the program needs monitor OR letting things happen as they are happening right now.
    Regards,
    Ramkrishna Pawar

  12. #12
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,070

    Re: Wake monitor from sleep... updated method

    1. I ran it on my Dell Inspiron 1750 laptop of 1.5 years with Vista Home installed and although the code to turn off the screen does the job, it works only for a short while and the screen comes back on again in a second or so. I spent a good deal of time trying to understand why this happens, and... I have no clue. But, on the side note, that OS... I don't know how is it still around...
    Just tested the app with Vista Ultimate. It worked like a charm in both cases. Well, I wasn't surprised. (Seems something in your Vista does some anti-sleep thing(s) like mouse or keyboard input imitation, or you just moved your mouse unintentionally.)
    Best regards,
    Igor

  13. #13
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,070

    Re: Wake monitor from sleep... updated method

    This is a very wrong approach and I hope that you don't use it in your software! Doing that will totally circumvent any power saving settings that a user might have set up.
    There is a very special sort of software that desperately needs this kind of things: media players.
    Last edited by Igor Vartanov; April 5th, 2011 at 01:33 PM.
    Best regards,
    Igor

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,070

    Re: Wake monitor from sleep... updated method

    In my case all I need is to wake up the screen (note, temporarily) to display a quick message for a user.
    As far as I remember, it's something medical, your software. Did you think about alerting personal with audio message sent for example to bluetooth headset/speaker? Or sending text message to cellphone? Calling skype contact? These seem way more reliable in the situations when the personal may be not around, or the monitor is out of sight.
    Best regards,
    Igor

  15. #15
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Wake monitor from sleep... updated method

    Guys, I can't find a consensus here. It might be my Vista and whatever software came pre-installed with Dell that doesn't let your code, Igor work. It beats me.

    As for password protected screensaver, I didn't mention that the software I need it for is a custom built energy saver that comes with my own screen saver so I have control over a message that is displayed (in the screensaver itself). The idea of waking a monitor up is to show the warning for a user that the system is about to enter a low-power state (and in some cases log off a user -- whatever they configure it for). This request came from a client so I can't really argue with it...

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center