Reputation: 1756
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.
Is there any other way I can put the monitor to sleep OR get the Handle in WPF?
Upvotes: 4
Views: 714
Reputation: 70369
To get the Handle for a WPF Window use:
new WindowInteropHelper(YourWPFWindow).Handle
Upvotes: 5
Reputation: 1563
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.
Upvotes: 3