1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace Microsoft.Tools.Common
8 using System.Runtime.InteropServices;
9 using System.Diagnostics.CodeAnalysis;
12 internal static class Win32Interop
14 public const int WM_SETICON = 0x80;
15 public const int WM_NCHITTEST = 0x84;
16 public const int WM_SYSCOMMAND = 0x0112;
18 public const int GWL_STYLE = -16;
19 public const int WS_MAXIMIZEBOX = 0x00010000;
20 public const int WS_MINIMIZEBOX = 0x00020000;
21 public const int WS_CLIPCHILDREN = 0x02000000;
22 public const int WS_CLIPSIBLINGS = 0x04000000;
24 public const int GWL_EXSTYLE = -20;
25 public const int WS_EX_DLGMODALFRAME = 0x00000001;
26 public const int WS_EX_CONTEXTHELP = 0x00000400;
28 public const int SC_CONTEXTHELP = 0xf180;
30 public const int ICON_SMALL = 0;
31 public const int ICON_BIG = 1;
34 [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "This class is shared by various projects and may not be used by a specific project")]
35 [StructLayout(LayoutKind.Sequential)]
36 public sealed class POINT
47 public POINT(int x, int y)
54 internal static void MakeWindowClipSiblingsAndChildren(HandleRef hwnd)
56 IntPtr windowStyle = Win32Interop.GetWindowLongPtr(hwnd.Handle, Win32Interop.GWL_STYLE);
59 windowStyle = new IntPtr(windowStyle.ToInt32() | Win32Interop.WS_CLIPSIBLINGS | Win32Interop.WS_CLIPCHILDREN);
63 windowStyle = new IntPtr(windowStyle.ToInt64() | ((long)Win32Interop.WS_CLIPSIBLINGS) | ((long)Win32Interop.WS_CLIPCHILDREN));
65 Win32Interop.SetWindowLongPtr(hwnd, Win32Interop.GWL_STYLE, (IntPtr)windowStyle);
68 // This static method is required because legacy OSes do not support
70 internal static IntPtr SetWindowLongPtr(HandleRef hWnd, int nIndex, IntPtr dwNewLong)
73 return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
75 return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()));
79 // This static method is required because Win32 does not support
80 // GetWindowLongPtr directly
81 public static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex)
84 return GetWindowLongPtr64(hWnd, nIndex);
86 return GetWindowLongPtr32(hWnd, nIndex);
89 [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
90 private static extern int SetWindowLong32(HandleRef hWnd, int nIndex, int dwNewLong);
92 [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
93 private static extern IntPtr SetWindowLongPtr64(HandleRef hWnd, int nIndex, IntPtr dwNewLong);
95 [SuppressMessage("Microsoft.Portability", "CA1901:PInvokeDeclarationsShouldBePortable", MessageId = "return", Justification = "Calling code is expected to handle the different size of IntPtr")]
96 [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
97 private static extern IntPtr GetWindowLongPtr32(IntPtr hWnd, int nIndex);
99 [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]
100 private static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
102 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "This function is shared by various projects and may not be used by a specific project")]
103 [DllImport("user32.dll")]
104 public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
106 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "This function is shared by various projects and may not be used by a specific project")]
107 [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
108 public static extern IntPtr GetActiveWindow();
110 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "This function is shared by various projects and may not be used by a specific project")]
111 [System.Runtime.InteropServices.DllImport("gdi32.dll")]
112 public static extern bool DeleteObject(IntPtr hObject);
114 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "This function is shared by various projects and may not be used by a specific project")]
115 [DllImport("User32", EntryPoint = "ScreenToClient", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
116 public static extern int ScreenToClient(IntPtr hWnd, [In, Out] POINT pt);