NativeMethods.cs
author Thomas
Thu, 14 Nov 2019 16:16:03 +0100
branchsync
changeset 2861 590f021d5fb6
parent 2557 f586944e61be
permissions -rw-r--r--
Remove unused handshake signals
Thomas@1758
     1
´╗┐using System;
Thomas@1758
     2
using System.Runtime.InteropServices;
Thomas@1758
     3
Thomas@1758
     4
namespace pEp
Thomas@1758
     5
{
Thomas@1758
     6
    /// <summary>
Thomas@1758
     7
    /// Provides P/Invoke methods for calling Win32 and other unmanaged APIs from managed code.
Thomas@1758
     8
    /// </summary>
Thomas@1758
     9
    internal class NativeMethods
Thomas@1758
    10
    {
Thomas@1758
    11
        /// <summary>
Thomas@1896
    12
        /// Flag to use for FindMimeFromData(). Returns "image/png" and "image/jpeg" instead of "image/x-png" and "image/pjpeg". 
Thomas@1896
    13
        /// </summary>
Thomas@1896
    14
        internal const int FMFD_RETURNUPDATEDIMGMIMES = 0x00000020;
Thomas@1896
    15
Thomas@2557
    16
        /// <summary>
Thomas@2557
    17
        /// Defines the Z order of a window in the SetWindowPos method. Places the window at the bottom of the Z order. 
Thomas@2557
    18
        /// If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the 
Thomas@2557
    19
        /// bottom of all other windows. 
Thomas@2557
    20
        /// </summary>
Thomas@2557
    21
        internal static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
Thomas@2557
    22
Thomas@2352
    23
        #region Enumerations
Thomas@1896
    24
        /// <summary>
Thomas@2352
    25
        /// Specifies the type of the input event.
Thomas@2352
    26
        /// See: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-taginput
Thomas@1758
    27
        /// </summary>
Thomas@2352
    28
        internal enum InputType
Thomas@2352
    29
        {
Thomas@2352
    30
            InputMouse = 0,
Thomas@2352
    31
            InputKeyboard = 1,
Thomas@2352
    32
            InputHardware = 2
Thomas@2352
    33
        }
Thomas@1758
    34
Thomas@1758
    35
        /// <summary>
Thomas@2352
    36
        /// A set of bit flags that specify various aspects of mouse motion and button clicks.
Thomas@2352
    37
        /// See: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmouseinput
Thomas@1758
    38
        /// </summary>
Thomas@2352
    39
        [Flags]
Thomas@2352
    40
        internal enum MouseEvents
Thomas@2352
    41
        {
Thomas@2352
    42
            MouseEventFAbsolute = 0x8000,
Thomas@2352
    43
            MouseEventFHWheel = 0x01000,
Thomas@2352
    44
            MouseEventFMove = 0x0001,
Thomas@2352
    45
            MouseEventFMoveNoCoalesce = 0x2000,
Thomas@2352
    46
            MouseEventFLeftDown = 0x0002,
Thomas@2352
    47
            MouseEventFLeftUp = 0x0004,
Thomas@2352
    48
            MouseEventFRightDown = 0x0008,
Thomas@2352
    49
            MouseEventFRightUp = 0x0010,
Thomas@2352
    50
            MouseEventFMiddleDown = 0x0020,
Thomas@2352
    51
            MouseEventFMiddleUp = 0x0040,
Thomas@2352
    52
            MouseEventFVirtualDesk = 0x4000,
Thomas@2352
    53
            MouseEventFWheel = 0x0800,
Thomas@2352
    54
            MouseEventFXDown = 0x0080,
Thomas@2352
    55
            MouseEventFXUp = 0x0100
Thomas@2352
    56
        }
Thomas@2557
    57
Thomas@2557
    58
        [Flags]
Thomas@2557
    59
        internal enum SetWindowPosFlags : uint
Thomas@2557
    60
        {
Thomas@2557
    61
            /// <summary>If the calling thread and the thread that owns the window are attached to different input queues,
Thomas@2557
    62
            /// the system posts the request to the thread that owns the window. This prevents the calling thread from
Thomas@2557
    63
            /// blocking its execution while other threads process the request.</summary>
Thomas@2557
    64
            /// <remarks>SWP_ASYNCWINDOWPOS</remarks>
Thomas@2557
    65
            AsynchronousWindowPosition = 0x4000,
Thomas@2557
    66
            /// <summary>Prevents generation of the WM_SYNCPAINT message.</summary>
Thomas@2557
    67
            /// <remarks>SWP_DEFERERASE</remarks>
Thomas@2557
    68
            DeferErase = 0x2000,
Thomas@2557
    69
            /// <summary>Draws a frame (defined in the window's class description) around the window.</summary>
Thomas@2557
    70
            /// <remarks>SWP_DRAWFRAME</remarks>
Thomas@2557
    71
            DrawFrame = 0x0020,
Thomas@2557
    72
            /// <summary>Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to
Thomas@2557
    73
            /// the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE
Thomas@2557
    74
            /// is sent only when the window's size is being changed.</summary>
Thomas@2557
    75
            /// <remarks>SWP_FRAMECHANGED</remarks>
Thomas@2557
    76
            FrameChanged = 0x0020,
Thomas@2557
    77
            /// <summary>Hides the window.</summary>
Thomas@2557
    78
            /// <remarks>SWP_HIDEWINDOW</remarks>
Thomas@2557
    79
            HideWindow = 0x0080,
Thomas@2557
    80
            /// <summary>Does not activate the window. If this flag is not set, the window is activated and moved to the
Thomas@2557
    81
            /// top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter
Thomas@2557
    82
            /// parameter).</summary>
Thomas@2557
    83
            /// <remarks>SWP_NOACTIVATE</remarks>
Thomas@2557
    84
            DoNotActivate = 0x0010,
Thomas@2557
    85
            /// <summary>Discards the entire contents of the client area. If this flag is not specified, the valid
Thomas@2557
    86
            /// contents of the client area are saved and copied back into the client area after the window is sized or
Thomas@2557
    87
            /// repositioned.</summary>
Thomas@2557
    88
            /// <remarks>SWP_NOCOPYBITS</remarks>
Thomas@2557
    89
            DoNotCopyBits = 0x0100,
Thomas@2557
    90
            /// <summary>Retains the current position (ignores X and Y parameters).</summary>
Thomas@2557
    91
            /// <remarks>SWP_NOMOVE</remarks>
Thomas@2557
    92
            IgnoreMove = 0x0002,
Thomas@2557
    93
            /// <summary>Does not change the owner window's position in the Z order.</summary>
Thomas@2557
    94
            /// <remarks>SWP_NOOWNERZORDER</remarks>
Thomas@2557
    95
            DoNotChangeOwnerZOrder = 0x0200,
Thomas@2557
    96
            /// <summary>Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to
Thomas@2557
    97
            /// the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent
Thomas@2557
    98
            /// window uncovered as a result of the window being moved. When this flag is set, the application must
Thomas@2557
    99
            /// explicitly invalidate or redraw any parts of the window and parent window that need redrawing.</summary>
Thomas@2557
   100
            /// <remarks>SWP_NOREDRAW</remarks>
Thomas@2557
   101
            DoNotRedraw = 0x0008,
Thomas@2557
   102
            /// <summary>Same as the SWP_NOOWNERZORDER flag.</summary>
Thomas@2557
   103
            /// <remarks>SWP_NOREPOSITION</remarks>
Thomas@2557
   104
            DoNotReposition = 0x0200,
Thomas@2557
   105
            /// <summary>Prevents the window from receiving the WM_WINDOWPOSCHANGING message.</summary>
Thomas@2557
   106
            /// <remarks>SWP_NOSENDCHANGING</remarks>
Thomas@2557
   107
            DoNotSendChangingEvent = 0x0400,
Thomas@2557
   108
            /// <summary>Retains the current size (ignores the cx and cy parameters).</summary>
Thomas@2557
   109
            /// <remarks>SWP_NOSIZE</remarks>
Thomas@2557
   110
            IgnoreResize = 0x0001,
Thomas@2557
   111
            /// <summary>Retains the current Z order (ignores the hWndInsertAfter parameter).</summary>
Thomas@2557
   112
            /// <remarks>SWP_NOZORDER</remarks>
Thomas@2557
   113
            IgnoreZOrder = 0x0004,
Thomas@2557
   114
            /// <summary>Displays the window.</summary>
Thomas@2557
   115
            /// <remarks>SWP_SHOWWINDOW</remarks>
Thomas@2557
   116
            ShowWindow = 0x0040,
Thomas@2557
   117
        }
Thomas@2557
   118
Thomas@2352
   119
        #endregion
Thomas@2352
   120
Thomas@2352
   121
        #region Structures
Thomas@2352
   122
        /// <summary>
Thomas@2352
   123
        /// Defines the x- and y- coordinates of a point.
Thomas@2352
   124
        /// </summary>
Thomas@2352
   125
        internal struct Point
Thomas@2352
   126
        {
Thomas@2352
   127
            public int X;
Thomas@2352
   128
            public int Y;
Thomas@2352
   129
Thomas@2352
   130
            public Point(int x, int y)
Thomas@2352
   131
            {
Thomas@2352
   132
                X = x;
Thomas@2352
   133
                Y = y;
Thomas@2352
   134
            }
Thomas@2352
   135
        }
Thomas@2352
   136
Thomas@2352
   137
        /// <summary>
Thomas@2352
   138
        /// Used by SendInput to store information for synthesizing input events such as keystrokes, 
Thomas@2352
   139
        /// mouse movement, and mouse clicks.
Thomas@2352
   140
        /// </summary>
Thomas@2352
   141
        [StructLayout(LayoutKind.Explicit)]
Thomas@2352
   142
        public struct Input
Thomas@2352
   143
        {
Thomas@2352
   144
            [FieldOffset(0)]
Thomas@2352
   145
            public int              Type;
Thomas@2352
   146
            [FieldOffset(4)]
Thomas@2352
   147
            public MouseInput       Mi;
Thomas@2352
   148
            [FieldOffset(4)]
Thomas@2352
   149
            public KeyBdInput       Ki;
Thomas@2352
   150
            [FieldOffset(4)]
Thomas@2352
   151
            public HardwareInput    Hi;
Thomas@2352
   152
        }
Thomas@2352
   153
Thomas@2352
   154
        /// <summary>
Thomas@2352
   155
        /// Contains information about a simulated message generated by an input device other than a keyboard or mouse.
Thomas@2352
   156
        /// </summary>
Thomas@2352
   157
        [StructLayout(LayoutKind.Sequential)]
Thomas@2352
   158
        public struct HardwareInput
Thomas@2352
   159
        {
Thomas@2352
   160
            public int      Msg;
Thomas@2352
   161
            public short    ParamL;
Thomas@2352
   162
            public short    ParamH;
Thomas@2352
   163
        }
Thomas@2352
   164
Thomas@2352
   165
        /// <summary>
Thomas@2352
   166
        /// Contains information about a simulated keyboard event.
Thomas@2352
   167
        /// </summary>
Thomas@2352
   168
        [StructLayout(LayoutKind.Sequential)]
Thomas@2352
   169
        public struct KeyBdInput
Thomas@2352
   170
        {
Thomas@2352
   171
            public short    Vk;
Thomas@2352
   172
            public short    Scan;
Thomas@2352
   173
            public int      Flags;
Thomas@2352
   174
            public int      Time;
Thomas@2352
   175
            public IntPtr   ExtraInfo;
Thomas@2352
   176
        }
Thomas@2352
   177
Thomas@2352
   178
        /// <summary>
Thomas@2352
   179
        /// Contains information about a simulated mouse event.
Thomas@2352
   180
        /// </summary>
Thomas@2352
   181
        [StructLayout(LayoutKind.Sequential)]
Thomas@2352
   182
        internal struct MouseInput
Thomas@2352
   183
        {
Thomas@2352
   184
            public int     X;
Thomas@2352
   185
            public int     Y;
Thomas@2352
   186
            public int     MouseData;
Thomas@2352
   187
            public int     Flags;
Thomas@2352
   188
            public int     Time;
Thomas@2352
   189
            public IntPtr  ExtraInfo;
Thomas@2352
   190
        }
Thomas@2352
   191
Thomas@2352
   192
        /// <summary>
Thomas@2352
   193
        /// Defines the coordinates of the upper-left and lower-right corners of a rectangle.
Thomas@2352
   194
        /// </summary>
Thomas@2374
   195
        [Serializable]
Thomas@2352
   196
        internal struct Rect
Thomas@2352
   197
        {
Thomas@2352
   198
            public int Left;
Thomas@2352
   199
            public int Top;
Thomas@2352
   200
            public int Right;
Thomas@2352
   201
            public int Bottom;
Thomas@2352
   202
        }
Thomas@2352
   203
Thomas@2352
   204
        /// <summary>
Thomas@2352
   205
        /// Contains information about a GUI thread.
Thomas@2352
   206
        /// </summary>
Thomas@2352
   207
        [Serializable, StructLayout(LayoutKind.Sequential)]
Thomas@2352
   208
        internal struct GuiThreadInfo
Thomas@2352
   209
        {
Thomas@2352
   210
            public int      size;
Thomas@2352
   211
            public int      flags;
Thomas@2352
   212
            public IntPtr   hwndActive;
Thomas@2352
   213
            public IntPtr   hwndFocus;
Thomas@2352
   214
            public IntPtr   hwndCapture;
Thomas@2352
   215
            public IntPtr   hwndMenuOwner;
Thomas@2352
   216
            public IntPtr   hwndMoveSize;
Thomas@2352
   217
            public IntPtr   hwndCaret;
Thomas@2352
   218
            public Rect     caretRectangle;
Thomas@2352
   219
        }
Thomas@2352
   220
        #endregion
Thomas@2352
   221
Thomas@2352
   222
        #region Methods
Thomas@2352
   223
        /// <summary>
Thomas@2352
   224
        /// Converts the client-area coordinates of a specified point to screen coordinates.
Thomas@2352
   225
        /// </summary>
Thomas@2352
   226
        /// <param name="hWnd">A handle to the window whose client area is used for the conversion.</param>
Thomas@2352
   227
        /// <param name="point">A Point structure that contains the client coordinates to be converted. 
Thomas@2352
   228
        /// The new screen coordinates are copied into this structure if the function succeeds.</param>
Thomas@1758
   229
        /// <returns>True if the method succeeds, otherwise false.</returns>
Thomas@2352
   230
        [DllImport("user32.dll", SetLastError = true)]
Thomas@2352
   231
        internal static extern bool ClientToScreen(IntPtr hWnd, ref Point point);
Thomas@1758
   232
Thomas@1758
   233
        /// <summary>
Thomas@1896
   234
        /// Datermines the MIME type of a file (or byte array).
Thomas@1896
   235
        /// Note: this function seems to return some obsolete or non-standard compliant values like
Thomas@1896
   236
        /// "image/x-png" (which should be "image/png" after its standardization).
Thomas@1896
   237
        /// </summary>
Thomas@1896
   238
        /// <param name="bc">A pointer to the IBindCtx interface. Can be set to null.</param>
Thomas@1896
   239
        /// <param name="url">The URL of the data. Can be set to null if the buffer contains the data to be sniffed.</param>
Thomas@1896
   240
        /// <param name="buffer">The buffer that contains the data to be sniffed. Can be set to null if url contains a valid URL.</param>
Thomas@1896
   241
        /// <param name="bufferSize">The size of the buffer.</param>
Thomas@1896
   242
        /// <param name="mimeProposed">The proposed MIME type. This value is authoritative if type cannot be determined from the data. If the proposed type contains a semi-colon (;) it is removed. This parameter can be set to null.</param>
Thomas@1896
   243
        /// <param name="mimeFlags">Flags to control special behaviour of the methos.</param>
Thomas@1896
   244
        /// <param name="mimeOut">A pointer to the suggested MIME type.</param>
Thomas@1896
   245
        /// <param name="reserved">Reserved. Must be set to 0.</param>
Thomas@1896
   246
        /// <returns></returns>
Thomas@1896
   247
        [DllImport("urlmon.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = false)]
Thomas@2352
   248
        internal static extern int FindMimeFromData(IntPtr bc,
Thomas@2352
   249
                                                    [MarshalAs(UnmanagedType.LPWStr)] string url,
Thomas@2352
   250
                                                    [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1, SizeParamIndex = 3)] byte[] buffer,
Thomas@2352
   251
                                                    uint bufferSize,
Thomas@2352
   252
                                                    [MarshalAs(UnmanagedType.LPWStr)] string mimeProposed,
Thomas@2352
   253
                                                    int mimeFlags,
Thomas@1896
   254
                                                    out IntPtr mimeOut,
Thomas@1896
   255
                                                    int reserved);
Thomas@1896
   256
Thomas@1896
   257
        /// <summary>
Thomas@2557
   258
        /// Retrieves the window handle to the active window attached to the calling thread's message queue.
Thomas@2557
   259
        /// </summary>
Thomas@2557
   260
        /// <returns>The handle to the active window attached to the calling thread's message queue or null.</returns>
Thomas@2557
   261
        [DllImport("user32.dll")]
Thomas@2557
   262
        internal static extern IntPtr GetActiveWindow();
Thomas@2557
   263
Thomas@2557
   264
        /// <summary>
Thomas@2352
   265
        /// Copies the caret's position to the specified Point structure.
Thomas@1758
   266
        /// </summary>
Thomas@2352
   267
        /// <param name="point">A Point structure that is to receive the client coordinates of the caret.</param>
Thomas@2352
   268
        /// <returns>True if the method succeeds, otherwise false.</returns>
Thomas@2352
   269
        [DllImport("user32.dll", SetLastError = true)]
Thomas@2352
   270
        internal static extern bool GetCaretPos(out Point point);
Thomas@1758
   271
Thomas@1758
   272
        /// <summary>
Thomas@2352
   273
        /// Retrieves the thread identifier of the calling thread.
Thomas@1758
   274
        /// </summary>
Thomas@2352
   275
        /// <returns>The thread identifier of the calling thread.</returns>
Thomas@2352
   276
        [DllImport("kernel32.dll", SetLastError = true)]
Thomas@2352
   277
        internal static extern uint GetCurrentThreadId();
nikolaj@1965
   278
nikolaj@1965
   279
        /// <summary>
Thomas@2352
   280
        /// Retrieves information about the active window or a specified GUI thread.
nikolaj@1965
   281
        /// </summary>
Thomas@2352
   282
        /// <param name="threadId">The identifier for the thread for which information is to be retrieved. 
Thomas@2352
   283
        /// To retrieve this value, use the GetWindowThreadProcessId function. If this parameter is null, 
Thomas@2352
   284
        /// the function returns information for the foreground thread.</param>
Thomas@2352
   285
        /// <param name="guiThreadInfo">The GuiThreadInfo structure that receives information describing the thread. 
Thomas@2352
   286
        /// Note that you must set the size member to Marshal.SizeOf(guiThreadInfo) before calling this method.</param>
Thomas@2352
   287
        /// <returns>True if the method succeeds, otherwise false.</returns>
Thomas@2352
   288
        [DllImport("user32.dll", SetLastError = true)]
Thomas@2352
   289
        internal static extern bool GetGUIThreadInfo(uint threadId, ref GuiThreadInfo guiThreadInfo);
Thomas@2352
   290
Thomas@2352
   291
        /// <summary>
Thomas@2352
   292
        /// Synthesizes keystrokes, mouse motions, and button clicks.
Thomas@2352
   293
        /// </summary>
Thomas@2352
   294
        /// <param name="inputCount">The number of structures in the inputs array.</param>
Thomas@2352
   295
        /// <param name="inputs">An array of Input structures. Each structure represents an event to be 
Thomas@2352
   296
        /// inserted into the keyboard or mouse input stream.</param>
Thomas@2352
   297
        /// <param name="size">The size, in bytes, of an Input structure. If size is not the size of an Input structure, 
Thomas@2352
   298
        /// the function fails.</param>
Thomas@2352
   299
        /// <returns>The number of events that it successfully inserted into the keyboard or mouse input stream. 
Thomas@2352
   300
        /// If the function returns zero, the input was already blocked by another thread.</returns>
Thomas@2352
   301
        [DllImport("user32.dll", SetLastError = true)]
Thomas@2352
   302
        internal static extern uint SendInput(uint inputCount, [MarshalAs(UnmanagedType.LPArray), In] Input[] inputs, int size);
Thomas@2352
   303
Thomas@2352
   304
        /// <summary>
Thomas@2352
   305
        /// Moves the cursor to the specified screen coordinates. If the new coordinates are not within 
Thomas@2352
   306
        /// the screen rectangle set by the most recent ClipCursor function call, the system automatically 
Thomas@2352
   307
        /// adjusts the coordinates so that the cursor stays within the rectangle.
Thomas@2352
   308
        /// </summary>
Thomas@2352
   309
        /// <param name="x">The new x-coordinate of the cursor, in screen coordinates.</param>
Thomas@2352
   310
        /// <param name="y">The new y-coordinate of the cursor, in screen coordinates.</param>
Thomas@2352
   311
        /// <returns>True if the method succeeds, otherwise false.</returns>
Thomas@2352
   312
        [DllImport("user32.dll", SetLastError = true)]
Thomas@2352
   313
        [return: MarshalAs(UnmanagedType.Bool)]
Thomas@2352
   314
        internal static extern bool SetCursorPos(int x, int y);
Thomas@2557
   315
Thomas@2557
   316
        /// <summary>
Thomas@2557
   317
        ///     Changes the size, position, and Z order of a child, pop-up, or top-level window. These windows are ordered
Thomas@2557
   318
        ///     according to their appearance on the screen. The topmost window receives the highest rank and is the first window
Thomas@2557
   319
        ///     in the Z order.
Thomas@2557
   320
        ///     <para>See https://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx for more information.</para>
Thomas@2557
   321
        /// </summary>
Thomas@2557
   322
        /// <param name="hWnd">C++ ( hWnd [in]. Type: HWND )<br />A handle to the window.</param>
Thomas@2557
   323
        /// <param name="hWndInsertAfter">
Thomas@2557
   324
        ///     C++ ( hWndInsertAfter [in, optional]. Type: HWND )<br />A handle to the window to precede the positioned window in
Thomas@2557
   325
        ///     the Z order. This parameter must be a window handle or one of the following values.
Thomas@2557
   326
        ///     <list type="table">
Thomas@2557
   327
        ///     <itemheader>
Thomas@2557
   328
        ///         <term>HWND placement</term><description>Window to precede placement</description>
Thomas@2557
   329
        ///     </itemheader>
Thomas@2557
   330
        ///     <item>
Thomas@2557
   331
        ///         <term>HWND_BOTTOM ((HWND)1)</term>
Thomas@2557
   332
        ///         <description>
Thomas@2557
   333
        ///         Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost
Thomas@2557
   334
        ///         window, the window loses its topmost status and is placed at the bottom of all other windows.
Thomas@2557
   335
        ///         </description>
Thomas@2557
   336
        ///     </item>
Thomas@2557
   337
        ///     <item>
Thomas@2557
   338
        ///         <term>HWND_NOTOPMOST ((HWND)-2)</term>
Thomas@2557
   339
        ///         <description>
Thomas@2557
   340
        ///         Places the window above all non-topmost windows (that is, behind all topmost windows). This
Thomas@2557
   341
        ///         flag has no effect if the window is already a non-topmost window.
Thomas@2557
   342
        ///         </description>
Thomas@2557
   343
        ///     </item>
Thomas@2557
   344
        ///     <item>
Thomas@2557
   345
        ///         <term>HWND_TOP ((HWND)0)</term><description>Places the window at the top of the Z order.</description>
Thomas@2557
   346
        ///     </item>
Thomas@2557
   347
        ///     <item>
Thomas@2557
   348
        ///         <term>HWND_TOPMOST ((HWND)-1)</term>
Thomas@2557
   349
        ///         <description>
Thomas@2557
   350
        ///         Places the window above all non-topmost windows. The window maintains its topmost position
Thomas@2557
   351
        ///         even when it is deactivated.
Thomas@2557
   352
        ///         </description>
Thomas@2557
   353
        ///     </item>
Thomas@2557
   354
        ///     </list>
Thomas@2557
   355
        ///     <para>For more information about how this parameter is used, see the following Remarks section.</para>
Thomas@2557
   356
        /// </param>
Thomas@2557
   357
        /// <param name="x">C++ ( X [in]. Type: int )<br />The new position of the left side of the window, in client coordinates.</param>
Thomas@2557
   358
        /// <param name="y">C++ ( Y [in]. Type: int )<br />The new position of the top of the window, in client coordinates.</param>
Thomas@2557
   359
        /// <param name="cx">C++ ( cx [in]. Type: int )<br />The new width of the window, in pixels.</param>
Thomas@2557
   360
        /// <param name="cy">C++ ( cy [in]. Type: int )<br />The new height of the window, in pixels.</param>
Thomas@2557
   361
        /// <param name="uFlags">
Thomas@2557
   362
        ///     C++ ( uFlags [in]. Type: UINT )<br />The window sizing and positioning flags. This parameter can be a combination
Thomas@2557
   363
        ///     of the following values.
Thomas@2557
   364
        ///     <list type="table">
Thomas@2557
   365
        ///     <itemheader>
Thomas@2557
   366
        ///         <term>HWND sizing and positioning flags</term>
Thomas@2557
   367
        ///         <description>Where to place and size window. Can be a combination of any</description>
Thomas@2557
   368
        ///     </itemheader>
Thomas@2557
   369
        ///     <item>
Thomas@2557
   370
        ///         <term>SWP_ASYNCWINDOWPOS (0x4000)</term>
Thomas@2557
   371
        ///         <description>
Thomas@2557
   372
        ///         If the calling thread and the thread that owns the window are attached to different input
Thomas@2557
   373
        ///         queues, the system posts the request to the thread that owns the window. This prevents the calling
Thomas@2557
   374
        ///         thread from blocking its execution while other threads process the request.
Thomas@2557
   375
        ///         </description>
Thomas@2557
   376
        ///     </item>
Thomas@2557
   377
        ///     <item>
Thomas@2557
   378
        ///         <term>SWP_DEFERERASE (0x2000)</term>
Thomas@2557
   379
        ///         <description>Prevents generation of the WM_SYNCPAINT message. </description>
Thomas@2557
   380
        ///     </item>
Thomas@2557
   381
        ///     <item>
Thomas@2557
   382
        ///         <term>SWP_DRAWFRAME (0x0020)</term>
Thomas@2557
   383
        ///         <description>Draws a frame (defined in the window's class description) around the window.</description>
Thomas@2557
   384
        ///     </item>
Thomas@2557
   385
        ///     <item>
Thomas@2557
   386
        ///         <term>SWP_FRAMECHANGED (0x0020)</term>
Thomas@2557
   387
        ///         <description>
Thomas@2557
   388
        ///         Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message
Thomas@2557
   389
        ///         to the window, even if the window's size is not being changed. If this flag is not specified,
Thomas@2557
   390
        ///         WM_NCCALCSIZE is sent only when the window's size is being changed
Thomas@2557
   391
        ///         </description>
Thomas@2557
   392
        ///     </item>
Thomas@2557
   393
        ///     <item>
Thomas@2557
   394
        ///         <term>SWP_HIDEWINDOW (0x0080)</term><description>Hides the window.</description>
Thomas@2557
   395
        ///     </item>
Thomas@2557
   396
        ///     <item>
Thomas@2557
   397
        ///         <term>SWP_NOACTIVATE (0x0010)</term>
Thomas@2557
   398
        ///         <description>
Thomas@2557
   399
        ///         Does not activate the window. If this flag is not set, the window is activated and moved to
Thomas@2557
   400
        ///         the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter
Thomas@2557
   401
        ///         parameter).
Thomas@2557
   402
        ///         </description>
Thomas@2557
   403
        ///     </item>
Thomas@2557
   404
        ///     <item>
Thomas@2557
   405
        ///         <term>SWP_NOCOPYBITS (0x0100)</term>
Thomas@2557
   406
        ///         <description>
Thomas@2557
   407
        ///         Discards the entire contents of the client area. If this flag is not specified, the valid
Thomas@2557
   408
        ///         contents of the client area are saved and copied back into the client area after the window is sized or
Thomas@2557
   409
        ///         repositioned.
Thomas@2557
   410
        ///         </description>
Thomas@2557
   411
        ///     </item>
Thomas@2557
   412
        ///     <item>
Thomas@2557
   413
        ///         <term>SWP_NOMOVE (0x0002)</term>
Thomas@2557
   414
        ///         <description>Retains the current position (ignores X and Y parameters).</description>
Thomas@2557
   415
        ///     </item>
Thomas@2557
   416
        ///     <item>
Thomas@2557
   417
        ///         <term>SWP_NOOWNERZORDER (0x0200)</term>
Thomas@2557
   418
        ///         <description>Does not change the owner window's position in the Z order.</description>
Thomas@2557
   419
        ///     </item>
Thomas@2557
   420
        ///     <item>
Thomas@2557
   421
        ///         <term>SWP_NOREDRAW (0x0008)</term>
Thomas@2557
   422
        ///         <description>
Thomas@2557
   423
        ///         Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies
Thomas@2557
   424
        ///         to the client area, the nonclient area (including the title bar and scroll bars), and any part of the
Thomas@2557
   425
        ///         parent window uncovered as a result of the window being moved. When this flag is set, the application
Thomas@2557
   426
        ///         must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
Thomas@2557
   427
        ///         </description>
Thomas@2557
   428
        ///     </item>
Thomas@2557
   429
        ///     <item>
Thomas@2557
   430
        ///         <term>SWP_NOREPOSITION (0x0200)</term><description>Same as the SWP_NOOWNERZORDER flag.</description>
Thomas@2557
   431
        ///     </item>
Thomas@2557
   432
        ///     <item>
Thomas@2557
   433
        ///         <term>SWP_NOSENDCHANGING (0x0400)</term>
Thomas@2557
   434
        ///         <description>Prevents the window from receiving the WM_WINDOWPOSCHANGING message.</description>
Thomas@2557
   435
        ///     </item>
Thomas@2557
   436
        ///     <item>
Thomas@2557
   437
        ///         <term>SWP_NOSIZE (0x0001)</term>
Thomas@2557
   438
        ///         <description>Retains the current size (ignores the cx and cy parameters).</description>
Thomas@2557
   439
        ///     </item>
Thomas@2557
   440
        ///     <item>
Thomas@2557
   441
        ///         <term>SWP_NOZORDER (0x0004)</term>
Thomas@2557
   442
        ///         <description>Retains the current Z order (ignores the hWndInsertAfter parameter).</description>
Thomas@2557
   443
        ///     </item>
Thomas@2557
   444
        ///     <item>
Thomas@2557
   445
        ///         <term>SWP_SHOWWINDOW (0x0040)</term><description>Displays the window.</description>
Thomas@2557
   446
        ///     </item>
Thomas@2557
   447
        ///     </list>
Thomas@2557
   448
        /// </param>
Thomas@2557
   449
        /// <returns><c>true</c> or nonzero if the function succeeds, <c>false</c> or zero otherwise or if function fails.</returns>
Thomas@2557
   450
        /// <remarks>
Thomas@2557
   451
        ///     <para>
Thomas@2557
   452
        ///     As part of the Vista re-architecture, all services were moved off the interactive desktop into Session 0.
Thomas@2557
   453
        ///     hwnd and window manager operations are only effective inside a session and cross-session attempts to manipulate
Thomas@2557
   454
        ///     the hwnd will fail. For more information, see The Windows Vista Developer Story: Application Compatibility
Thomas@2557
   455
        ///     Cookbook.
Thomas@2557
   456
        ///     </para>
Thomas@2557
   457
        ///     <para>
Thomas@2557
   458
        ///     If you have changed certain window data using SetWindowLong, you must call SetWindowPos for the changes to
Thomas@2557
   459
        ///     take effect. Use the following combination for uFlags: SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
Thomas@2557
   460
        ///     SWP_FRAMECHANGED.
Thomas@2557
   461
        ///     </para>
Thomas@2557
   462
        ///     <para>
Thomas@2557
   463
        ///     A window can be made a topmost window either by setting the hWndInsertAfter parameter to HWND_TOPMOST and
Thomas@2557
   464
        ///     ensuring that the SWP_NOZORDER flag is not set, or by setting a window's position in the Z order so that it is
Thomas@2557
   465
        ///     above any existing topmost windows. When a non-topmost window is made topmost, its owned windows are also made
Thomas@2557
   466
        ///     topmost. Its owners, however, are not changed.
Thomas@2557
   467
        ///     </para>
Thomas@2557
   468
        ///     <para>
Thomas@2557
   469
        ///     If neither the SWP_NOACTIVATE nor SWP_NOZORDER flag is specified (that is, when the application requests that
Thomas@2557
   470
        ///     a window be simultaneously activated and its position in the Z order changed), the value specified in
Thomas@2557
   471
        ///     hWndInsertAfter is used only in the following circumstances.
Thomas@2557
   472
        ///     </para>
Thomas@2557
   473
        ///     <list type="bullet">
Thomas@2557
   474
        ///     <item>Neither the HWND_TOPMOST nor HWND_NOTOPMOST flag is specified in hWndInsertAfter. </item>
Thomas@2557
   475
        ///     <item>The window identified by hWnd is not the active window. </item>
Thomas@2557
   476
        ///     </list>
Thomas@2557
   477
        ///     <para>
Thomas@2557
   478
        ///     An application cannot activate an inactive window without also bringing it to the top of the Z order.
Thomas@2557
   479
        ///     Applications can change an activated window's position in the Z order without restrictions, or it can activate
Thomas@2557
   480
        ///     a window and then move it to the top of the topmost or non-topmost windows.
Thomas@2557
   481
        ///     </para>
Thomas@2557
   482
        ///     <para>
Thomas@2557
   483
        ///     If a topmost window is repositioned to the bottom (HWND_BOTTOM) of the Z order or after any non-topmost
Thomas@2557
   484
        ///     window, it is no longer topmost. When a topmost window is made non-topmost, its owners and its owned windows
Thomas@2557
   485
        ///     are also made non-topmost windows.
Thomas@2557
   486
        ///     </para>
Thomas@2557
   487
        ///     <para>
Thomas@2557
   488
        ///     A non-topmost window can own a topmost window, but the reverse cannot occur. Any window (for example, a
Thomas@2557
   489
        ///     dialog box) owned by a topmost window is itself made a topmost window, to ensure that all owned windows stay
Thomas@2557
   490
        ///     above their owner.
Thomas@2557
   491
        ///     </para>
Thomas@2557
   492
        ///     <para>
Thomas@2557
   493
        ///     If an application is not in the foreground, and should be in the foreground, it must call the
Thomas@2557
   494
        ///     SetForegroundWindow function.
Thomas@2557
   495
        ///     </para>
Thomas@2557
   496
        ///     <para>
Thomas@2557
   497
        ///     To use SetWindowPos to bring a window to the top, the process that owns the window must have
Thomas@2557
   498
        ///     SetForegroundWindow permission.
Thomas@2557
   499
        ///     </para>
Thomas@2557
   500
        /// </remarks>
Thomas@2557
   501
Thomas@2557
   502
        [DllImport("user32.dll", SetLastError = true)]
Thomas@2557
   503
        internal static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SetWindowPosFlags uFlags);
Thomas@2352
   504
        #endregion
Thomas@2401
   505
Thomas@2401
   506
        #region MAPI DLL Imports
Thomas@2401
   507
        /// <summary>
Thomas@2401
   508
        /// Increments the MAPI subsystem reference count and initializes global data for the MAPI DLL.
Thomas@2401
   509
        /// </summary>
Thomas@2401
   510
        /// <param name="mapiInit">Pointer to a MAPIINIT_0 structure. The mapiInit parameter can be set to IntPtr.Zero.</param>
Thomas@2401
   511
        /// <returns>The status of this method.</returns>
Thomas@2401
   512
        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi)]
Thomas@2401
   513
        internal static extern int MAPIInitialize(IntPtr mapiInit);
Thomas@2401
   514
Thomas@2401
   515
        /// <summary>
Thomas@2401
   516
        /// Decrements the reference count, cleans up, and deletes per-instance global data for the MAPI DLL.
Thomas@2401
   517
        /// </summary>
Thomas@2401
   518
        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi)]
Thomas@2401
   519
        internal static extern void MAPIUninitialize();
Thomas@2401
   520
Thomas@2401
   521
        /// <summary>
Thomas@2401
   522
        /// Retrieves the value of a single property from a property interface, that is, an interface derived from IMAPIProp.
Thomas@2401
   523
        /// </summary>
Thomas@2401
   524
        /// <param name="iMAPIProp">Pointer to the IMAPIProp interface from which the property value is to be retrieved.</param>
Thomas@2401
   525
        /// <param name="propTag">Property tag of the property to be retrieved.</param>
Thomas@2401
   526
        /// <param name="propertyValue">Pointer to a pointer to the returned SPropValue structure defining the retrieved property value.</param>
Thomas@2401
   527
        /// <remarks>
Thomas@2401
   528
        /// Unlike the IMAPIProp.GetProps method, the HrGetOneProp function never returns any warning.
Thomas@2401
   529
        /// Because it retrieves only one property, it simply either succeeds or fails. For retrieving multiple properties,
Thomas@2401
   530
        /// GetProps is faster.
Thomas@2401
   531
        /// </remarks>
Thomas@2401
   532
        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi, EntryPoint = "HrGetOneProp@12")]
Thomas@2401
   533
        internal static extern void HrGetOneProp(IntPtr iMAPIProp, uint propTag, out IntPtr propertyValue);
Thomas@2401
   534
Thomas@2401
   535
        /// <summary>
Thomas@2401
   536
        /// Sets or changes the value of a single property on a property interface, that is, an interface derived from IMAPIProp.
Thomas@2401
   537
        /// </summary>
Thomas@2401
   538
        /// <param name="iMAPIProp">Pointer to an IMAPIProp interface on which the property value is to be set or changed.</param>
Thomas@2401
   539
        /// <param name="propertyValue">[in] Pointer to the SPropValue structure defining the property to be set or changed.</param>
Thomas@2401
   540
        /// <remarks>
Thomas@2401
   541
        /// Unlike the IMAPIProp::SetProps method, the HrSetOneProp function never returns any warning.
Thomas@2401
   542
        /// Because it sets only one property, it simply either succeeds or fails.
Thomas@2401
   543
        /// For setting or changing multiple properties, SetProps is faster. 
Thomas@2401
   544
        /// </remarks>
Thomas@2401
   545
        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi, EntryPoint = "HrSetOneProp@8")]
Thomas@2401
   546
        internal static extern void HrSetOneProp(IntPtr iMAPIProp, IntPtr propertyValue);
Thomas@2401
   547
Thomas@2401
   548
        /// <summary>
Thomas@2401
   549
        /// Frees a memory buffer allocated with a call to the MAPIAllocateBuffer function or the MAPIAllocateMore function.
Thomas@2401
   550
        /// </summary>
Thomas@2401
   551
        /// <param name="buffer">Pointer to a previously allocated memory buffer. If IntPtr.Zero is passed in the buffer parameter, MAPIFreeBuffer does nothing.</param>
Thomas@2401
   552
        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi, EntryPoint = "MAPIFreeBuffer@4")]
Thomas@2401
   553
        internal static extern void MAPIFreeBuffer(IntPtr buffer);
Thomas@2401
   554
        #endregion
Thomas@1758
   555
    }
Thomas@1758
   556
}