2 using System.Collections.Generic;
4 using System.Runtime.InteropServices;
13 public const int S_OK = 0x00000000;
14 public const int S_FALSE = 0x00000001;
15 public const int E_FAIL = unchecked( (int) 0x80004005 );
16 public const int E_ABORT = unchecked( (int) 0x80004004 );
18 public const int BROADCAST_QUERY_DENY = 0x424d5144;
20 public const uint CALLBACK_FUNCTION = 0x30000;
21 public const uint ES_CONTINUOUS = 0x80000000;
22 public const uint ES_DISPLAY_REQUIRED = 2;
23 public const uint ES_SYSTEM_REQUIRED = 1;
24 public const uint ES_USER_PRESENT = 4;
26 public const int GWL_EXSTYLE = -20;
27 public const int GWL_HINSTANCE = -6;
28 public const int GWL_HWNDPARENT = -8;
29 public const int GWL_ID = -12;
30 public const int GWL_STYLE = -16;
31 public const int GWL_USERDATA = -21;
32 public const int GWL_WNDPROC = -4;
34 public static readonly IntPtr HWND_NOTOPMOST = new IntPtr( -2 );
35 public static readonly IntPtr HWND_TOPMOST = new IntPtr( -1 );
36 public const uint MAXPNAMELEN = 0x20;
39 public const uint MIM_CLOSE = 0x3c2;
40 public const uint MIM_DATA = 0x3c3;
41 public const uint MIM_ERROR = 0x3c5;
42 public const uint MIM_LONGDATA = 0x3c4;
43 public const uint MIM_LONGERROR = 0x3c6;
44 public const uint MIM_OPEN = 0x3c1;
47 public const int MONITOR_DEFAULTTOPRIMARY = 1;
49 public const int PBT_APMQUERYSTANDBY = 1;
50 public const int PBT_APMQUERYSUSPEND = 0;
52 public const int SC_MONITORPOWER = 0xf170;
53 public const int SC_SCREENSAVE = 0xf140;
55 public const int SIZE_MAXIMIZED = 2;
56 public const int SIZE_MINIMIZED = 1;
57 public const int SIZE_RESTORED = 0;
59 public const uint SWP_FRAMECHANGED = 0x20;
60 public const uint SWP_HIDEWINDOW = 0x80;
61 public const uint SWP_NOACTIVATE = 0x10;
62 public const uint SWP_NOCOPYBITS = 0x100;
63 public const uint SWP_NOMOVE = 2;
64 public const uint SWP_NOOWNERZORDER = 0x200;
65 public const uint SWP_NOREDRAW = 8;
66 public const uint SWP_NOSENDCHANGING = 0x400;
67 public const uint SWP_NOSIZE = 1;
68 public const uint SWP_NOZORDER = 4;
69 public const uint SWP_SHOWWINDOW = 0x40;
71 public const uint PM_NOREMOVE = 0;
72 public const uint PM_REMOVE = 1;
74 #region [ DirectShow, VFW 関連 ]
76 public const int S_WARN_OUTPUTRESET = 0x00009DD4;
77 public const int E_NOTINTREE = unchecked( (int) 0x80040400 );
78 public const int E_RENDER_ENGINE_IS_BROKEN = unchecked( (int) 0x80040401 );
79 public const int E_MUST_INIT_RENDERER = unchecked( (int) 0x80040402 );
80 public const int E_NOTDETERMINED = unchecked( (int) 0x80040403 );
81 public const int E_NO_TIMELINE = unchecked( (int) 0x80040404 );
83 public const int VFW_E_INVALIDMEDIATYPE = unchecked( (int) 0x80040200 );
84 public const int VFW_E_INVALIDSUBTYPE = unchecked( (int) 0x80040201 );
85 public const int VFW_E_NEED_OWNER = unchecked( (int) 0x80040202 );
86 public const int VFW_E_ENUM_OUT_OF_SYNC = unchecked( (int) 0x80040203 );
87 public const int VFW_E_ALREADY_CONNECTED = unchecked( (int) 0x80040204 );
88 public const int VFW_E_FILTER_ACTIVE = unchecked( (int) 0x80040205 );
89 public const int VFW_E_NO_TYPES = unchecked( (int) 0x80040206 );
90 public const int VFW_E_NO_ACCEPTABLE_TYPES = unchecked( (int) 0x80040207 );
91 public const int VFW_E_INVALID_DIRECTION = unchecked( (int) 0x80040208 );
92 public const int VFW_E_NOT_CONNECTED = unchecked( (int) 0x80040209 );
93 public const int VFW_E_NO_ALLOCATOR = unchecked( (int) 0x8004020A );
94 public const int VFW_E_RUNTIME_ERROR = unchecked( (int) 0x8004020B );
95 public const int VFW_E_BUFFER_NOTSET = unchecked( (int) 0x8004020C );
96 public const int VFW_E_BUFFER_OVERFLOW = unchecked( (int) 0x8004020D );
97 public const int VFW_E_BADALIGN = unchecked( (int) 0x8004020E );
98 public const int VFW_E_ALREADY_COMMITTED = unchecked( (int) 0x8004020F );
99 public const int VFW_E_BUFFERS_OUTSTANDING = unchecked( (int) 0x80040210 );
100 public const int VFW_E_NOT_COMMITTED = unchecked( (int) 0x80040211 );
101 public const int VFW_E_SIZENOTSET = unchecked( (int) 0x80040212 );
102 public const int VFW_E_NO_CLOCK = unchecked( (int) 0x80040213 );
103 public const int VFW_E_NO_SINK = unchecked( (int) 0x80040214 );
104 public const int VFW_E_NO_INTERFACE = unchecked( (int) 0x80040215 );
105 public const int VFW_E_NOT_FOUND = unchecked( (int) 0x80040216 );
106 public const int VFW_E_CANNOT_CONNECT = unchecked( (int) 0x80040217 );
107 public const int VFW_E_CANNOT_RENDER = unchecked( (int) 0x80040218 );
108 public const int VFW_E_CHANGING_FORMAT = unchecked( (int) 0x80040219 );
109 public const int VFW_E_NO_COLOR_KEY_SET = unchecked( (int) 0x8004021A );
110 public const int VFW_E_NOT_OVERLAY_CONNECTION = unchecked( (int) 0x8004021B );
111 public const int VFW_E_NOT_SAMPLE_CONNECTION = unchecked( (int) 0x8004021C );
112 public const int VFW_E_PALETTE_SET = unchecked( (int) 0x8004021D );
113 public const int VFW_E_COLOR_KEY_SET = unchecked( (int) 0x8004021E );
114 public const int VFW_E_NO_COLOR_KEY_FOUND = unchecked( (int) 0x8004021F );
115 public const int VFW_E_NO_PALETTE_AVAILABLE = unchecked( (int) 0x80040220 );
116 public const int VFW_E_NO_DISPLAY_PALETTE = unchecked( (int) 0x80040221 );
117 public const int VFW_E_TOO_MANY_COLORS = unchecked( (int) 0x80040222 );
118 public const int VFW_E_STATE_CHANGED = unchecked( (int) 0x80040223 );
119 public const int VFW_E_NOT_STOPPED = unchecked( (int) 0x80040224 );
120 public const int VFW_E_NOT_PAUSED = unchecked( (int) 0x80040225 );
121 public const int VFW_E_NOT_RUNNING = unchecked( (int) 0x80040226 );
122 public const int VFW_E_WRONG_STATE = unchecked( (int) 0x80040227 );
123 public const int VFW_E_START_TIME_AFTER_END = unchecked( (int) 0x80040228 );
124 public const int VFW_E_INVALID_RECT = unchecked( (int) 0x80040229 );
125 public const int VFW_E_TYPE_NOT_ACCEPTED = unchecked( (int) 0x8004022A );
126 public const int VFW_E_SAMPLE_REJECTED = unchecked( (int) 0x8004022B );
127 public const int VFW_E_SAMPLE_REJECTED_EOS = unchecked( (int) 0x8004022C );
128 public const int VFW_E_DUPLICATE_NAME = unchecked( (int) 0x8004022D );
129 public const int VFW_S_DUPLICATE_NAME = 0x0004022D;
130 public const int VFW_E_TIMEOUT = unchecked( (int) 0x8004022E );
131 public const int VFW_E_INVALID_FILE_FORMAT = unchecked( (int) 0x8004022F );
132 public const int VFW_E_ENUM_OUT_OF_RANGE = unchecked( (int) 0x80040230 );
133 public const int VFW_E_CIRCULAR_GRAPH = unchecked( (int) 0x80040231 );
134 public const int VFW_E_NOT_ALLOWED_TO_SAVE = unchecked( (int) 0x80040232 );
135 public const int VFW_E_TIME_ALREADY_PASSED = unchecked( (int) 0x80040233 );
136 public const int VFW_E_ALREADY_CANCELLED = unchecked( (int) 0x80040234 );
137 public const int VFW_E_CORRUPT_GRAPH_FILE = unchecked( (int) 0x80040235 );
138 public const int VFW_E_ADVISE_ALREADY_SET = unchecked( (int) 0x80040236 );
139 public const int VFW_S_STATE_INTERMEDIATE = 0x00040237;
140 public const int VFW_E_NO_MODEX_AVAILABLE = unchecked( (int) 0x80040238 );
141 public const int VFW_E_NO_ADVISE_SET = unchecked( (int) 0x80040239 );
142 public const int VFW_E_NO_FULLSCREEN = unchecked( (int) 0x8004023A );
143 public const int VFW_E_IN_FULLSCREEN_MODE = unchecked( (int) 0x8004023B );
144 public const int VFW_E_UNKNOWN_FILE_TYPE = unchecked( (int) 0x80040240 );
145 public const int VFW_E_CANNOT_LOAD_SOURCE_FILTER = unchecked( (int) 0x80040241 );
146 public const int VFW_S_PARTIAL_RENDER = 0x00040242;
147 public const int VFW_E_FILE_TOO_SHORT = unchecked( (int) 0x80040243 );
148 public const int VFW_E_INVALID_FILE_VERSION = unchecked( (int) 0x80040244 );
149 public const int VFW_S_SOME_DATA_IGNORED = 0x00040245;
150 public const int VFW_S_CONNECTIONS_DEFERRED = 0x00040246;
151 public const int VFW_E_INVALID_CLSID = unchecked( (int) 0x80040247 );
152 public const int VFW_E_INVALID_MEDIA_TYPE = unchecked( (int) 0x80040248 );
153 public const int VFW_E_SAMPLE_TIME_NOT_SET = unchecked( (int) 0x80040249 );
154 public const int VFW_S_RESOURCE_NOT_NEEDED = 0x00040250;
155 public const int VFW_E_MEDIA_TIME_NOT_SET = unchecked( (int) 0x80040251 );
156 public const int VFW_E_NO_TIME_FORMAT_SET = unchecked( (int) 0x80040252 );
157 public const int VFW_E_MONO_AUDIO_HW = unchecked( (int) 0x80040253 );
158 public const int VFW_S_MEDIA_TYPE_IGNORED = 0x00040254;
159 public const int VFW_E_NO_DECOMPRESSOR = unchecked( (int) 0x80040255 );
160 public const int VFW_E_NO_AUDIO_HARDWARE = unchecked( (int) 0x80040256 );
161 public const int VFW_S_VIDEO_NOT_RENDERED = 0x00040257;
162 public const int VFW_S_AUDIO_NOT_RENDERED = 0x00040258;
163 public const int VFW_E_RPZA = unchecked( (int) 0x80040259 );
164 public const int VFW_S_RPZA = 0x0004025A;
165 public const int VFW_E_PROCESSOR_NOT_SUITABLE = unchecked( (int) 0x8004025B );
166 public const int VFW_E_UNSUPPORTED_AUDIO = unchecked( (int) 0x8004025C );
167 public const int VFW_E_UNSUPPORTED_VIDEO = unchecked( (int) 0x8004025D );
168 public const int VFW_E_MPEG_NOT_CONSTRAINED = unchecked( (int) 0x8004025E );
169 public const int VFW_E_NOT_IN_GRAPH = unchecked( (int) 0x8004025F );
170 public const int VFW_S_ESTIMATED = 0x00040260;
171 public const int VFW_E_NO_TIME_FORMAT = unchecked( (int) 0x80040261 );
172 public const int VFW_E_READ_ONLY = unchecked( (int) 0x80040262 );
173 public const int VFW_S_RESERVED = 0x00040263;
174 public const int VFW_E_BUFFER_UNDERFLOW = unchecked( (int) 0x80040264 );
175 public const int VFW_E_UNSUPPORTED_STREAM = unchecked( (int) 0x80040265 );
176 public const int VFW_E_NO_TRANSPORT = unchecked( (int) 0x80040266 );
177 public const int VFW_S_STREAM_OFF = 0x00040267;
178 public const int VFW_S_CANT_CUE = 0x00040268;
179 public const int VFW_E_BAD_VIDEOCD = unchecked( (int) 0x80040269 );
180 public const int VFW_S_NO_STOP_TIME = 0x00040270;
181 public const int VFW_E_OUT_OF_VIDEO_MEMORY = unchecked( (int) 0x80040271 );
182 public const int VFW_E_VP_NEGOTIATION_FAILED = unchecked( (int) 0x80040272 );
183 public const int VFW_E_DDRAW_CAPS_NOT_SUITABLE = unchecked( (int) 0x80040273 );
184 public const int VFW_E_NO_VP_HARDWARE = unchecked( (int) 0x80040274 );
185 public const int VFW_E_NO_CAPTURE_HARDWARE = unchecked( (int) 0x80040275 );
186 public const int VFW_E_DVD_OPERATION_INHIBITED = unchecked( (int) 0x80040276 );
187 public const int VFW_E_DVD_INVALIDDOMAIN = unchecked( (int) 0x80040277 );
188 public const int VFW_E_DVD_NO_BUTTON = unchecked( (int) 0x80040278 );
189 public const int VFW_E_DVD_GRAPHNOTREADY = unchecked( (int) 0x80040279 );
190 public const int VFW_E_DVD_RENDERFAIL = unchecked( (int) 0x8004027A );
191 public const int VFW_E_DVD_DECNOTENOUGH = unchecked( (int) 0x8004027B );
192 public const int VFW_E_DVD_NOT_IN_KARAOKE_MODE = unchecked( (int) 0x8004028B );
193 public const int VFW_E_FRAME_STEP_UNSUPPORTED = unchecked( (int) 0x8004028E );
194 public const int VFW_E_PIN_ALREADY_BLOCKED_ON_THIS_THREAD = unchecked( (int) 0x80040293 );
195 public const int VFW_E_PIN_ALREADY_BLOCKED = unchecked( (int) 0x80040294 );
196 public const int VFW_E_CERTIFICATION_FAILURE = unchecked( (int) 0x80040295 );
197 public const int VFW_E_BAD_KEY = unchecked( (int) 0x800403F2 );
201 #region [ Windowsメッセージ ]
202 public const uint WM_ACTIVATEAPP = 0x1c;
203 public const uint WM_COPYDATA = 0x4a;
204 public const uint WM_CLOSE = 0x10;
205 public const uint WM_POWERBROADCAST = 0x218;
206 public const uint WM_SIZE = 5;
207 public const uint WM_SYSCOMMAND = 0x112;
208 public const uint WM_SYSKEYDOWN = 260;
209 public const uint WM_APP = 0x00008000;
210 public const uint WM_QUIT = 0x12;
211 public const uint WPF_RESTORETOMAXIMIZED = 2;
214 #region [ WindowsStyle フラグ]
215 public const long WS_BORDER = 0x800000L;
216 public const long WS_CAPTION = 0xc00000L;
217 public const long WS_CHILD = 0x40000000L;
218 public const long WS_CHILDWINDOW = 0x40000000L;
219 public const long WS_CLIPCHILDREN = 0x2000000L;
220 public const long WS_CLIPSIBLINGS = 0x4000000L;
221 public const long WS_DISABLED = 0x8000000L;
222 public const long WS_DLGFRAME = 0x400000L;
223 public const long WS_GROUP = 0x20000L;
224 public const long WS_HSCROLL = 0x100000L;
225 public const long WS_ICONIC = 0x20000000L;
226 public const long WS_MAXIMIZE = 0x1000000L;
227 public const long WS_MAXIMIZEBOX = 0x10000L;
228 public const long WS_MINIMIZE = 0x20000000L;
229 public const long WS_MINIMIZEBOX = 0x20000L;
230 public const long WS_OVERLAPPED = 0L;
231 public const long WS_OVERLAPPEDWINDOW = 0xcf0000L;
232 public const long WS_POPUP = 0x80000000L;
233 public const long WS_POPUPWINDOW = 0x80880000L;
234 public const long WS_SIZEBOX = 0x40000L;
235 public const long WS_SYSMENU = 0x80000L;
236 public const long WS_TABSTOP = 0x10000L;
237 public const long WS_THICKFRAME = 0x40000L;
238 public const long WS_TILED = 0L;
239 public const long WS_TILEDWINDOW = 0xcf0000L;
240 public const long WS_VISIBLE = 0x10000000L;
241 public const long WS_VSCROLL = 0x200000L;
242 public const long WS_EX_ACCEPTFILES = 0x10L;
243 public const long WS_EX_APPWINDOW = 0x40000L;
244 public const long WS_EX_CLIENTEDGE = 0x200L;
245 public const long WS_EX_COMPOSITED = 0x2000000L;
246 public const long WS_EX_CONTEXTHELP = 0x400L;
247 public const long WS_EX_CONTROLPARENT = 0x10000L;
248 public const long WS_EX_DLGMODALFRAME = 1L;
249 public const long WS_EX_LAYERED = 0x80000L;
250 public const long WS_EX_LAYOUTRTL = 0x400000L;
251 public const long WS_EX_LEFT = 0L;
252 public const long WS_EX_LEFTSCROLLBAR = 0x4000L;
253 public const long WS_EX_LTRREADING = 0L;
254 public const long WS_EX_MDICHILD = 0x40L;
255 public const long WS_EX_NOACTIVATE = 0x8000000L;
256 public const long WS_EX_NOINHERITLAYOUT = 0x100000L;
257 public const long WS_EX_NOPARENTNOTIFY = 4L;
258 public const long WS_EX_OVERLAPPEDWINDOW = 0x300L;
259 public const long WS_EX_PALETTEWINDOW = 0x188L;
260 public const long WS_EX_RIGHT = 0x1000L;
261 public const long WS_EX_RIGHTSCROLLBAR = 0L;
262 public const long WS_EX_RTLREADING = 0x2000L;
263 public const long WS_EX_STATICEDGE = 0x20000L;
264 public const long WS_EX_TOOLWINDOW = 0x80L;
265 public const long WS_EX_TOPMOST = 8L;
266 public const long WS_EX_TRANSPARENT = 0x20L;
267 public const long WS_EX_WINDOWEDGE = 0x100L;
271 public enum EShowWindow
313 internal enum ExecutionState : uint
315 Null = 0, // 関数が失敗した時の戻り値
316 SystemRequired = 1, // スタンバイを抑止
317 DisplayRequired = 2, // 画面OFFを抑止
318 Continuous = 0x80000000, // 効果を永続させる。ほかオプションと併用する。
325 [return: MarshalAs( UnmanagedType.Bool )]
326 [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
327 public static extern bool AdjustWindowRect( ref RECT lpRect, uint dwStyle, [MarshalAs( UnmanagedType.Bool )] bool bMenu );
328 [return: MarshalAs( UnmanagedType.Bool )]
329 [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
330 public static extern bool GetClientRect( IntPtr hWnd, out RECT lpRect );
331 [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
332 public static extern uint GetWindowLong( IntPtr hWnd, int nIndex );
333 [return: MarshalAs( UnmanagedType.Bool )]
334 [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
335 public static extern bool GetWindowPlacement( IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl );
336 [return: MarshalAs( UnmanagedType.Bool )]
337 [DllImport( "user32.dll", CharSet = CharSet.Auto )]
338 public static extern bool IsIconic( IntPtr hWnd );
339 [return: MarshalAs( UnmanagedType.Bool )]
340 [DllImport( "user32.dll", CharSet = CharSet.Auto )]
341 public static extern bool IsWindowVisible( IntPtr hWnd );
342 [return: MarshalAs( UnmanagedType.Bool )]
343 [DllImport( "user32.dll", CharSet = CharSet.Auto )]
344 public static extern bool IsZoomed( IntPtr hWnd );
345 [DllImport( "winmm.dll" )]
346 public static extern uint midiInClose( uint hMidiIn );
347 [DllImport( "winmm.dll" )]
348 public static extern uint midiInGetDevCaps( uint uDeviceID, ref MIDIINCAPS lpMidiInCaps, uint cbMidiInCaps );
349 [DllImport( "winmm.dll" )]
350 public static extern uint midiInGetID( uint hMidiIn, ref uint puDeviceID );
351 [DllImport( "winmm.dll" )]
352 public static extern uint midiInGetNumDevs();
353 [DllImport( "winmm.dll" )]
354 public static extern uint midiInOpen( ref uint phMidiIn, uint uDeviceID, MidiInProc dwCallback, int dwInstance, int fdwOpen );
355 [DllImport( "winmm.dll" )]
356 public static extern uint midiInReset( uint hMidiIn );
357 [DllImport( "winmm.dll" )]
358 public static extern uint midiInStart( uint hMidiIn );
359 [DllImport( "winmm.dll" )]
360 public static extern uint midiInStop( uint hMidiIn );
361 [DllImport( "user32.dll", CharSet = CharSet.Auto )]
362 public static extern IntPtr MonitorFromWindow( IntPtr hwnd, uint dwFlags );
363 [return: MarshalAs( UnmanagedType.Bool )]
364 [DllImport( "user32.dll", CharSet = CharSet.Auto )]
365 public static extern bool PeekMessage( out WindowMessage message, IntPtr hwnd, uint messageFilterMin, uint messageFilterMax, uint flags );
366 //[DllImport( "kernel32.dll", CharSet = CharSet.Auto )]
367 //public static extern uint SetThreadExecutionState( uint esFlags );
368 [DllImport( "Kernel32.Dll" )]
369 public static unsafe extern void CopyMemory( void* pDest, void* pSrc, uint numOfBytes );
371 [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
372 public static extern uint SetWindowLong( IntPtr hWnd, int nIndex, uint dwNewLong );
373 [return: MarshalAs( UnmanagedType.Bool )]
374 [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
375 public static extern bool SetWindowPlacement( IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl );
376 [return: MarshalAs( UnmanagedType.Bool )]
377 [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
378 public static extern bool SetWindowPos( IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags );
379 [return: MarshalAs( UnmanagedType.Bool )]
380 [DllImport( "user32.dll", CharSet = CharSet.Auto )]
381 public static extern bool ShowWindow( IntPtr hWnd, EShowWindow nCmdShow );
382 [return: MarshalAs( UnmanagedType.Bool )]
383 [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
384 public static extern bool SystemParametersInfo( uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni );
385 [DllImport( "kernel32.dll" )]
386 public static extern void GetSystemInfo( ref SYSTEM_INFO ptmpsi );
387 [DllImport( "kernel32.dll" )]
388 internal static extern ExecutionState SetThreadExecutionState( ExecutionState esFlags );
391 [DllImport("PowrProf.dll")]
392 public static extern UInt32 PowerEnumerate(IntPtr RootPowerKey, IntPtr SchemeGuid, IntPtr SubGroupOfPowerSettingGuid, UInt32 AcessFlags, UInt32 Index, ref Guid Buffer, ref UInt32 BufferSize);
393 public enum AccessFlags : uint
396 ACCESS_SUBGROUP = 17,
397 ACCESS_INDIVIDUAL_SETTING = 18
399 [DllImport( "PowrProf.dll" )]
400 public static extern UInt32 PowerReadFriendlyName( IntPtr RootPowerKey, ref Guid SchemeGuid, IntPtr SubGroupOfPowerSettingGuid, IntPtr PowerSettingGuid, IntPtr Buffer, ref UInt32 BufferSize );
401 [DllImport( "PowrProf.dll" )]
402 public static extern uint PowerGetActiveScheme( IntPtr UserRootPowerKey, ref IntPtr ActivePolicyGuid );
403 [DllImport( "PowrProf.dll" )]
404 public static extern uint PowerSetActiveScheme(IntPtr UserRootPowerKey, ref Guid SchemeGuid);
405 [DllImport( "powrprof.dll" )]
406 public static extern uint CallNtPowerInformation(
407 int InformationLevel,
408 IntPtr lpInputBuffer,
409 int nInputBufferSize,
410 out SYSTEM_POWER_CAPABILITIES spi,
411 int nOutputBufferSize
418 #region [ Win32 構造体 ]
420 [StructLayout( LayoutKind.Sequential )]
421 private struct FILTERKEYS
427 [StructLayout( LayoutKind.Sequential )]
428 public struct MIDIINCAPS
432 public uint vDriverVersion;
433 [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 0x20 )]
434 public string szPname;
435 public uint dwSupport;
438 [StructLayout( LayoutKind.Sequential )]
447 [StructLayout( LayoutKind.Sequential )]
448 private struct STICKYKEYS
454 [StructLayout( LayoutKind.Sequential )]
455 private struct TOGGLEKEYS
461 [StructLayout( LayoutKind.Sequential )]
462 public struct WAVEFORMATEX
464 public ushort wFormatTag;
465 public ushort nChannels;
466 public uint nSamplesPerSec;
467 public uint nAvgBytesPerSec;
468 public ushort nBlockAlign;
469 public ushort wBitsPerSample;
470 public ushort cbSize;
473 [StructLayout( LayoutKind.Sequential )]
474 public struct WindowMessage
478 public IntPtr wParam;
479 public IntPtr lParam;
484 [StructLayout( LayoutKind.Sequential )]
485 public struct WINDOWPLACEMENT
489 public CWin32.EShowWindow showCmd;
490 public Point ptMinPosition;
491 public Point ptMaxPosition;
492 public CWin32.RECT rcNormalPosition;
493 public static int Length
497 return Marshal.SizeOf( typeof( CWin32.WINDOWPLACEMENT ) );
501 [StructLayout( LayoutKind.Sequential )]
502 public struct SYSTEM_INFO
505 public uint dwPageSize;
506 public uint lpMinimumApplicationAddress;
507 public uint lpMaximumApplicationAddress;
508 public uint dwActiveProcessorMask;
509 public uint dwNumberOfProcessors;
510 public uint dwProcessorType;
511 public uint dwAllocationGranularity;
512 public uint dwProcessorLevel;
513 public uint dwProcessorRevision;
515 public struct BATTERY_REPORTING_SCALE
517 public ulong Granularity;
518 public ulong Capacity;
520 public enum SYSTEM_POWER_STATE
522 PowerSystemUnspecified = 0,
523 PowerSystemWorking = 1,
524 PowerSystemSleeping1 = 2,
525 PowerSystemSleeping2 = 3,
526 PowerSystemSleeping3 = 4,
527 PowerSystemHibernate = 5,
528 PowerSystemShutdown = 6,
529 PowerSystemMaximum = 7
531 public struct SYSTEM_POWER_INFORMATION
533 public uint MaxIdlenessAllowed;
534 public uint Idleness;
535 public uint TimeRemaining;
536 public byte CoolingMode;
538 public enum POWER_INFORMATION_LEVEL : int
540 AdministratorPowerPolicy = 9,
543 ProcessorInformation = 11,
544 ProcessorPowerPolicyAc = 18,
545 ProcessorPowerPolicyCurrent = 22,
546 ProcessorPowerPolicyDc = 19,
547 SystemBatteryState = 5,
548 SystemExecutionState = 16,
549 SystemPowerCapabilities = 4,
550 SystemPowerInformation = 12,
551 SystemPowerPolicyAc = 0,
552 SystemPowerPolicyCurrent = 8,
553 SystemPowerPolicyDc = 1,
554 SystemReserveHiberFile = 10,
555 VerifyProcessorPowerPolicyAc = 20,
556 VerifyProcessorPowerPolicyDc = 21,
557 VerifySystemPolicyAc = 2,
558 VerifySystemPolicyDc = 3
561 // http://www.pinvoke.net/default.aspx/Structures/SYSTEM_POWER_STATE.html
562 public struct SYSTEM_POWER_CAPABILITIES
564 [MarshalAs( UnmanagedType.U1 )]
565 public bool PowerButtonPresent;
566 [MarshalAs( UnmanagedType.U1 )]
567 public bool SleepButtonPresent;
568 [MarshalAs( UnmanagedType.U1 )]
569 public bool LidPresent;
570 [MarshalAs( UnmanagedType.U1 )]
571 public bool SystemS1;
572 [MarshalAs( UnmanagedType.U1 )]
573 public bool SystemS2;
574 [MarshalAs( UnmanagedType.U1 )]
575 public bool SystemS3;
576 [MarshalAs( UnmanagedType.U1 )]
577 public bool SystemS4;
578 [MarshalAs( UnmanagedType.U1 )]
579 public bool SystemS5;
580 [MarshalAs( UnmanagedType.U1 )]
581 public bool HiberFilePresent;
582 [MarshalAs( UnmanagedType.U1 )]
583 public bool FullWake;
584 [MarshalAs( UnmanagedType.U1 )]
585 public bool VideoDimPresent;
586 [MarshalAs( UnmanagedType.U1 )]
587 public bool ApmPresent;
588 [MarshalAs( UnmanagedType.U1 )]
589 public bool UpsPresent;
590 [MarshalAs( UnmanagedType.U1 )]
591 public bool ThermalControl;
592 [MarshalAs( UnmanagedType.U1 )]
593 public bool ProcessorThrottle;
594 public byte ProcessorMinThrottle;
595 public byte ProcessorMaxThrottle; // Also known as ProcessorThrottleScale before Windows XP
596 [MarshalAs( UnmanagedType.U1 )]
597 public bool FastSystemS4; // Ignore if earlier than Windows XP
598 [MarshalAs( UnmanagedType.U1 )]
599 public bool Hiberboot; // Ignore if earlier than Windows XP
600 [MarshalAs( UnmanagedType.U1 )]
601 public bool WakeAlarmPresent; // Ignore if earlier than Windows XP
602 [MarshalAs( UnmanagedType.U1 )]
603 public bool AoAc; // Ignore if earlier than Windows XP
604 [MarshalAs( UnmanagedType.U1 )]
605 public bool DiskSpinDown;
606 public byte HiberFileType; // Ignore if earlier than Windows 10 (10.0.10240.0)
607 [MarshalAs( UnmanagedType.U1 )]
608 public bool AoAcConnectivitySupported; // Ignore if earlier than Windows 10 (10.0.10240.0)
609 [MarshalAs( UnmanagedType.ByValArray, SizeConst = 6 )]
610 private readonly byte[] spare3;
611 [MarshalAs( UnmanagedType.U1 )]
612 public bool SystemBatteriesPresent;
613 [MarshalAs( UnmanagedType.U1 )]
614 public bool BatteriesAreShortTerm;
615 [MarshalAs( UnmanagedType.ByValArray, SizeConst = 3 )]
616 public BATTERY_REPORTING_SCALE[] BatteryScale;
617 public SYSTEM_POWER_STATE AcOnLineWake;
618 public SYSTEM_POWER_STATE SoftLidWake;
619 public SYSTEM_POWER_STATE RtcWake;
620 public SYSTEM_POWER_STATE MinDeviceWakeState;
621 public SYSTEM_POWER_STATE DefaultLowLatencyWake;
629 public static bool bアプリがIdle状態である
633 WindowMessage message;
634 return !PeekMessage( out message, IntPtr.Zero, 0, 0, 0 );
641 public static class Cトグルキー機能
643 public static void t無効化する()
645 if( ( stored.dwFlags & 1L ) == 0L )
647 CWin32.TOGGLEKEYS structure = new CWin32.TOGGLEKEYS();
648 structure.dwFlags = stored.dwFlags;
649 structure.cbSize = stored.cbSize;
650 structure.dwFlags &= -5;
651 structure.dwFlags &= -9;
652 int cb = Marshal.SizeOf( structure );
653 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
654 Marshal.StructureToPtr( structure, ptr, false );
655 CWin32.SystemParametersInfo( 0x35, (uint) cb, ptr, 0 );
656 Marshal.FreeCoTaskMem( ptr );
659 public static void t復元する()
661 int cb = Marshal.SizeOf( stored );
662 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
663 Marshal.StructureToPtr( stored, ptr, false );
664 CWin32.SystemParametersInfo( 0x35, (uint) cb, ptr, 0 );
665 Marshal.FreeCoTaskMem( ptr );
672 int cb = Marshal.SizeOf( stored );
673 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
674 Marshal.StructureToPtr( stored, ptr, false );
675 CWin32.SystemParametersInfo( 0x34, (uint) cb, ptr, 0 );
676 stored = (CWin32.TOGGLEKEYS) Marshal.PtrToStructure( ptr, typeof( CWin32.TOGGLEKEYS ) );
677 Marshal.FreeCoTaskMem( ptr );
680 private const uint SPI_GETTOGGLEKEYS = 0x34;
681 private const uint SPI_SETTOGGLEKEYS = 0x35;
682 private static CWin32.TOGGLEKEYS stored = new CWin32.TOGGLEKEYS();
683 private const uint TKF_CONFIRMHOTKEY = 8;
684 private const uint TKF_HOTKEYACTIVE = 4;
685 private const uint TKF_TOGGLEKEYSON = 1;
689 public static class Cフィルタキー機能
691 public static void t無効化する()
693 if( ( stored.dwFlags & 1L ) == 0L )
695 CWin32.FILTERKEYS structure = new CWin32.FILTERKEYS();
696 structure.dwFlags = stored.dwFlags;
697 structure.cbSize = stored.cbSize;
698 structure.dwFlags &= -5;
699 structure.dwFlags &= -9;
700 int cb = Marshal.SizeOf( structure );
701 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
702 Marshal.StructureToPtr( structure, ptr, false );
703 CWin32.SystemParametersInfo( 0x3b, (uint) cb, ptr, 0 );
704 Marshal.FreeCoTaskMem( ptr );
707 public static void t復元する()
709 int cb = Marshal.SizeOf( stored );
710 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
711 Marshal.StructureToPtr( stored, ptr, false );
712 CWin32.SystemParametersInfo( 0x3b, (uint) cb, ptr, 0 );
713 Marshal.FreeCoTaskMem( ptr );
722 int cb = Marshal.SizeOf( stored );
723 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
724 Marshal.StructureToPtr( stored, ptr, false );
725 CWin32.SystemParametersInfo( 50, (uint) cb, ptr, 0 );
726 stored = (CWin32.FILTERKEYS) Marshal.PtrToStructure( ptr, typeof( CWin32.FILTERKEYS ) );
727 Marshal.FreeCoTaskMem( ptr );
730 private const uint FKF_CONFIRMHOTKEY = 8;
731 private const uint FKF_FILTERKEYSON = 1;
732 private const uint FKF_HOTKEYACTIVE = 4;
733 private const uint SPI_GETFILTERKEYS = 50;
734 private const uint SPI_SETFILTERKEYS = 0x3b;
735 private static CWin32.FILTERKEYS stored = new CWin32.FILTERKEYS();
739 public static class C固定キー機能
741 public static void t無効化する()
743 if( ( stored.dwFlags & 1L ) == 0L )
745 CWin32.STICKYKEYS structure = new CWin32.STICKYKEYS();
746 structure.dwFlags = stored.dwFlags;
747 structure.cbSize = stored.cbSize;
748 structure.dwFlags &= -5;
749 structure.dwFlags &= -9;
750 int cb = Marshal.SizeOf( structure );
751 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
752 Marshal.StructureToPtr( structure, ptr, false );
753 CWin32.SystemParametersInfo( 0x3b, (uint) cb, ptr, 0 );
754 Marshal.FreeCoTaskMem( ptr );
757 public static void t復元する()
759 int cb = Marshal.SizeOf( stored );
760 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
761 Marshal.StructureToPtr( stored, ptr, false );
762 CWin32.SystemParametersInfo( 0x3b, (uint) cb, ptr, 0 );
763 Marshal.FreeCoTaskMem( ptr );
772 int cb = Marshal.SizeOf( stored );
773 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
774 Marshal.StructureToPtr( stored, ptr, false );
775 CWin32.SystemParametersInfo( 0x3a, (uint) cb, ptr, 0 );
776 stored = (CWin32.STICKYKEYS) Marshal.PtrToStructure( ptr, typeof( CWin32.STICKYKEYS ) );
777 Marshal.FreeCoTaskMem( ptr );
780 private const uint SKF_CONFIRMHOTKEY = 8;
781 private const uint SKF_HOTKEYACTIVE = 4;
782 private const uint SKF_STICKYKEYSON = 1;
783 private const uint SPI_GETSTICKYKEYS = 0x3a;
784 private const uint SPI_SETSTICKYKEYS = 0x3b;
785 private static CWin32.STICKYKEYS stored = new CWin32.STICKYKEYS();
791 // Win32 メッセージ処理デリゲート
793 public delegate void MidiInProc( uint hMidiIn, uint wMsg, int dwInstance, int dwParam1, int dwParam2 );