[英]How can I put the monitor to sleep when using C#/WPF (Not WinForms!)
The trouble I'm having is with using... 我遇到的麻烦就是使用......
[DllImport("user32")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
...and then... ...接着...
SendMessage(???, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)MONITOR_OFF);
SendMessage wants the Form's Handle but I'm not using Forms so cannot get the Handle. SendMessage想要Form的Handle,但我没有使用Forms,所以无法获得Handle。
Is there any other way I can put the monitor to sleep OR get the Handle in WPF? 有没有其他方法可以让显示器进入睡眠状态或获取WPF中的句柄?
To get the Handle for a WPF Window use: 要获取WPF窗口的句柄,请使用:
new WindowInteropHelper(YourWPFWindow).Handle
Or use 或者使用
HwndSource source = (HwndSource)HwndSource.FromVisual(this);
source.Handle...
to get a handle from a single element in the form, also runs for the whole window. 从表单中的单个元素获取句柄,也运行整个窗口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.