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