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( IntPtr 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( IntPtr hMidiIn, ref IntPtr puDeviceID );
351 [DllImport( "winmm.dll" )]
352 public static extern uint midiInGetNumDevs();
353 [DllImport( "winmm.dll" )]
354 public static extern uint midiInOpen( ref IntPtr phMidiIn, uint uDeviceID, MidiInProc dwCallback, IntPtr dwInstance, int fdwOpen );
355 [DllImport( "winmm.dll" )]
356 public static extern uint midiInReset( IntPtr hMidiIn );
357 [DllImport( "winmm.dll" )]
358 public static extern uint midiInStart( IntPtr hMidiIn );
359 [DllImport( "winmm.dll" )]
360 public static extern uint midiInStop( IntPtr 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( out 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;
472 public WAVEFORMATEX (
475 uint _nSamplesPerSec,
476 uint _nAvgBytesPerSec,
478 ushort _wBitsPerSample,
479 ushort _cbSize) : this()
481 wFormatTag = _wFormatTag;
482 nChannels = _nChannels;
483 nSamplesPerSec = _nSamplesPerSec;
484 nAvgBytesPerSec = _nAvgBytesPerSec;
485 nBlockAlign = _nBlockAlign;
486 wBitsPerSample = _wBitsPerSample;
491 [StructLayout( LayoutKind.Sequential )]
492 public struct WindowMessage
496 public IntPtr wParam;
497 public IntPtr lParam;
502 [StructLayout( LayoutKind.Sequential )]
503 public struct WINDOWPLACEMENT
507 public CWin32.EShowWindow showCmd;
508 public Point ptMinPosition;
509 public Point ptMaxPosition;
510 public CWin32.RECT rcNormalPosition;
511 public static int Length
515 return Marshal.SizeOf( typeof( CWin32.WINDOWPLACEMENT ) );
519 [StructLayout( LayoutKind.Sequential )]
520 public struct SYSTEM_INFO
523 public uint dwPageSize;
524 public IntPtr lpMinimumApplicationAddress;
525 public IntPtr lpMaximumApplicationAddress;
526 public UIntPtr dwActiveProcessorMask;
527 public uint dwNumberOfProcessors;
528 public uint dwProcessorType;
529 public uint dwAllocationGranularity;
530 public ushort dwProcessorLevel;
531 public ushort dwProcessorRevision;
533 public struct BATTERY_REPORTING_SCALE
535 public ulong Granularity;
536 public ulong Capacity;
538 public enum SYSTEM_POWER_STATE
540 PowerSystemUnspecified = 0,
541 PowerSystemWorking = 1,
542 PowerSystemSleeping1 = 2,
543 PowerSystemSleeping2 = 3,
544 PowerSystemSleeping3 = 4,
545 PowerSystemHibernate = 5,
546 PowerSystemShutdown = 6,
547 PowerSystemMaximum = 7
549 public struct SYSTEM_POWER_INFORMATION
551 public uint MaxIdlenessAllowed;
552 public uint Idleness;
553 public uint TimeRemaining;
554 public byte CoolingMode;
556 public enum POWER_INFORMATION_LEVEL : int
558 AdministratorPowerPolicy = 9,
561 ProcessorInformation = 11,
562 ProcessorPowerPolicyAc = 18,
563 ProcessorPowerPolicyCurrent = 22,
564 ProcessorPowerPolicyDc = 19,
565 SystemBatteryState = 5,
566 SystemExecutionState = 16,
567 SystemPowerCapabilities = 4,
568 SystemPowerInformation = 12,
569 SystemPowerPolicyAc = 0,
570 SystemPowerPolicyCurrent = 8,
571 SystemPowerPolicyDc = 1,
572 SystemReserveHiberFile = 10,
573 VerifyProcessorPowerPolicyAc = 20,
574 VerifyProcessorPowerPolicyDc = 21,
575 VerifySystemPolicyAc = 2,
576 VerifySystemPolicyDc = 3
579 // http://www.pinvoke.net/default.aspx/Structures/SYSTEM_POWER_STATE.html
580 public struct SYSTEM_POWER_CAPABILITIES
582 [MarshalAs( UnmanagedType.U1 )]
583 public bool PowerButtonPresent;
584 [MarshalAs( UnmanagedType.U1 )]
585 public bool SleepButtonPresent;
586 [MarshalAs( UnmanagedType.U1 )]
587 public bool LidPresent;
588 [MarshalAs( UnmanagedType.U1 )]
589 public bool SystemS1;
590 [MarshalAs( UnmanagedType.U1 )]
591 public bool SystemS2;
592 [MarshalAs( UnmanagedType.U1 )]
593 public bool SystemS3;
594 [MarshalAs( UnmanagedType.U1 )]
595 public bool SystemS4;
596 [MarshalAs( UnmanagedType.U1 )]
597 public bool SystemS5;
598 [MarshalAs( UnmanagedType.U1 )]
599 public bool HiberFilePresent;
600 [MarshalAs( UnmanagedType.U1 )]
601 public bool FullWake;
602 [MarshalAs( UnmanagedType.U1 )]
603 public bool VideoDimPresent;
604 [MarshalAs( UnmanagedType.U1 )]
605 public bool ApmPresent;
606 [MarshalAs( UnmanagedType.U1 )]
607 public bool UpsPresent;
608 [MarshalAs( UnmanagedType.U1 )]
609 public bool ThermalControl;
610 [MarshalAs( UnmanagedType.U1 )]
611 public bool ProcessorThrottle;
612 public byte ProcessorMinThrottle;
613 public byte ProcessorMaxThrottle; // Also known as ProcessorThrottleScale before Windows XP
614 [MarshalAs( UnmanagedType.U1 )]
615 public bool FastSystemS4; // Ignore if earlier than Windows XP
616 [MarshalAs( UnmanagedType.U1 )]
617 public bool Hiberboot; // Ignore if earlier than Windows XP
618 [MarshalAs( UnmanagedType.U1 )]
619 public bool WakeAlarmPresent; // Ignore if earlier than Windows XP
620 [MarshalAs( UnmanagedType.U1 )]
621 public bool AoAc; // Ignore if earlier than Windows XP
622 [MarshalAs( UnmanagedType.U1 )]
623 public bool DiskSpinDown;
624 public byte HiberFileType; // Ignore if earlier than Windows 10 (10.0.10240.0)
625 [MarshalAs( UnmanagedType.U1 )]
626 public bool AoAcConnectivitySupported; // Ignore if earlier than Windows 10 (10.0.10240.0)
627 [MarshalAs( UnmanagedType.ByValArray, SizeConst = 6 )]
628 private readonly byte[] spare3;
629 [MarshalAs( UnmanagedType.U1 )]
630 public bool SystemBatteriesPresent;
631 [MarshalAs( UnmanagedType.U1 )]
632 public bool BatteriesAreShortTerm;
633 [MarshalAs( UnmanagedType.ByValArray, SizeConst = 3 )]
634 public BATTERY_REPORTING_SCALE[] BatteryScale;
635 public SYSTEM_POWER_STATE AcOnLineWake;
636 public SYSTEM_POWER_STATE SoftLidWake;
637 public SYSTEM_POWER_STATE RtcWake;
638 public SYSTEM_POWER_STATE MinDeviceWakeState;
639 public SYSTEM_POWER_STATE DefaultLowLatencyWake;
647 public static bool bアプリがIdle状態である
651 WindowMessage message;
652 return !PeekMessage( out message, IntPtr.Zero, 0, 0, 0 );
659 public static class Cトグルキー機能
661 public static void t無効化する()
663 if( ( stored.dwFlags & 1L ) == 0L )
665 CWin32.TOGGLEKEYS structure = new CWin32.TOGGLEKEYS();
666 structure.dwFlags = stored.dwFlags;
667 structure.cbSize = stored.cbSize;
668 structure.dwFlags &= -5;
669 structure.dwFlags &= -9;
670 int cb = Marshal.SizeOf( structure );
671 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
672 Marshal.StructureToPtr( structure, ptr, false );
673 CWin32.SystemParametersInfo( 0x35, (uint) cb, ptr, 0 );
674 Marshal.FreeCoTaskMem( ptr );
677 public static void t復元する()
679 int cb = Marshal.SizeOf( stored );
680 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
681 Marshal.StructureToPtr( stored, ptr, false );
682 CWin32.SystemParametersInfo( 0x35, (uint) cb, ptr, 0 );
683 Marshal.FreeCoTaskMem( ptr );
690 int cb = Marshal.SizeOf( stored );
691 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
692 Marshal.StructureToPtr( stored, ptr, false );
693 CWin32.SystemParametersInfo( 0x34, (uint) cb, ptr, 0 );
694 stored = (CWin32.TOGGLEKEYS) Marshal.PtrToStructure( ptr, typeof( CWin32.TOGGLEKEYS ) );
695 Marshal.FreeCoTaskMem( ptr );
698 private const uint SPI_GETTOGGLEKEYS = 0x34;
699 private const uint SPI_SETTOGGLEKEYS = 0x35;
700 private static CWin32.TOGGLEKEYS stored = new CWin32.TOGGLEKEYS();
701 private const uint TKF_CONFIRMHOTKEY = 8;
702 private const uint TKF_HOTKEYACTIVE = 4;
703 private const uint TKF_TOGGLEKEYSON = 1;
707 public static class Cフィルタキー機能
709 public static void t無効化する()
711 if( ( stored.dwFlags & 1L ) == 0L )
713 CWin32.FILTERKEYS structure = new CWin32.FILTERKEYS();
714 structure.dwFlags = stored.dwFlags;
715 structure.cbSize = stored.cbSize;
716 structure.dwFlags &= -5;
717 structure.dwFlags &= -9;
718 int cb = Marshal.SizeOf( structure );
719 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
720 Marshal.StructureToPtr( structure, ptr, false );
721 CWin32.SystemParametersInfo( 0x3b, (uint) cb, ptr, 0 );
722 Marshal.FreeCoTaskMem( ptr );
725 public static void t復元する()
727 int cb = Marshal.SizeOf( stored );
728 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
729 Marshal.StructureToPtr( stored, ptr, false );
730 CWin32.SystemParametersInfo( 0x3b, (uint) cb, ptr, 0 );
731 Marshal.FreeCoTaskMem( ptr );
740 int cb = Marshal.SizeOf( stored );
741 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
742 Marshal.StructureToPtr( stored, ptr, false );
743 CWin32.SystemParametersInfo( 50, (uint) cb, ptr, 0 );
744 stored = (CWin32.FILTERKEYS) Marshal.PtrToStructure( ptr, typeof( CWin32.FILTERKEYS ) );
745 Marshal.FreeCoTaskMem( ptr );
748 private const uint FKF_CONFIRMHOTKEY = 8;
749 private const uint FKF_FILTERKEYSON = 1;
750 private const uint FKF_HOTKEYACTIVE = 4;
751 private const uint SPI_GETFILTERKEYS = 50;
752 private const uint SPI_SETFILTERKEYS = 0x3b;
753 private static CWin32.FILTERKEYS stored = new CWin32.FILTERKEYS();
757 public static class C固定キー機能
759 public static void t無効化する()
761 if( ( stored.dwFlags & 1L ) == 0L )
763 CWin32.STICKYKEYS structure = new CWin32.STICKYKEYS();
764 structure.dwFlags = stored.dwFlags;
765 structure.cbSize = stored.cbSize;
766 structure.dwFlags &= -5;
767 structure.dwFlags &= -9;
768 int cb = Marshal.SizeOf( structure );
769 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
770 Marshal.StructureToPtr( structure, ptr, false );
771 CWin32.SystemParametersInfo( 0x3b, (uint) cb, ptr, 0 );
772 Marshal.FreeCoTaskMem( ptr );
775 public static void t復元する()
777 int cb = Marshal.SizeOf( stored );
778 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
779 Marshal.StructureToPtr( stored, ptr, false );
780 CWin32.SystemParametersInfo( 0x3b, (uint) cb, ptr, 0 );
781 Marshal.FreeCoTaskMem( ptr );
790 int cb = Marshal.SizeOf( stored );
791 IntPtr ptr = Marshal.AllocCoTaskMem( cb );
792 Marshal.StructureToPtr( stored, ptr, false );
793 CWin32.SystemParametersInfo( 0x3a, (uint) cb, ptr, 0 );
794 stored = (CWin32.STICKYKEYS) Marshal.PtrToStructure( ptr, typeof( CWin32.STICKYKEYS ) );
795 Marshal.FreeCoTaskMem( ptr );
798 private const uint SKF_CONFIRMHOTKEY = 8;
799 private const uint SKF_HOTKEYACTIVE = 4;
800 private const uint SKF_STICKYKEYSON = 1;
801 private const uint SPI_GETSTICKYKEYS = 0x3a;
802 private const uint SPI_SETSTICKYKEYS = 0x3b;
803 private static CWin32.STICKYKEYS stored = new CWin32.STICKYKEYS();
809 // Win32 メッセージ処理デリゲート
811 public delegate void MidiInProc( IntPtr hMidiIn, uint wMsg, int dwInstance, int dwParam1, int dwParam2 );