簡體   English   中英

使用C#/ WPF(非WinForms!)時如何讓顯示器進入睡眠狀態

[英]How can I put the monitor to sleep when using C#/WPF (Not WinForms!)

我遇到的麻煩就是使用......

[DllImport("user32")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

...接着...

SendMessage(???, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)MONITOR_OFF);

SendMessage想要Form的Handle,但我沒有使用Forms,所以無法獲得Handle。

有沒有其他方法可以讓顯示器進入睡眠狀態或獲取WPF中的句柄?

要獲取WPF窗口的句柄,請使用:

  new WindowInteropHelper(YourWPFWindow).Handle

MSDN參考

或者使用

HwndSource source = (HwndSource)HwndSource.FromVisual(this);
source.Handle...

從表單中的單個元素獲取句柄,也運行整個窗口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM