简体   繁体   English

使用C#/ WPF(非WinForms!)时如何让显示器进入睡眠状态

[英]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

MSDN reference MSDN参考

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.

相关问题 是否可以使用WinAPI / C#将单个监视器置于睡眠状态? - Is it possible to put a single monitor to sleep using WinAPI/C#? 在C#WinForms中使用解析数据的方法时,如何查找包含异常的行 - How can i find the Line that Contains the exception when Using methods that Parse the Data in C# WinForms C#Winforms使用EF6时如何测试SQL连接? - C# Winforms how can I test for SQL connection when using EF6? 如何使用 WinForms c# 制作加速机制 - How can I make an acceleration mechanic using WinForms c# 如何使用c#监控进程? - How can i monitor the process using c#? C#Winforms:一个可以控制UI并且可以“休眠”而不会暂停整个程序的线程。 怎么样? - C# Winforms: A thread that can control the UI and can “sleep” without pausing the whole program. How? 使用带有枚举项的c#winforms数据绑定时,如何在组合框中获得友好的文本描述? - How can I get friendly text descriptions in a combo box when using c# winforms data binding with enum items? 如何使用WPF C#检测光标何时离开书面文本框 - How can I detect when the cursor leaves a Written Textbox using WPF C# 使用 NSIS 部署 C# Winforms 应用程序时,如何使用 Properties.Settings? - How can I use Properties.Settings when I deploy my C# Winforms app with NSIS? 如何抑制运行 C# Winforms 应用程序时弹出的黑色 Shell? - How Can I Suppress the Black Shell that Pops Up When I Run my C# Winforms Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM