3 using System
.Runtime
.InteropServices
;
5 using Microsoft
.SDK
.Samples
.VistaBridge
.Library
;
6 using Microsoft
.SDK
.Samples
.VistaBridge
.Library
.StockIcons
;
7 namespace Microsoft
.SDK
.Samples
.VistaBridge
.Interop
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.
18 [SuppressUnmanagedCodeSecurity
]
19 internal static class UnsafeNativeMethods
21 // Various overloads of SendMessage.
22 [DllImport(ExternDll
.User32
,
23 CharSet
= CharSet
.Auto
,
25 internal static extern IntPtr
SendMessage(
32 [DllImport(ExternDll
.User32
,
33 CharSet
= CharSet
.Auto
,
35 internal static extern IntPtr
SendMessage(
39 [MarshalAs(UnmanagedType
.Bool
)] bool lParam
42 [DllImport(ExternDll
.User32
,
43 CharSet
= CharSet
.Auto
,
45 internal static extern IntPtr
SendMessage(
49 [MarshalAs(UnmanagedType
.LPWStr
)] string lParam
);
51 [DllImport(ExternDll
.User32
,
52 CharSet
= CharSet
.Auto
,
54 internal static extern IntPtr
SendMessage(
58 [MarshalAs(UnmanagedType
.LPWStr
)] StringBuilder lParam
);
60 [DllImport("ole32.dll",
61 CharSet
= CharSet
.Unicode
,
64 [return: MarshalAs(UnmanagedType
.Interface
)]
65 internal static extern object CoGetObject(
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(
82 // Handle to device context.
84 // Rectangle to draw in.
85 ref SafeNativeMethods
.RECT lprc
,
90 [DllImport("user32.dll")]
91 internal static extern int GetClientRect(
93 ref SafeNativeMethods
.RECT rect
);
95 [DllImport("gdi32.dll")]
96 internal static extern IntPtr
CreateRectRgn(
102 [DllImport("gdi32.dll")]
103 internal static extern IntPtr
CreateRoundRectRgn(
108 // Width of the ellipse used to create the rounded corners.
110 int heightOfEllipse
);
112 [DllImport("user32.dll")]
113 internal static extern int SetWindowRgn(
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
,
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(
140 ref SafeNativeMethods
.DWM_THUMBNAIL_PROPERTIES tp
);
142 [DllImport("DwmApi.dll")]
143 internal static extern int DwmQueryThumbnailSourceSize(
145 ref SafeNativeMethods
.SIZE size
);
147 [DllImport("DwmApi.dll")]
148 internal static extern int DwmSetWindowAttribute(
151 uint dwAttributeToSet
,
152 IntPtr pvAttributeValue
,
155 [DllImport("DwmApi.dll")]
156 internal static extern int DwmGetWindowAttribute(
159 uint dwAttributeToGet
,
160 IntPtr pvAttributeValue
,
163 [DllImport("DwmApi.dll")]
164 public static extern int DwmSetPresentParameters(
166 ref SafeNativeMethods
.DWM_PRESENT_PARAMETERS pPresentParams
);
168 [DllImport("DwmApi.dll")]
169 internal static extern int DwmSetDxFrameDuration(
173 [DllImport("DwmApi.dll")]
174 internal static extern int DwmModifyPreviousDxFrameDuration(
177 [MarshalAs(UnmanagedType
.Bool
)] bool fRelative
);
179 [DllImport("DwmApi.dll")]
180 internal static extern int DwmGetCompositionTimingInfo(
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(
192 ref SafeNativeMethods
.DWM_BLURBEHIND bb
);
194 [DllImport("DwmApi.dll")]
195 internal static extern int DwmExtendFrameIntoClientArea(
197 ref SafeNativeMethods
.MARGINS m
);
199 [DllImport("DwmApi.dll")]
200 internal static extern int DwmGetColorizationColor(
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
);