Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
886 views
in Technique[技术] by (71.8m points)

c# - SendMessage/SC_MONITORPOWER won't turn monitor ON when running Windows 8

I turn my monitors on and off by using the following code:

[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MONITORPOWER = 0xF170;
private const int MonitorTurnOn = -1;
private const int MonitorShutoff = 2;

//Turn them off
SendMessage(f.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)MonitorShutoff);

//Turn them on
SendMessage(f.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)MonitorTurnOn);

This used to work as intended, but after installing Windows 8 (I assume this is the reason, since I see others have the same issue) turning the screen on won't work. I can still turn it off, but no matter how many times I run SendMessage() with MonitorTurnOn, I still have to move the mouse or press a key to get the monitors back on.

Any suggestions on how to make this work on Windows 8?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had the same problem, the solution I found is to move the mouse :

mouse_event(MOUSEEVENTF_MOVE, 0, 1, 0, NULL);
Sleep(40);
mouse_event(MOUSEEVENTF_MOVE, 0, -1, 0, NULL);

It will wake the monitor on. Earlypearl


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...