开发者

How to turn on monitor after wake-up from suspend mode? [closed]

开发者 https://www.devze.com 2022-12-25 21:42 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 5 years ago.

Improve this question

I need to wake up a PC from sleep to perform some actions using C#.

I've used CreateWaitableTimer functions, everything goes fine. At given time the PC wakes up but the monitor stays in power save mode (turned off)!

So I want to know, how to turn the monitor ON after wake up?

PS I've tried "Complete Guide on How To T开发者_运维知识库urn A Monitor On/Off/Standby" - with SendMessage (Codeproject) and SetThreadExecutionState(ES_DISPLAY_REQUIRED) - it doesn't work for me.

Any ideas?


Try making the mouse move. When i wake up my Windows 7 system with a tap on the keyboard the screen stays black until i move the mouse.

Cursor.Position = new Point(x, y);


for me it works fine to use pinvoke to call SendMessage.
code example for csharp:

using System;
using System.Runtime.InteropServices;

namespace MyDummyNamespace
{
   class MyProgram
   {
      private static int Main(string[] args)
      {
         // your program code here
         // ...

         NativeMethods.MonitorOff();
         System.Threading.Thread.Sleep(5000);
         NativeMethods.MonitorOn();

         return 0;
      }

      private static class NativeMethods
      {
         internal static void MonitorOn()
         {
            SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (IntPtr)MONITOR_ON);
         }

         internal static void MonitorOff()
         {
            SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (IntPtr)MONITOR_OFF);
         }

         [DllImport("user32.dll", CharSet = CharSet.Auto)]
         private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

         private static int MONITOR_ON = -1;
         private static int MONITOR_OFF = 2;
         private static int MONITOR_STANBY = 1;

         private static IntPtr HWND_BROADCAST = new IntPtr(0xffff);
         private static UInt32 WM_SYSCOMMAND = 0x0112;
         private static IntPtr SC_MONITORPOWER = new IntPtr(0xF170);
      }
   }
}

the above solution was inspired by this answer: https://stackoverflow.com/a/332733/1468842

0

精彩评论

暂无评论...
验证码 换一张
取 消