Beispiel #1
0
        /// <summary>
        /// Register for event notifications
        /// </summary>
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            // WtsRegisterSessionNotification requires Windows XP or higher
            bool haveXp = Environment.OSVersion.Platform == PlatformID.Win32NT &&
                          (Environment.OSVersion.Version.Major > 5 ||
                           (Environment.OSVersion.Version.Major == 5 &&
                            Environment.OSVersion.Version.Minor >= 1));


            if (haveXp)
            {
                log.Info("Registering session notification to WindowsXP");
                registered = Win32Helper.WTSRegisterSessionNotification(Handle, Win32Helper.NOTIFY_FOR_THIS_SESSION);
            }
            log.Debug("Start HWND: " + Handle.ToString());

            return;
        }
 public static void TurnOff(IntPtr hwnd)
 {
     log.Debug("Hwnd " + hwnd + " Turning off monitor...");
     Win32Helper.SendMessage(hwnd, (uint)WindowsMessages.WM_SYSCOMMAND, (int)SysCommands.SC_MONITORPOWER, Win32Helper.MONITOR_OFF_PARAM);
     log.Debug("Turned off monitor");
 }
 /// <summary>
 /// Turn on computer monitor.
 /// </summary>
 /// <remarks>
 /// In fact this API could never be called. When computer get any input (Keyboard, mouse, network), the monitor will be opned automatically at first.
 /// </remarks>
 public static void TurnOn()
 {
     Win32Helper.PostMessage(Win32Helper.HWND_BROADCAST, (uint)WindowsMessages.WM_SYSCOMMAND, (int)SysCommands.SC_MONITORPOWER, Win32Helper.MONITOR_ON_PARAM);
 }