【问题标题】:How can I put the monitor to sleep when using C#/WPF (Not WinForms!)使用 C#/WPF(不是 WinForms!)时如何让显示器进入睡眠状态
【发布时间】:2011-12-18 07:31:46
【问题描述】:

我遇到的麻烦是使用...

[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 想要表单的句柄,但我没有使用表单,因此无法获取句柄。

有没有其他方法可以让显示器进入睡眠状态或在 WPF 中获取句柄?

【问题讨论】:

标签: c# wpf


【解决方案1】:

要获取 WPF 窗口的句柄,请使用:

  new WindowInteropHelper(YourWPFWindow).Handle

MSDN reference

【讨论】:

    【解决方案2】:
    【解决方案3】:

    或者使用

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

    要从表单中的单个元素获取句柄,也适用于整个窗口。

    【讨论】:

      猜你喜欢
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-21
      • 2011-05-04
      • 2022-10-18
      相关资源
      最近更新 更多