Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Misc / GDI / SafeNativeMethods.cs / 1 / SafeNativeMethods.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- #if WINFORMS_NAMESPACE namespace System.Windows.Forms.Internal #elif DRAWING_NAMESPACE namespace System.Drawing.Internal #else namespace System.Experimental.Gdi #endif { using System; using System.Internal; using System.Text; using System.Runtime.InteropServices; using System.ComponentModel; ////// This is an extract of the System.Drawing IntNativeMethods in the CommonUI tree. /// This is done to be able to compile the GDI code in both assemblies System.Drawing /// and System.Windows.Forms. /// [System.Security.SuppressUnmanagedCodeSecurityAttribute()] #if WINFORMS_PUBLIC_GRAPHICS_LIBRARY public #else internal #endif static partial class IntSafeNativeMethods { public sealed class CommonHandles { static CommonHandles(){} ////// Handle type for enhanced metafiles. /// public static readonly int EMF = System.Internal.HandleCollector.RegisterType("EnhancedMetaFile", 20, 500); ////// Handle type for GDI objects. /// public static readonly int GDI = System.Internal.HandleCollector.RegisterType("GDI", 90, 50); ////// Handle type for HDC's that count against the Win98 limit of five DC's. HDC's /// which are not scarce, such as HDC's for bitmaps, are counted as GDIHANDLE's. /// public static readonly int HDC = System.Internal.HandleCollector.RegisterType("HDC", 100, 2); // wait for 2 dc's before collecting } // Brush. [DllImport(ExternDll.Gdi32, SetLastError=true, ExactSpelling = true, EntryPoint = "CreateSolidBrush", CharSet = System.Runtime.InteropServices.CharSet.Auto)] private static extern IntPtr IntCreateSolidBrush(int crColor); public static IntPtr CreateSolidBrush(int crColor) { IntPtr hBrush = System.Internal.HandleCollector.Add(IntCreateSolidBrush(crColor), IntSafeNativeMethods.CommonHandles.GDI); DbgUtil.AssertWin32(hBrush != IntPtr.Zero, "IntCreateSolidBrush(color={0}) failed.", crColor); return hBrush; } // Pen. [DllImport(ExternDll.Gdi32, SetLastError=true, ExactSpelling = true, EntryPoint = "CreatePen", CharSet = System.Runtime.InteropServices.CharSet.Auto)] private static extern IntPtr IntCreatePen(int fnStyle, int nWidth, int crColor); public static IntPtr CreatePen(int fnStyle, int nWidth, int crColor) { IntPtr hPen = System.Internal.HandleCollector.Add(IntCreatePen(fnStyle, nWidth, crColor), IntSafeNativeMethods.CommonHandles.GDI); DbgUtil.AssertWin32(hPen != IntPtr.Zero, "IntCreatePen(style={0}, width={1}, color=[{2}]) failed.", fnStyle, nWidth, crColor); return hPen; } [DllImport(ExternDll.Gdi32, SetLastError=true, ExactSpelling = true, EntryPoint = "ExtCreatePen", CharSet = System.Runtime.InteropServices.CharSet.Auto)] private static extern IntPtr IntExtCreatePen(int fnStyle, int dwWidth, IntNativeMethods.LOGBRUSH lplb, int dwStyleCount, [MarshalAs(UnmanagedType.LPArray)] int[] lpStyle); public static IntPtr ExtCreatePen(int fnStyle, int dwWidth, IntNativeMethods.LOGBRUSH lplb, int dwStyleCount, int[] lpStyle) { IntPtr hPen = System.Internal.HandleCollector.Add(IntExtCreatePen(fnStyle, dwWidth, lplb, dwStyleCount, lpStyle), IntSafeNativeMethods.CommonHandles.GDI); DbgUtil.AssertWin32(hPen != IntPtr.Zero, "IntExtCreatePen(style={0}, width={1}, brush={2}, styleCount={3}, styles={4}) failed.", fnStyle, dwWidth, lplb, dwStyleCount, lpStyle); return hPen; } // Region [DllImport(ExternDll.Gdi32, SetLastError=true, ExactSpelling=true, EntryPoint="CreateRectRgn", CharSet=System.Runtime.InteropServices.CharSet.Auto)] public static extern IntPtr IntCreateRectRgn(int x1, int y1, int x2, int y2); public static IntPtr CreateRectRgn(int x1, int y1, int x2, int y2) { IntPtr hRgn = System.Internal.HandleCollector.Add(IntCreateRectRgn(x1, y1, x2, y2), IntSafeNativeMethods.CommonHandles.GDI); DbgUtil.AssertWin32(hRgn != IntPtr.Zero, "IntCreateRectRgn([x1={0}, y1={1}, x2={2}, y2={3}]) failed.", x1, y1, x2, y2); return hRgn; } // Misc. [DllImport(ExternDll.Kernel32, SetLastError=true, CharSet=System.Runtime.InteropServices.CharSet.Auto)] public static extern int GetUserDefaultLCID(); [DllImport(ExternDll.Gdi32, SetLastError=true, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] public static extern bool GdiFlush(); } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataRecordObjectView.cs
- MenuItemStyle.cs
- NoneExcludedImageIndexConverter.cs
- HotSpot.cs
- XmlTextReader.cs
- Gdiplus.cs
- DefinitionBase.cs
- TcpHostedTransportConfiguration.cs
- ExtendedTransformFactory.cs
- TreeViewHitTestInfo.cs
- DecimalAnimationUsingKeyFrames.cs
- SymbolPair.cs
- AdapterSwitches.cs
- GlyphElement.cs
- Focus.cs
- StandardTransformFactory.cs
- AuthenticationConfig.cs
- TextRange.cs
- AutomationElementIdentifiers.cs
- Quack.cs
- TakeQueryOptionExpression.cs
- RadialGradientBrush.cs
- WindowsGraphicsWrapper.cs
- ApplicationActivator.cs
- HybridObjectCache.cs
- DataPointer.cs
- MultipleViewProviderWrapper.cs
- XmlILModule.cs
- __FastResourceComparer.cs
- IOThreadScheduler.cs
- XmlSchemaObjectTable.cs
- ImageInfo.cs
- XPathPatternBuilder.cs
- FontSource.cs
- TrustSection.cs
- SecurityContextCookieSerializer.cs
- SecurityElement.cs
- GridViewColumnCollection.cs
- MetadataCache.cs
- WindowsIPAddress.cs
- RectValueSerializer.cs
- StartUpEventArgs.cs
- LineSegment.cs
- ConcatQueryOperator.cs
- ColumnWidthChangedEvent.cs
- SoapObjectReader.cs
- Keyboard.cs
- GradientStopCollection.cs
- EnumUnknown.cs
- Msec.cs
- InvalidOperationException.cs
- SelectionProcessor.cs
- Funcletizer.cs
- XmlEventCache.cs
- HttpStaticObjectsCollectionBase.cs
- StyleSelector.cs
- DeferredElementTreeState.cs
- DataStreams.cs
- TemplatePagerField.cs
- RemotingSurrogateSelector.cs
- Executor.cs
- XComponentModel.cs
- CreateUserErrorEventArgs.cs
- BasicSecurityProfileVersion.cs
- FontWeights.cs
- DbException.cs
- StrokeCollection2.cs
- Privilege.cs
- HashHelpers.cs
- DataTableMappingCollection.cs
- XmlCharCheckingReader.cs
- ListViewItem.cs
- Int16.cs
- IncrementalHitTester.cs
- XmlWhitespace.cs
- OleDbConnectionFactory.cs
- WebPartConnectionsCloseVerb.cs
- DataRelationPropertyDescriptor.cs
- TextUtf8RawTextWriter.cs
- UIElementAutomationPeer.cs
- ProxyAttribute.cs
- PingOptions.cs
- KeyEvent.cs
- MessageSmuggler.cs
- SByteConverter.cs
- ThreadExceptionEvent.cs
- _NestedMultipleAsyncResult.cs
- UpDownBase.cs
- WsdlInspector.cs
- IListConverters.cs
- JournalEntryListConverter.cs
- StoreItemCollection.cs
- AppDomainUnloadedException.cs
- RefreshPropertiesAttribute.cs
- JoinSymbol.cs
- LookupNode.cs
- NativeMethods.cs
- ComplexPropertyEntry.cs
- _IPv6Address.cs
- RequestCache.cs