Exemplo n.º 1
0
 /// <summary>
 /// Changes the power mode of the screen to the provided value.
 /// </summary>
 /// <param name="handle">The window handle of the application.</param>
 /// <param name="mode">The mode to set.</param>
 /// <param name="sendMessageCount">Sets how often the SEND command should be sent.</param>
 private static void ChangeScreenPower(int handle, ScreenPowerMode mode, int sendMessageCount = 3)
 {
     if (handle < 0)
     {
         handle = HWND_BROADCAST;
     }
     for (int i = 0; i < sendMessageCount; i++)
     {
         SendMessage(handle, WM_SYSCOMMAND, SC_MONITORPOWER, (int)mode);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Changes the power mode of the screen to the provided value.
        /// </summary>
        /// <param name="window">The window of the application.</param>
        /// <param name="mode">The mode to set.</param>
        /// <param name="sendMessageCount">Sets how often the SEND command should be sent.</param>
        private static void ChangeScreenPower(Window window, ScreenPowerMode mode, int sendMessageCount = 3)
        {
            int handle = HWND_BROADCAST;

            if (window != null)
            {
                var helper = new WindowInteropHelper(window);
                handle = (int)helper.Handle;
            }
            ChangeScreenPower(handle, mode, sendMessageCount);
        }