Rename MediaInfo() to GetMediaInfoString() to make it more sense
[marukotoolbox.git] / mp4box / Win32API.cs
blobea4a5f1c1016f3e99198d18a13369c38e7653b67
1 // ------------------------------------------------------------------
2 // Copyright (C) 2015-2016 Maruko Toolbox Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 // express or implied.
14 // See the License for the specific language governing permissions
15 // and limitations under the License.
16 // -------------------------------------------------------------------
19 using System;
20 using System.Collections.Generic;
21 using System.Linq;
22 using System.Runtime.InteropServices;
23 using System.Text;
25 namespace mp4box
27 namespace Win32API
29 /// <summary>
30 /// Class hosting Native Win32 APIs
31 /// </summary>
32 public partial class NativeMethods
34 #region <WinUser.h>
36 /// <summary>
37 /// Specifies the type of scroll bar.
38 /// </summary>
39 public enum ScrollBarConsts : int
41 /// <summary>
42 /// Window's standard horizontal scroll bar.
43 /// </summary>
44 SB_HORZ = 0,
45 /// <summary>
46 /// Window's standard vertical scroll bar.
47 /// </summary>
48 SB_VERT = 1,
49 /// <summary>
50 /// Retrieves the position of the scroll box in a scroll bar control.
51 /// The hWnd parameter must be the handle to the scroll bar control.
52 /// </summary>
53 SB_CTL = 2,
54 /// <summary>
55 /// Window's standard scroll bar.
56 /// </summary>
57 SB_BOTH = 3
60 /// <summary>
61 /// Specifies the commands to scroll bar.
62 /// </summary>
63 public enum ScrollBarCmds : int
65 /// <summary>
66 /// Scrolls one line down.
67 /// </summary>
68 SB_LINEUP = 0,
69 /// <summary>
70 /// Scrolls left by one unit.
71 /// </summary>
72 SB_LINELEFT = 0,
73 /// <summary>
74 /// Scrolls one line up.
75 /// </summary>
76 SB_LINEDOWN = 1,
77 /// <summary>
78 /// Scrolls right by one unit.
79 /// </summary>
80 SB_LINERIGHT = 1,
81 /// <summary>
82 /// Scrolls one page up.
83 /// </summary>
84 SB_PAGEUP = 2,
85 /// <summary>
86 /// Scrolls left by the width of the window.
87 /// </summary>
88 SB_PAGELEFT = 2,
89 /// <summary>
90 /// Scrolls one page down.
91 /// </summary>
92 SB_PAGEDOWN = 3,
93 /// <summary>
94 /// Scrolls right by the width of the window.
95 /// </summary>
96 SB_PAGERIGHT = 3,
97 /// <summary>
98 /// The user has dragged the scroll box (thumb) and released the mouse button.
99 /// The HIWORD indicates the position of the scroll box at the end of the drag operation.
100 /// </summary>
101 SB_THUMBPOSITION = 4,
102 /// <summary>
103 /// The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button.
104 /// The HIWORD indicates the position that the scroll box has been dragged to.
105 /// </summary>
106 SB_THUMBTRACK = 5,
107 /// <summary>
108 /// Scrolls to the upper left.
109 /// </summary>
110 SB_TOP = 6,
111 /// <summary>
112 /// Scrolls to the upper left.
113 /// </summary>
114 SB_LEFT = 6,
115 /// <summary>
116 /// Scrolls to the lower right.
117 /// </summary>
118 SB_BOTTOM = 7,
119 /// <summary>
120 /// Scrolls to the lower right.
121 /// </summary>
122 SB_RIGHT = 7,
123 /// <summary>
124 /// Ends scroll.
125 /// </summary>
126 SB_ENDSCROLL = 8
129 /// <summary>
130 /// Indicate the parameters to set or get.
131 /// </summary>
132 public enum ScrollBarFlags : uint
134 /// <summary>
135 /// The nMin and nMax members contain the minimum and maximum values for the scrolling range.
136 /// </summary>
137 SIF_RANGE = 0x1,
138 /// <summary>
139 /// The nPage member contains the page size for a proportional scroll bar.
140 /// </summary>
141 SIF_PAGE = 0x2,
142 /// <summary>
143 /// The nPos member contains the scroll box position, which is not updated while the user drags the scroll box.
144 /// </summary>
145 SIF_POS = 0x4,
146 /// <summary>
147 /// This value is used only when setting a scroll bar's parameters.
148 /// If the scroll bar's new parameters make the scroll bar unnecessary, disable the scroll bar instead of removing it.
149 /// </summary>
150 SIF_DISABLENOSCROLL = 0x8,
151 /// <summary>
152 /// The nTrackPos member contains the current position of the scroll box while the user is dragging it.
153 /// </summary>
154 SIF_TRACKPOS = 0x10,
155 /// <summary>
156 /// Combination of SIF_PAGE, SIF_POS, SIF_RANGE, and SIF_TRACKPOS.
157 /// </summary>
158 SIF_ALL = (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS)
161 /// <summary>
162 /// The flash status.
163 /// </summary>
164 public enum FlashWindowFlags : uint
166 /// <summary>
167 /// Stop flashing. The system restores the window to its original state.
168 /// </summary>
169 FLASHW_STOP = 0,
170 /// <summary>
171 /// Flash the window caption.
172 /// </summary>
173 FLASHW_CAPTION = 0x1,
174 /// <summary>
175 /// Flash the taskbar button.
176 /// </summary>
177 FLASHW_TRAY = 0x2,
178 /// <summary>
179 /// Flash both the window caption and taskbar button.
180 /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
181 /// </summary>
182 FLASHW_ALL = (FLASHW_CAPTION | FLASHW_TRAY),
183 /// <summary>
184 /// Flash continuously, until the FLASHW_STOP flag is set.
185 /// </summary>
186 FLASHW_TIMER = 0x4,
187 /// <summary>
188 /// Flash continuously until the window comes to the foreground.
189 /// </summary>
190 FLASHW_TIMERNOFG = 0xC
193 /// <summary>
194 /// Window Messages
195 /// </summary>
196 public enum Win32Msgs : uint
198 /// <summary>
199 /// The WM_HSCROLL message is sent to a window when a scroll event occurs in the window's standard horizontal scroll bar.
200 /// This message is also sent to the owner of a horizontal scroll bar control when a scroll event occurs in the control.
201 /// </summary>
202 WM_HSCROLL = 0x114,
203 /// <summary>
204 /// The WM_VSCROLL message is sent to a window when a scroll event occurs in the window's standard vertical scroll bar.
205 /// This message is also sent to the owner of a vertical scroll bar control when a scroll event occurs in the control.
206 /// </summary>
207 WM_VSCROLL = 0x115,
208 /// <summary>
209 /// The WM_CTLCOLORSCROLLBAR message is sent to the parent window of a scroll bar control when the control is about to be drawn.
210 /// By responding to this message, the parent window can use the display context handle to set the background color of the scroll bar control.
211 /// </summary>
212 WM_CTLCOLORSCROLLBAR = 0x137,
213 /// <summary>
214 /// Used to define private messages for use by private window classes, usually of the form WM_USER+x, where x is an integer value.
215 /// </summary>
216 WM_USER = 0x400
219 /// <summary>
220 /// Contains scroll bar parameters to be set by the SetScrollInfo function, or retrieved by the GetScrollInfo function.
221 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/bb787537(v=vs.85).aspx</para>
222 /// </summary>
223 [StructLayout(LayoutKind.Sequential)]
224 public struct SCROLLINFO
226 /// <summary>
227 /// Specifies the size, in bytes, of this structure.
228 /// </summary>
229 public uint cbSize;
230 /// <summary>
231 /// Specifies the scroll bar parameters to set or retrieve.
232 /// </summary>
233 public ScrollBarFlags fMask;
234 /// <summary>
235 /// Specifies the minimum scrolling position.
236 /// </summary>
237 public int nMin;
238 /// <summary>
239 /// Specifies the maximum scrolling position.
240 /// </summary>
241 public int nMax;
242 /// <summary>
243 /// Specifies the page size, in device units.
244 /// A scroll bar uses this value to determine the appropriate size of the proportional scroll box.
245 /// </summary>
246 public uint nPage;
247 /// <summary>
248 /// Specifies the position of the scroll box.
249 /// </summary>
250 public int nPos;
251 /// <summary>
252 /// Specifies the immediate position of a scroll box that the user is dragging.
253 /// An application cannot set the immediate scroll position; the SetScrollInfo function ignores this member.
254 /// </summary>
255 public int nTrackPos;
258 /// <summary>
259 /// Contains the flash status for a window and the number of times the system should flash the window.
260 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/ms679348(v=vs.85).aspx</para>
261 /// </summary>
262 [StructLayout(LayoutKind.Sequential)]
263 public struct FLASHWINFO
265 /// <summary>
266 /// The size of the structure, in bytes.
267 /// </summary>
268 public uint cbSize;
269 /// <summary>
270 /// A Handle to the Window to be Flashed. The window can be either opened or minimized.
271 /// </summary>
272 public IntPtr hwnd;
273 /// <summary>
274 /// The Flash Status.
275 /// </summary>
276 public FlashWindowFlags dwFlags;
277 /// <summary>
278 /// The number of times to Flash the window.
279 /// </summary>
280 public uint uCount;
281 /// <summary>
282 /// The rate at which the Window is to be flashed, in milliseconds.
283 /// If Zero, the function uses the default cursor blink rate.
284 /// </summary>
285 public uint dwTimeout;
288 /// <summary>
289 /// Creates a value for use as a wParam parameter in a message.
290 /// The macro concatenates the specified values.
291 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/ms632664(v=vs.85).aspx</para>
292 /// </summary>
293 /// <param name="wLow">The low-order word of the new value.</param>
294 /// <param name="wHi">The high-order word of the new value.</param>
295 /// <returns>The return value is a WPARAM value.</returns>
296 public static UIntPtr MakeWParam(uint wLow, uint wHi)
298 return (UIntPtr)MakeLong(wLow, wHi);
301 /// <summary>
302 /// Creates a value for use as an lParam parameter in a message.
303 /// The macro concatenates the specified values.
304 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/ms632661(v=vs.85).aspx</para>
305 /// </summary>
306 /// <param name="wLow">The low-order word of the new value.</param>
307 /// <param name="wHi">The high-order word of the new value. </param>
308 /// <returns>The return value is an LPARAM value. </returns>
309 public static IntPtr MakeLParam(uint wLow, uint wHi)
311 return (IntPtr)MakeLong(wLow, wHi);
314 #endregion
316 #region <WinDef.h>
318 /// <summary>
319 /// Retrieves the high-order word from the specified 32-bit value.
320 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/ms632657(v=vs.85).aspx</para>
321 /// </summary>
322 /// <param name="ptr">The value to be converted.</param>
323 /// <returns>The return value is the high-order word of the specified value.</returns>
324 public static uint HiWord(IntPtr ptr)
326 return ((uint)ptr >> 16) & 0xFFFFu;
329 /// <summary>
330 /// Retrieves the low-order word from the specified value.
331 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/ms632659(v=vs.85).aspx</para>
332 /// </summary>
333 /// <param name="ptr">The value to be converted.</param>
334 /// <returns>The return value is the low-order word of the specified value.</returns>
335 public static uint LoWord(IntPtr ptr)
337 return (uint)ptr & 0xFFFFu;
340 /// <summary>
341 /// Creates a LONG value by concatenating the specified values.
342 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/ms632660(v=vs.85).aspx</para>
343 /// </summary>
344 /// <param name="wLow">The low-order word of the new value.</param>
345 /// <param name="wHi">The high-order word of the new value.</param>
346 /// <returns>The return value is a LONG value.</returns>
347 public static uint MakeLong(uint wLow, uint wHi)
349 return (wLow & 0xFFFFu) | ((wHi & 0xFFFFu) << 16);
352 #endregion
354 #region <CommCtrl.h>
356 /// <summary>
357 /// Windows Common Controls Messages
358 /// </summary>
359 public enum Win32CommCtrlMsgs : uint
361 /// <summary>
362 /// Edit control messages
363 /// </summary>
364 ECM_FIRST = 0x1500,
366 /// <summary>
367 /// Set the cue banner with the lParm = LPCWSTR
368 /// </summary>
369 EM_SETCUEBANNER = ECM_FIRST + 1,
371 /// <summary>
372 /// Sets the state of the progress bar.
373 /// </summary>
374 PBM_SETSTATE = Win32Msgs.WM_USER + 16
377 /// <summary>
378 /// ProgressBar States
379 /// </summary>
380 public enum ProgressBarState : uint
382 /// <summary>
383 /// In progress.
384 /// </summary>
385 PBST_NORMAL = 0x1,
386 /// <summary>
387 /// Error.
388 /// </summary>
389 PBST_ERROR = 0x2,
390 /// <summary>
391 /// Paused.
392 /// </summary>
393 PBST_PAUSED = 0x3
396 #endregion
398 /// <summary>
399 /// The GetScrollInfo function retrieves the parameters of a scroll bar,
400 /// including the minimum and maximum scrolling positions, the page size,
401 /// and the position of the scroll box (thumb).
402 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/bb787583(v=vs.85).aspx</para>
403 /// </summary>
404 /// <param name="hWnd">Handle to a scroll bar control or a window with a standard scroll bar,
405 /// depending on the value of the fnBar parameter. </param>
406 /// <param name="fnBar">Specifies the type of scroll bar for which to retrieve parameters.</param>
407 /// <param name="lpsi">Pointer to a SCROLLINFO structure. Before calling GetScrollInfo, set the cbSize member to sizeof(SCROLLINFO),
408 /// and set the fMask member to specify the scroll bar parameters to retrieve.
409 /// Before returning, the function copies the specified parameters to the appropriate members of the structure.</param>
410 /// <returns>If the function retrieved any values, the return value is nonzero.</returns>
411 [DllImport("user32.dll")]
412 [return: MarshalAs(UnmanagedType.Bool)]
413 public static extern bool GetScrollInfo(
414 IntPtr hWnd,
415 ScrollBarConsts fnBar,
416 ref SCROLLINFO lpsi);
418 /// <summary>
419 /// The SetScrollInfo function sets the parameters of a scroll bar, including the minimum and maximum scrolling positions,
420 /// the page size, and the position of the scroll box (thumb). The function also redraws the scroll bar, if requested.
421 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/bb787595(v=vs.85).aspx</para>
422 /// </summary>
423 /// <param name="hWnd">Handle to a scroll bar control or a window with a standard scroll bar,
424 /// depending on the value of the fnBar parameter. </param>
425 /// <param name="fnBar">Specifies the type of scroll bar for which to set parameters.</param>
426 /// <param name="lpsi">Pointer to a SCROLLINFO structure. Before calling SetScrollInfo, set the cbSize member of the structure to sizeof(SCROLLINFO),
427 /// set the fMask member to indicate the parameters to set, and specify the new parameter values in the appropriate members.</param>
428 /// <param name="fRedraw">Specifies whether the scroll bar is redrawn to reflect the changes to the scroll bar.
429 /// If this parameter is TRUE, the scroll bar is redrawn, otherwise, it is not redrawn. </param>
430 /// <returns>The current position of the scroll box.</returns>
431 [DllImport("user32.dll")]
432 public static extern int SetScrollInfo(
433 IntPtr hWnd,
434 ScrollBarConsts fnBar,
435 ref SCROLLINFO lpsi,
436 [MarshalAs(UnmanagedType.Bool)] bool fRedraw);
438 /// <summary>
439 /// Flashes the specified window. It does not change the active state of the window.
440 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/ms679347(v=vs.85).aspx</para>
441 /// </summary>
442 /// <param name="pwfi">A pointer to a FLASHWINFO structure.</param>
443 /// <returns>The return value specifies the window's state before the call to the FlashWindowEx function.
444 /// If the window caption was drawn as active before the call, the return value is nonzero. Otherwise, the return value is zero.</returns>
445 [DllImport("user32.dll")]
446 public static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
448 /// <summary>
449 /// Places (posts) a message in the message queue associated with the thread that created
450 /// the specified window and returns without waiting for the thread to process the message.
451 /// <para>http://msdn.microsoft.com/en-us/library/windows/desktop/ms644944(v=vs.85).aspx</para>
452 /// </summary>
453 /// <param name="hWnd">A handle to the window whose window procedure is to receive the message.</param>
454 /// <param name="Msg">The message to be posted.</param>
455 /// <param name="wParam">Additional message-specific information.</param>
456 /// <param name="lParam">Additional message-specific information.</param>
457 /// <returns>If the function succeeds, the return value is nonzero.</returns>
458 [DllImport("user32.dll")]
459 [return: MarshalAs(UnmanagedType.Bool)]
460 public static extern bool PostMessage(
461 IntPtr hWnd,
462 Win32Msgs Msg,
463 [MarshalAs(UnmanagedType.SysUInt)] UIntPtr wParam,
464 [MarshalAs(UnmanagedType.SysInt)] IntPtr lParam);
466 /// <summary>
467 /// Another overload for PostMessage.
468 /// </summary>
469 [DllImport("user32.dll")]
470 [return: MarshalAs(UnmanagedType.Bool)]
471 public static extern bool PostMessage(
472 IntPtr hWnd,
473 Win32CommCtrlMsgs Msg,
474 [MarshalAs(UnmanagedType.SysUInt)] UIntPtr wParam,
475 [MarshalAs(UnmanagedType.SysInt)] IntPtr lParam);
477 /// <summary>
478 /// Sets the text that is displayed as the textual cue, or tip, for an edit control.
479 /// <para>https://msdn.microsoft.com/en-us/library/windows/desktop/bb761701%28v=vs.85%29.aspx</para>
480 /// </summary>
481 /// <param name="hWnd">A handle to the edit control.</param>
482 /// <param name="lpcwText">A pointer to a Unicode string that contains the text to set as the textual cue.</param>
483 /// <returns>If the method succeeds, it returns true. Otherwise it returns false.</returns>
484 public static bool Edit_SetCueBannerText(IntPtr hWnd, string lpcwText)
486 var lp = Marshal.StringToHGlobalAnsi(lpcwText);
487 var result = PostMessage(hWnd, Win32CommCtrlMsgs.EM_SETCUEBANNER,
488 new UIntPtr(0), Marshal.StringToHGlobalUni(lpcwText));
489 Marshal.FreeHGlobal(lp);
490 return result;