/* 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.ApplicationServices.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); /// /// Memory Status EX Struct /// public struct MEMORYSTATUSEX { public int dwLength; public int dwMemoryLoad; public ulong ullTotalPhys; public ulong ullAvailPhys; public ulong ullTotalPageFile; public ulong ullAvailPageFile; public ulong ullTotalVirtual; public ulong ullAvailVirtual; public ulong ullAvailExtendedVirtual; } /// /// Get the System Memory information /// /// /// The lp buffer. /// /// /// A boolean. /// [DllImport("kernel32.dll", SetLastError = true)] public static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX 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); /// /// Execution State /// [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); } } }