How to turn off the monitor when using C # / WPF (not WinForms!)

I am having a problem 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 to process the form, but I do not use Forms, so I cannot get Handle.

Is there any other way by which I can put the monitor to sleep or get Handle in WPF?

+4
source share
3 answers

To get a handle for using the WPF window:

  new WindowInteropHelper(YourWPFWindow).Handle 

MSDN Link

+5
source

Or use

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

to get a descriptor from one element in the form, is also executed for the whole window.

+3
source

All Articles