我使用以下代码打开和关闭监视器:

[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);

这过去曾按预期工作,但在安装Windows 8(I assume this is the reason, since I see others have the same issue)之后,无法打开屏幕。我仍然可以关闭它,但是无论我用MonitorTurnOn运行SendMessage()多少次,我仍然必须移动鼠标或按一个键才能重新打开监视器。

关于如何使它在Windows 8上运行的任何建议?

最佳答案

我遇到了同样的问题,发现的解决方案是移动鼠标:

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

它将唤醒监视器。
早珍珠

关于c# - 运行Windows 8时,SendMessage/SC_MONITORPOWER不会打开监视器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12572441/

10-13 08:05