OSDN Git Service

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