/* win32.cs $ This file is part of the HandBrake source code. Homepage: . It may be used under the terms of the GNU General Public License. */ namespace Handbrake.Functions { using System; using System.Runtime.InteropServices; /// /// Win32 API calls /// public class Win32 { /// /// Set the Forground Window /// /// /// The h wnd. /// /// /// A Boolean true when complete. /// [DllImport("user32.dll")] public static extern bool SetForegroundWindow(int hWnd); /// /// Lock the workstation /// [DllImport("user32.dll")] public static extern void LockWorkStation(); /// /// Exit Windows /// /// /// The u flags. /// /// /// The dw reason. /// /// /// an integer /// [DllImport("user32.dll")] public static extern int ExitWindowsEx(int uFlags, int dwReason); /// /// System Memory Status /// public struct MEMORYSTATUS // Unused var's are required here. { /// /// Unknown /// public UInt32 dwLength; /// /// Memory Load /// public UInt32 dwMemoryLoad; /// /// Total Physical Memory /// public UInt32 dwTotalPhys; // Used /// /// Available Physical Memory /// public UInt32 dwAvailPhys; /// /// Total Page File /// public UInt32 dwTotalPageFile; /// /// Available Page File /// public UInt32 dwAvailPageFile; /// /// Total Virtual Memory /// public UInt32 dwTotalVirtual; /// /// Available Virtual Memory /// public UInt32 dwAvailVirtual; } /// /// Global Memory Status /// /// /// The lp buffer. /// [DllImport("kernel32.dll")] public static extern void GlobalMemoryStatus ( ref MEMORYSTATUS lpBuffer ); /// /// Generate a Console Ctrl Event /// /// /// The sigevent. /// /// /// The dw process group id. /// /// /// Bool true is sucess /// [DllImport("kernel32.dll", SetLastError = true)] public static extern bool GenerateConsoleCtrlEvent(ConsoleCtrlEvent sigevent, int dwProcessGroupId); /// /// Console Ctrl Event /// public enum ConsoleCtrlEvent { /// /// Ctrl - C /// CTRL_C = 0, /// /// Ctrl - Break /// CTRL_BREAK = 1, /// /// Ctrl - Close /// CTRL_CLOSE = 2, } [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags); [FlagsAttribute] public enum EXECUTION_STATE : uint { ES_SYSTEM_REQUIRED = 0x00000001, ES_CONTINUOUS = 0x80000000, ES_AWAYMODE_REQUIRED = 0x00000040 } /// /// Prevent the system from sleeping /// public static void PreventSleep() { SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_AWAYMODE_REQUIRED); } /// /// Allow the system to sleep. /// public static void AllowSleep() { SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS); } } }