added samples
[windows-sources.git] / sdk / samples / CrossTechnologySamples / VistaBridge / vistabridgelibrary / interop / unsafenativemethods.cs
bloba9f2ac07a95efc2ef001bd6b3aeef491eeda7b87
1 using System;
2 using System.Text;
3 using System.Runtime.InteropServices;
4 using System.Security;
5 using Microsoft.SDK.Samples.VistaBridge.Library;
6 using Microsoft.SDK.Samples.VistaBridge.Library.StockIcons;
7 namespace Microsoft.SDK.Samples.VistaBridge.Interop
9 /// <summary>
10 /// Internal class that contains interop declarations for
11 /// performance critical native functions.
12 /// Note that NO security checking is done by the CLR,
13 /// because the unmanaged code security checks are disabled;
14 /// ANY usage of these methods must be properly
15 /// protected with the appropriate security demands.
16 /// </summary>
17 ///
18 [SuppressUnmanagedCodeSecurity]
19 internal static class UnsafeNativeMethods
21 // Various overloads of SendMessage.
22 [DllImport(ExternDll.User32,
23 CharSet = CharSet.Auto,
24 SetLastError = true)]
25 internal static extern IntPtr SendMessage(
26 IntPtr hWnd,
27 uint msg,
28 IntPtr wParam,
29 IntPtr lParam
32 [DllImport(ExternDll.User32,
33 CharSet = CharSet.Auto,
34 SetLastError = true)]
35 internal static extern IntPtr SendMessage(
36 IntPtr hWnd,
37 uint msg,
38 int wParam,
39 [MarshalAs(UnmanagedType.Bool)] bool lParam
42 [DllImport(ExternDll.User32,
43 CharSet = CharSet.Auto,
44 SetLastError = true)]
45 internal static extern IntPtr SendMessage(
46 IntPtr hWnd,
47 uint Msg,
48 int wParam,
49 [MarshalAs(UnmanagedType.LPWStr)] string lParam);
51 [DllImport(ExternDll.User32,
52 CharSet = CharSet.Auto,
53 SetLastError = true)]
54 internal static extern IntPtr SendMessage(
55 IntPtr hWnd,
56 uint Msg,
57 ref int wParam,
58 [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lParam);
60 [DllImport("ole32.dll",
61 CharSet = CharSet.Unicode,
62 ExactSpelling = true,
63 PreserveSig = false)]
64 [return: MarshalAs(UnmanagedType.Interface)]
65 internal static extern object CoGetObject(
66 string pszName,
67 [In] ref SafeNativeMethods.BIND_OPTS3 pBindOptions,
68 [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid);
70 #region GDI and DWM Declarations
72 [DllImport("user32.dll")]
73 internal static extern IntPtr GetDC(IntPtr hWnd);
75 [DllImport("user32.dll")]
76 internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hdc);
78 [DllImport("user32.dll")]
79 internal static extern int DrawCaption(
80 // Handle to window.
81 IntPtr hwnd,
82 // Handle to device context.
83 IntPtr hdc,
84 // Rectangle to draw in.
85 ref SafeNativeMethods.RECT lprc,
86 // drawing options.
87 int uFlags
90 [DllImport("user32.dll")]
91 internal static extern int GetClientRect(
92 IntPtr hwnd,
93 ref SafeNativeMethods.RECT rect);
95 [DllImport("gdi32.dll")]
96 internal static extern IntPtr CreateRectRgn(
97 int left,
98 int top,
99 int right,
100 int bottom);
102 [DllImport("gdi32.dll")]
103 internal static extern IntPtr CreateRoundRectRgn(
104 int left,
105 int top,
106 int right,
107 int bottom,
108 // Width of the ellipse used to create the rounded corners.
109 int widthOfEllipse,
110 int heightOfEllipse);
112 [DllImport("user32.dll")]
113 internal static extern int SetWindowRgn(
114 IntPtr hwnd,
115 IntPtr hrgn,
116 [MarshalAs(UnmanagedType.Bool)] bool redrawWindow);
118 [DllImport("DwmApi.dll")]
119 internal static extern int DwmEnableComposition(
120 [MarshalAs(UnmanagedType.Bool)] bool fEnabled);
122 [DllImport("DwmApi.dll")]
123 internal static extern int DwmIsCompositionEnabled(
124 [MarshalAs(UnmanagedType.Bool)] ref bool fEnabled);
126 [DllImport("DwmApi.dll")]
127 internal static extern int DwmRegisterThumbnail(
128 IntPtr hwndDestination,
129 IntPtr hwndSource,
130 ref SafeNativeMethods.SIZE minimizedSize,
131 ref IntPtr hThumbnailId);
133 [DllImport("DwmApi.dll")]
134 internal static extern int DwmUnregisterThumbnail(
135 IntPtr hThumbnailId);
137 [DllImport("DwmApi.dll")]
138 internal static extern int DwmUpdateThumbnailProperties(
139 IntPtr hThumbnailId,
140 ref SafeNativeMethods.DWM_THUMBNAIL_PROPERTIES tp);
142 [DllImport("DwmApi.dll")]
143 internal static extern int DwmQueryThumbnailSourceSize(
144 IntPtr hThumbnailId,
145 ref SafeNativeMethods.SIZE size);
147 [DllImport("DwmApi.dll")]
148 internal static extern int DwmSetWindowAttribute(
149 IntPtr hwnd,
150 //DWMWA_* values.
151 uint dwAttributeToSet,
152 IntPtr pvAttributeValue,
153 uint cbAttribute);
155 [DllImport("DwmApi.dll")]
156 internal static extern int DwmGetWindowAttribute(
157 IntPtr hwnd,
158 //DWMWA_* values.
159 uint dwAttributeToGet,
160 IntPtr pvAttributeValue,
161 uint cbAttribute);
163 [DllImport("DwmApi.dll")]
164 public static extern int DwmSetPresentParameters(
165 IntPtr hwnd,
166 ref SafeNativeMethods.DWM_PRESENT_PARAMETERS pPresentParams);
168 [DllImport("DwmApi.dll")]
169 internal static extern int DwmSetDxFrameDuration(
170 IntPtr hwnd,
171 int refreshes);
173 [DllImport("DwmApi.dll")]
174 internal static extern int DwmModifyPreviousDxFrameDuration(
175 IntPtr hwnd,
176 int refreshes,
177 [MarshalAs(UnmanagedType.Bool)] bool fRelative);
179 [DllImport("DwmApi.dll")]
180 internal static extern int DwmGetCompositionTimingInfo(
181 IntPtr hwnd,
182 IntPtr timingInfo);
184 [DllImport("DwmApi.dll")]
185 internal static extern int DwmEnableMMCSS(
186 [MarshalAs(UnmanagedType.Bool)] bool fEnableMMCSS);
189 [DllImport("DwmApi.dll")]
190 internal static extern int DwmEnableBlurBehindWindow(
191 IntPtr hwnd,
192 ref SafeNativeMethods.DWM_BLURBEHIND bb);
194 [DllImport("DwmApi.dll")]
195 internal static extern int DwmExtendFrameIntoClientArea(
196 IntPtr hwnd,
197 ref SafeNativeMethods.MARGINS m);
199 [DllImport("DwmApi.dll")]
200 internal static extern int DwmGetColorizationColor(
201 ref int color);
203 #endregion
205 #region StockIcon interop
207 [DllImport("Shell32.dll", CharSet = CharSet.Unicode,
208 ExactSpelling = true, SetLastError = false)]
209 internal static extern int SHGetStockIconInfo(
210 StockIconIdentifier identifier,
211 StockIconOptions flags,
212 ref SafeNativeMethods.StockIconInfo info);
214 [DllImport("User32.dll", SetLastError = true)]
215 [return: MarshalAs(UnmanagedType.Bool)]
216 internal static extern bool DestroyIcon(IntPtr handle);
218 #endregion