OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / Win32.cs
1 /*  win32.cs $\r
2     This file is part of the HandBrake source code.\r
3     Homepage: <http://handbrake.fr>.\r
4     It may be used under the terms of the GNU General Public License. */\r
5 \r
6 namespace Handbrake.Functions\r
7 {\r
8     using System;\r
9     using System.Runtime.InteropServices;\r
10 \r
11     /// <summary>\r
12     /// Win32 API calls\r
13     /// </summary>\r
14     public class Win32\r
15     {\r
16         /// <summary>\r
17         /// Set the Forground Window\r
18         /// </summary>\r
19         /// <param name="hWnd">\r
20         /// The h wnd.\r
21         /// </param>\r
22         /// <returns>\r
23         /// A Boolean true when complete.\r
24         /// </returns>\r
25         [DllImport("user32.dll")]\r
26         public static extern bool SetForegroundWindow(int hWnd);\r
27 \r
28         /// <summary>\r
29         /// Lock the workstation\r
30         /// </summary>\r
31         [DllImport("user32.dll")]\r
32         public static extern void LockWorkStation();\r
33 \r
34         /// <summary>\r
35         /// Exit Windows\r
36         /// </summary>\r
37         /// <param name="uFlags">\r
38         /// The u flags.\r
39         /// </param>\r
40         /// <param name="dwReason">\r
41         /// The dw reason.\r
42         /// </param>\r
43         /// <returns>\r
44         /// an integer\r
45         /// </returns>\r
46         [DllImport("user32.dll")]\r
47         public static extern int ExitWindowsEx(int uFlags, int dwReason);\r
48 \r
49         /// <summary>\r
50         /// System Memory Status\r
51         /// </summary>\r
52         public struct MEMORYSTATUS // Unused var's are required here.\r
53         {\r
54             /// <summary>\r
55             /// Unknown\r
56             /// </summary>\r
57             public UInt32 dwLength;\r
58 \r
59             /// <summary>\r
60             /// Memory Load\r
61             /// </summary>\r
62             public UInt32 dwMemoryLoad;\r
63 \r
64             /// <summary>\r
65             /// Total Physical Memory\r
66             /// </summary>\r
67             public UInt32 dwTotalPhys; // Used\r
68 \r
69             /// <summary>\r
70             /// Available Physical Memory\r
71             /// </summary>\r
72             public UInt32 dwAvailPhys;\r
73 \r
74             /// <summary>\r
75             /// Total Page File\r
76             /// </summary>\r
77             public UInt32 dwTotalPageFile;\r
78 \r
79             /// <summary>\r
80             /// Available Page File\r
81             /// </summary>\r
82             public UInt32 dwAvailPageFile;\r
83 \r
84             /// <summary>\r
85             /// Total Virtual Memory\r
86             /// </summary>\r
87             public UInt32 dwTotalVirtual;\r
88 \r
89             /// <summary>\r
90             /// Available Virtual Memory\r
91             /// </summary>\r
92             public UInt32 dwAvailVirtual;\r
93         }\r
94 \r
95         /// <summary>\r
96         /// Global Memory Status\r
97         /// </summary>\r
98         /// <param name="lpBuffer">\r
99         /// The lp buffer.\r
100         /// </param>\r
101         [DllImport("kernel32.dll")]\r
102         public static extern void GlobalMemoryStatus(ref MEMORYSTATUS lpBuffer);\r
103 \r
104         /// <summary>\r
105         /// Generate a Console Ctrl Event\r
106         /// </summary>\r
107         /// <param name="sigevent">\r
108         /// The sigevent.\r
109         /// </param>\r
110         /// <param name="dwProcessGroupId">\r
111         /// The dw process group id.\r
112         /// </param>\r
113         /// <returns>\r
114         /// Bool true is sucess\r
115         /// </returns>\r
116         [DllImport("kernel32.dll", SetLastError = true)]\r
117         public static extern bool GenerateConsoleCtrlEvent(ConsoleCtrlEvent sigevent, int dwProcessGroupId);\r
118 \r
119         /// <summary>\r
120         /// Console Ctrl Event\r
121         /// </summary>\r
122         public enum ConsoleCtrlEvent\r
123         {\r
124             /// <summary>\r
125             /// Ctrl - C\r
126             /// </summary>\r
127             CTRL_C = 0,\r
128 \r
129             /// <summary>\r
130             /// Ctrl - Break\r
131             /// </summary>\r
132             CTRL_BREAK = 1,\r
133 \r
134             /// <summary>\r
135             /// Ctrl - Close\r
136             /// </summary>\r
137             CTRL_CLOSE = 2,\r
138         }\r
139 \r
140         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]\r
141         static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);\r
142 \r
143         [FlagsAttribute]\r
144         public enum EXECUTION_STATE : uint\r
145         {\r
146             ES_SYSTEM_REQUIRED = 0x00000001,\r
147             ES_CONTINUOUS = 0x80000000,\r
148             ES_AWAYMODE_REQUIRED = 0x00000040\r
149         }\r
150 \r
151         /// <summary>\r
152         /// Prevent the system from sleeping\r
153         /// </summary>\r
154         public static void PreventSleep()\r
155         {\r
156             SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_AWAYMODE_REQUIRED);\r
157         }\r
158 \r
159         /// <summary>\r
160         ///  Allow the system to sleep.\r
161         /// </summary>\r
162         public static void AllowSleep()\r
163         {\r
164             SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);\r
165         }\r
166     }\r
167 }\r