发布评论
评论(2)
黄昏下泛黄的笔记2024-09-04 09:37:34
对我来说,使用 pinvoke 调用 SendMessage
效果很好。
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);
}
}
}
上述解决方案受到以下答案的启发:https://stackoverflow.com/a/332733/1468842
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
尝试让鼠标移动。当我通过敲击键盘唤醒 Windows 7 系统时,屏幕会保持黑色,直到我移动鼠标。
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.