--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ public enum CombineMode : int
+ {
+ RGN_AND = 1,
+ RGN_XOR = 3,
+ RGN_DIFF = 4,
+ }
+
+ [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true)]
+ public static extern RegionType CombineRgn(IntPtr hrgnDst, IntPtr hrgnSrc1, IntPtr hrgnSrc2, CombineMode iMode);
+
+ public static RegionType CombineRgn(HandleRef hrgnDst, HandleRef hrgnSrc1, HandleRef hrgnSrc2, CombineMode iMode)
+ {
+ RegionType result = CombineRgn(hrgnDst.Handle, hrgnSrc1.Handle, hrgnSrc2.Handle, iMode);
+ GC.KeepAlive(hrgnDst.Wrapper);
+ GC.KeepAlive(hrgnSrc1.Wrapper);
+ GC.KeepAlive(hrgnSrc2.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true, CharSet = CharSet.Unicode)]
+ public static extern IntPtr CreateDCW(string pwszDriver, string pwszDevice, string pszPort, IntPtr pdm);
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true, CharSet = CharSet.Unicode)]
+ public static extern IntPtr CreateFontIndirectW(ref User32.LOGFONT lplf);
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true, CharSet = CharSet.Unicode)]
+ public static extern IntPtr CreateICW(string pszDriver, string pszDevice, string pszPort, IntPtr pdm);
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern bool DeleteDC(IntPtr hdc);
+
+ public static bool DeleteDC(HandleRef hdc)
+ {
+ bool result = DeleteDC(hdc.Handle);
+ GC.KeepAlive(hdc.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern bool DeleteObject(IntPtr ho);
+
+ public static bool DeleteObject(HandleRef ho)
+ {
+ bool result = DeleteObject(ho.Handle);
+ GC.KeepAlive(ho.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern int GetClipRgn(IntPtr hdc, IntPtr hrgn);
+
+ public static int GetClipRgn(HandleRef hdc, IntPtr hrgn)
+ {
+ int result = GetClipRgn(hdc.Handle, hrgn);
+ GC.KeepAlive(hdc.Wrapper);
+ return result;
+ }
+
+ public static int GetClipRgn(HandleRef hdc, HandleRef hrgn)
+ {
+ int result = GetClipRgn(hdc.Handle, hrgn.Handle);
+ GC.KeepAlive(hdc.Wrapper);
+ GC.KeepAlive(hrgn.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern IntPtr GetCurrentObject(IntPtr hdc, ObjectType type);
+
+ public static IntPtr GetCurrentObject(HandleRef hdc, ObjectType type)
+ {
+ IntPtr result = GetCurrentObject(hdc.Handle, type);
+ GC.KeepAlive(hdc.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ public enum DeviceCapability : int
+ {
+ TECHNOLOGY = 2,
+ VERTRES = 10,
+ HORZRES = 8,
+ BITSPIXEL = 12,
+ PLANES = 14,
+ LOGPIXELSX = 88,
+ LOGPIXELSY = 90,
+ PHYSICALWIDTH = 110,
+ PHYSICALHEIGHT = 111,
+ PHYSICALOFFSETX = 112,
+ PHYSICALOFFSETY = 113
+ }
+
+ public static class DeviceTechnology
+ {
+ public const int DT_PLOTTER = 0;
+ public const int DT_RASPRINTER = 2;
+ }
+
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern int GetDeviceCaps(IntPtr hdc, DeviceCapability index);
+
+ public static int GetDeviceCaps(HandleRef hdc, DeviceCapability index)
+ {
+ int caps = GetDeviceCaps(hdc.Handle, index);
+ GC.KeepAlive(hdc.Wrapper);
+ return caps;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern ObjectType GetObjectType(IntPtr h);
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern RegionType GetRgnBox(IntPtr hrgn, ref RECT lprc);
+
+ public static RegionType GetRgnBox(HandleRef hrgn, ref RECT lprc)
+ {
+ RegionType result = GetRgnBox(hrgn.Handle, ref lprc);
+ GC.KeepAlive(hrgn.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ public enum StockObject : int
+ {
+ DEFAULT_GUI_FONT = 17
+ }
+
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern IntPtr GetStockObject(StockObject i);
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ public enum ObjectType : int
+ {
+ OBJ_PEN = 1,
+ OBJ_BRUSH = 2,
+ OBJ_DC = 3,
+ OBJ_METADC = 4,
+ OBJ_PAL = 5,
+ OBJ_FONT = 6,
+ OBJ_BITMAP = 7,
+ OBJ_REGION = 8,
+ OBJ_METAFILE = 9,
+ OBJ_MEMDC = 10,
+ OBJ_EXTPEN = 11,
+ OBJ_ENHMETADC = 12,
+ OBJ_ENHMETAFILE = 13,
+ OBJ_COLORSPACE = 14
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Drawing;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern bool OffsetViewportOrgEx(IntPtr hdc, int x, int y, ref Point lppt);
+
+ public static bool OffsetViewportOrgEx(HandleRef hdc, int x, int y, ref Point lppt)
+ {
+ bool result = OffsetViewportOrgEx(hdc.Handle, x, y, ref lppt);
+ GC.KeepAlive(hdc.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Drawing;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [StructLayout(LayoutKind.Sequential)]
+ public struct RECT
+ {
+ public int left;
+ public int top;
+ public int right;
+ public int bottom;
+
+ public Size Size => new Size(right - left, bottom - top);
+ }
+ }
+}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-namespace System.Drawing.Internal
+internal static partial class Interop
{
- internal enum RegionCombineMode
+ internal enum RegionType : int
{
- AND = 1,
- OR = 2,
- XOR = 3,
- DIFF = 4,
- COPY = 5,
- MIN = AND,
- MAX = COPY
+ ERROR = 0,
+ NULLREGION = 1,
+ SIMPLEREGION = 2,
+ COMPLEXREGION = 3,
}
}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern bool RestoreDC(IntPtr hdc, int nSavedDC);
+
+ public static bool RestoreDC(HandleRef hdc, int nSavedDC)
+ {
+ bool result = RestoreDC(hdc.Handle, nSavedDC);
+ GC.KeepAlive(hdc.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, ExactSpelling = true)]
+ public static extern int SaveDC(IntPtr hdc);
+
+ public static int SaveDC(HandleRef hdc)
+ {
+ int result = SaveDC(hdc.Handle);
+ GC.KeepAlive(hdc.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Gdi32
+ {
+ [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true)]
+ public static extern RegionType SelectClipRgn(IntPtr hdc, IntPtr hrgn);
+
+ public static RegionType SelectClipRgn(HandleRef hdc, IntPtr hrgn)
+ {
+ RegionType result = SelectClipRgn(hdc.Handle, hrgn);
+ GC.KeepAlive(hdc.Wrapper);
+ return result;
+ }
+
+ public static RegionType SelectClipRgn(HandleRef hdc, HandleRef hrgn)
+ {
+ RegionType result = SelectClipRgn(hdc.Handle, hrgn.Handle);
+ GC.KeepAlive(hdc.Wrapper);
+ GC.KeepAlive(hrgn.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class User32
+ {
+ [DllImport(Libraries.User32, ExactSpelling = true)]
+ public static extern IntPtr GetDC(IntPtr hWnd);
+
+ public static IntPtr GetDC(HandleRef hWnd)
+ {
+ IntPtr dc = GetDC(hWnd.Handle);
+ GC.KeepAlive(hWnd.Wrapper);
+ return dc;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class User32
+ {
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+ public unsafe struct LOGFONT
+ {
+ private const int LF_FACESIZE = 32;
+
+ public int lfHeight;
+ public int lfWidth;
+ public int lfEscapement;
+ public int lfOrientation;
+ public int lfWeight;
+ public byte lfItalic;
+ public byte lfUnderline;
+ public byte lfStrikeOut;
+ public byte lfCharSet;
+ public byte lfOutPrecision;
+ public byte lfClipPrecision;
+ public byte lfQuality;
+ public byte lfPitchAndFamily;
+ private fixed char _lfFaceName[LF_FACESIZE];
+ public Span<char> lfFaceName
+ {
+ get { fixed (char* c = _lfFaceName) { return new Span<char>(c, LF_FACESIZE); } }
+ }
+
+ public override string ToString()
+ {
+ return
+ "lfHeight=" + lfHeight + ", " +
+ "lfWidth=" + lfWidth + ", " +
+ "lfEscapement=" + lfEscapement + ", " +
+ "lfOrientation=" + lfOrientation + ", " +
+ "lfWeight=" + lfWeight + ", " +
+ "lfItalic=" + lfItalic + ", " +
+ "lfUnderline=" + lfUnderline + ", " +
+ "lfStrikeOut=" + lfStrikeOut + ", " +
+ "lfCharSet=" + lfCharSet + ", " +
+ "lfOutPrecision=" + lfOutPrecision + ", " +
+ "lfClipPrecision=" + lfClipPrecision + ", " +
+ "lfQuality=" + lfQuality + ", " +
+ "lfPitchAndFamily=" + lfPitchAndFamily + ", " +
+ "lfFaceName=" + lfFaceName.ToString();
+ }
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Drawing;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class User32
+ {
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+ public struct NONCLIENTMETRICS
+ {
+ public uint cbSize;
+ public int iBorderWidth;
+ public int iScrollWidth;
+ public int iScrollHeight;
+ public int iCaptionWidth;
+ public int iCaptionHeight;
+ public LOGFONT lfCaptionFont;
+ public int iSmCaptionWidth;
+ public int iSmCaptionHeight;
+ public LOGFONT lfSmCaptionFont;
+ public int iMenuWidth;
+ public int iMenuHeight;
+ public LOGFONT lfMenuFont;
+ public LOGFONT lfStatusFont;
+ public LOGFONT lfMessageFont;
+ public int iPaddedBorderWidth;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class User32
+ {
+ [DllImport(Libraries.User32, ExactSpelling = true)]
+ public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
+
+ public static int ReleaseDC(HandleRef hWnd, IntPtr hDC)
+ {
+ int result = ReleaseDC(hWnd.Handle, hDC);
+ GC.KeepAlive(hWnd.Wrapper);
+ return result;
+ }
+
+ public static int ReleaseDC(HandleRef hWnd, HandleRef hDC)
+ {
+ int result = ReleaseDC(hWnd.Handle, hDC.Handle);
+ GC.KeepAlive(hWnd.Wrapper);
+ GC.KeepAlive(hDC.Wrapper);
+ return result;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class User32
+ {
+ public enum SystemParametersAction : uint
+ {
+ SPI_GETICONTITLELOGFONT = 0x1F,
+ SPI_GETNONCLIENTMETRICS = 0x29
+ }
+
+ [DllImport(Libraries.User32, ExactSpelling = true, CharSet = CharSet.Unicode)]
+ public static extern unsafe bool SystemParametersInfoW(SystemParametersAction uiAction, uint uiParam, void* pvParam, uint fWinIni);
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class User32
+ {
+ [DllImport(Libraries.User32, ExactSpelling = true)]
+ public static extern IntPtr WindowFromDC(IntPtr hDC);
+
+ public static IntPtr WindowFromDC(HandleRef hDC)
+ {
+ IntPtr result = WindowFromDC(hDC.Handle);
+ GC.KeepAlive(hDC.Wrapper);
+ return result;
+ }
+ }
+}
gdi32.dll!CombineRgn
gdi32.dll!CreateCompatibleBitmap
gdi32.dll!CreateCompatibleDC
-gdi32.dll!CreateCompatibleDC
-gdi32.dll!CreateDC
+gdi32.dll!CreateDCW
gdi32.dll!CreateDIBSection
-gdi32.dll!CreateFontIndirect
-gdi32.dll!CreateIC
-gdi32.dll!CreateRectRgn
+gdi32.dll!CreateFontIndirectW
+gdi32.dll!CreateICW
gdi32.dll!CreateRectRgn
gdi32.dll!DeleteDC
-gdi32.dll!DeleteDC
-gdi32.dll!DeleteObject
gdi32.dll!DeleteObject
gdi32.dll!EndDoc
gdi32.dll!EndPage
gdi32.dll!ExtEscape
gdi32.dll!ExtEscape
gdi32.dll!GetClipRgn
-gdi32.dll!GetClipRgn
gdi32.dll!GetCurrentObject
gdi32.dll!GetDeviceCaps
gdi32.dll!GetDIBits
gdi32.dll!GetObject
-gdi32.dll!GetObject
gdi32.dll!GetObjectType
gdi32.dll!GetPaletteEntries
gdi32.dll!GetRgnBox
gdi32.dll!RestoreDC
gdi32.dll!SaveDC
gdi32.dll!SelectClipRgn
-gdi32.dll!SelectClipRgn
gdi32.dll!SelectObject
gdi32.dll!StartDoc
gdi32.dll!StartPage
user32.dll!GetSystemMetrics
user32.dll!LoadIcon
user32.dll!ReleaseDC
-user32.dll!ReleaseDC
-user32.dll!SystemParametersInfo
-user32.dll!SystemParametersInfo
+user32.dll!SystemParametersInfoW
user32.dll!WindowFromDC
winspool.drv!DeviceCapabilities
winspool.drv!DocumentProperties
-winspool.drv!DocumentProperties
winspool.drv!EnumPrinters
<Compile Include="System\Drawing\Brush.cs" />
<Compile Include="System\Drawing\Font.cs" />
<Compile Include="System\Drawing\FontFamily.cs" />
- <Compile Include="System\Drawing\ScreenDC.cs" />
<Compile Include="System\Drawing\SolidBrush.cs" />
<Compile Include="System\Drawing\SystemBrushes.cs" />
<Compile Include="System\Drawing\TextureBrush.cs" />
<Compile Include="System\Drawing\Imaging\ImageCodecInfo.cs" />
<Compile Include="System\Drawing\Imaging\ImageCodecInfoPrivate.cs" />
<Compile Include="System\Drawing\Imaging\MetafileFrameUnit.cs" />
+ <Compile Include="$(CommonPath)\Interop\Windows\User32\Interop.LOGFONT.cs">
+ <Link>Common\Interop\Windows\User32\Interop.LOGFONT.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.RasterOp.cs">
<Link>Common\Interop\Windows\Gdi32\Interop.RasterOp.cs</Link>
</Compile>
<Compile Include="System\Drawing\Printing\PrintPreviewGraphics.cs" />
<Compile Include="System\Drawing\Printing\TriState.cs" />
<Compile Include="System\Drawing\Region.Windows.cs" />
+ <Compile Include="System\Drawing\ScreenDC.cs" />
<Compile Include="System\Drawing\SystemFonts.Windows.cs" />
<Compile Include="System\Drawing\SystemIcons.Windows.cs" />
<Compile Include="System\Drawing\ToolboxBitmapAttribute.cs" />
<Compile Include="misc\GDI\DeviceContext.cs" />
<Compile Include="misc\GDI\DeviceContexts.cs" />
<Compile Include="misc\GDI\DeviceContextType.cs" />
- <Compile Include="misc\GDI\NativeMethods.cs" />
- <Compile Include="misc\GDI\SafeNativeMethods.cs" />
- <Compile Include="misc\GDI\UnsafeNativeMethods.cs" />
<Compile Include="misc\GDI\WindowsGraphics.cs" />
<Compile Include="misc\GDI\WindowsRegion.cs" />
- <Compile Include="misc\GDI\WindowsRegionCombineMode.cs" />
<Compile Include="$(CommonPath)\CoreLib\System\LocalAppContextSwitches.Common.cs">
<Link>Common\CoreLib\System\LocalAppContextSwitches.Common.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
<Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.CombineRgn.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.CombineRgn.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.CreateCompatibleDC.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.CreateCompatibleDC.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.CreateDC.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.CreateDC.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.CreateIC.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.CreateIC.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.CreateFontIndirect.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.CreateFontIndirect.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.CreateRectRgn.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.CreateRectRgn.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.DeleteDC.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.DeleteDC.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.DeleteObject.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.DeleteObject.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.GetClipRgn.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.GetClipRgn.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.GetCurrentObject.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.GetCurrentObject.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.GetDeviceCaps.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.GetDeviceCaps.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.GetObjectType.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.GetObjectType.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.GetRgnBox.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.GetRgnBox.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.GetStockObject.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.GetStockObject.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.ObjectType.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.ObjectType.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.OffsetViewportOrgEx.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.OffsetViewportOrgEx.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.RECT.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.RECT.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.RegionType.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.RegionType.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.RestoreDC.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.RestoreDC.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.SaveDC.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.SaveDC.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Gdi32\Interop.SelectClipRgn.cs">
+ <Link>Common\Interop\Windows\Gdi32\Interop.SelectClipRgn.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.FreeLibrary.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.FreeLibrary.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Ole32\Interop.STGM.cs">
<Link>Common\Interop\Windows\Ole32\Interop.STGM.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\User32\Interop.GetDC.cs">
+ <Link>Common\Interop\Windows\User32\Interop.GetDC.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\User32\Interop.ReleaseDC.cs">
+ <Link>Common\Interop\Windows\User32\Interop.ReleaseDC.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\User32\Interop.SystemParametersInfo.cs">
+ <Link>Common\Interop\Windows\User32\Interop.SystemParametersInfo.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\User32\Interop.NONCLIENTMETRICS.cs">
+ <Link>Common\Interop\Windows\User32\Interop.NONCLIENTMETRICS.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\User32\Interop.WindowFromDC.cs">
+ <Link>Common\Interop\Windows\User32\Interop.WindowFromDC.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Interop.HRESULT.cs">
<Link>Common\Interop\Windows\Interop.HRESULT.cs</Link>
</Compile>
{
if (hbm != IntPtr.Zero)
{
- SafeNativeMethods.DeleteObject(new HandleRef(null, hbm));
+ Interop.Gdi32.DeleteObject(hbm);
hbm = IntPtr.Zero;
}
}
_busy = BufferBusyDisposing;
DisposeDC();
_busy = BufferBusyPainting;
- _compatDC = UnsafeNativeMethods.CreateCompatibleDC(new HandleRef(null, src));
+ _compatDC = Interop.Gdi32.CreateCompatibleDC(src);
// Recreate the bitmap if necessary.
if (width > _bufferSize.Width || height > _bufferSize.Height)
var pbmi = new NativeMethods.BITMAPINFO_FLAT();
// Validate hdc.
- int objType = UnsafeNativeMethods.GetObjectType(new HandleRef(null, hdc));
-
+ Interop.Gdi32.ObjectType objType = Interop.Gdi32.GetObjectType(hdc);
switch (objType)
{
- case NativeMethods.OBJ_DC:
- case NativeMethods.OBJ_METADC:
- case NativeMethods.OBJ_MEMDC:
- case NativeMethods.OBJ_ENHMETADC:
+ case Interop.Gdi32.ObjectType.OBJ_DC:
+ case Interop.Gdi32.ObjectType.OBJ_METADC:
+ case Interop.Gdi32.ObjectType.OBJ_MEMDC:
+ case Interop.Gdi32.ObjectType.OBJ_ENHMETADC:
break;
default:
throw new ArgumentException(SR.DCTypeInvalid);
if (_compatDC != IntPtr.Zero)
{
- UnsafeNativeMethods.DeleteDC(new HandleRef(this, _compatDC));
+ Interop.Gdi32.DeleteDC(new HandleRef(this, _compatDC));
_compatDC = IntPtr.Zero;
}
}
{
Debug.Assert(_oldBitmap == IntPtr.Zero);
- SafeNativeMethods.DeleteObject(new HandleRef(this, _dib));
+ Interop.Gdi32.DeleteObject(new HandleRef(this, _dib));
_dib = IntPtr.Zero;
}
}
IntPtr newObject;
FontStyle newStyle = FontStyle.Regular;
float newSize;
- SafeNativeMethods.LOGFONT lf = new SafeNativeMethods.LOGFONT();
+ Interop.User32.LOGFONT lf = new Interop.User32.LOGFONT();
// Sanity. Should we throw an exception?
if (hfont == IntPtr.Zero)
public static Font FromLogFont(object lf, IntPtr hdc)
{
IntPtr newObject;
- SafeNativeMethods.LOGFONT o = (SafeNativeMethods.LOGFONT)lf;
+ Interop.User32.LOGFONT o = (Interop.User32.LOGFONT)lf;
int status = Gdip.GdipCreateFontFromLogfont(hdc, ref o, out newObject);
Gdip.CheckStatus(status);
return new Font(newObject, "Microsoft Sans Serif", FontStyle.Regular, 10);
/// </summary>
public static Font FromHfont(IntPtr hfont)
{
- var logFont = new SafeNativeMethods.LOGFONT();
+ var logFont = new Interop.User32.LOGFONT();
SafeNativeMethods.GetObject(new HandleRef(null, hfont), ref logFont);
using (ScreenDC dc = ScreenDC.Create())
}
}
- internal static Font FromLogFont(ref SafeNativeMethods.LOGFONT logFont)
+ internal static Font FromLogFont(ref Interop.User32.LOGFONT logFont)
{
using (ScreenDC dc = ScreenDC.Create())
{
}
}
- internal static Font FromLogFontInternal(ref SafeNativeMethods.LOGFONT logFont, IntPtr hdc)
+ internal static Font FromLogFontInternal(ref Interop.User32.LOGFONT logFont, IntPtr hdc)
{
int status = Gdip.GdipCreateFontFromLogfontW(hdc, ref logFont, out IntPtr font);
throw new ArgumentNullException(nameof(lf));
}
- if (lf is SafeNativeMethods.LOGFONT logFont)
+ if (lf is Interop.User32.LOGFONT logFont)
{
// A boxed LOGFONT, just use it to create the font
return FromLogFontInternal(ref logFont, hdc);
}
Type type = lf.GetType();
- int nativeSize = sizeof(SafeNativeMethods.LOGFONT);
+ int nativeSize = sizeof(Interop.User32.LOGFONT);
if (Marshal.SizeOf(type) != nativeSize)
{
// If we don't actually have an object that is LOGFONT in size, trying to pass
}
// Now that we know the marshalled size is the same as LOGFONT, copy in the data
- logFont = new SafeNativeMethods.LOGFONT();
+ logFont = new Interop.User32.LOGFONT();
Marshal.StructureToPtr(lf, new IntPtr(&logFont), fDeleteOld: false);
using (ScreenDC dc = ScreenDC.Create())
using (Graphics graphics = Graphics.FromHdcInternal(dc))
{
- SafeNativeMethods.LOGFONT lf = ToLogFontInternal(graphics);
- IntPtr handle = IntUnsafeNativeMethods.CreateFontIndirect(ref lf);
+ Interop.User32.LOGFONT lf = ToLogFontInternal(graphics);
+ IntPtr handle = Interop.Gdi32.CreateFontIndirectW(ref lf);
if (handle == IntPtr.Zero)
{
throw new Win32Exception();
}
Type type = logFont.GetType();
- int nativeSize = sizeof(SafeNativeMethods.LOGFONT);
+ int nativeSize = sizeof(Interop.User32.LOGFONT);
if (Marshal.SizeOf(type) != nativeSize)
{
// If we don't actually have an object that is LOGFONT in size, trying to pass
throw new ArgumentException();
}
- SafeNativeMethods.LOGFONT nativeLogFont = ToLogFontInternal(graphics);
+ Interop.User32.LOGFONT nativeLogFont = ToLogFontInternal(graphics);
// PtrToStructure requires that the passed in object not be a value type.
if (!type.IsValueType)
}
}
- private unsafe SafeNativeMethods.LOGFONT ToLogFontInternal(Graphics graphics)
+ private unsafe Interop.User32.LOGFONT ToLogFontInternal(Graphics graphics)
{
if (graphics == null)
{
throw new ArgumentNullException(nameof(graphics));
}
- SafeNativeMethods.LOGFONT logFont = new SafeNativeMethods.LOGFONT();
+ Interop.User32.LOGFONT logFont = new Interop.User32.LOGFONT();
Gdip.CheckStatus(Gdip.GdipGetLogFontW(
new HandleRef(this, NativeFont), new HandleRef(graphics, graphics.NativeGraphics), ref logFont));
GMEM_ZEROINIT = 0x0040,
DM_IN_BUFFER = 8,
DM_OUT_BUFFER = 2,
- DT_PLOTTER = 0,
- DT_RASPRINTER = 2,
- TECHNOLOGY = 2,
DC_PAPERS = 2,
DC_PAPERSIZE = 3,
DC_BINS = 6,
IDI_WARNING = 32515,
IDI_ERROR = 32513,
IDI_INFORMATION = 32516,
- PLANES = 14,
- BITSPIXEL = 12,
- LOGPIXELSX = 88,
- LOGPIXELSY = 90,
- PHYSICALWIDTH = 110,
- PHYSICALHEIGHT = 111,
- PHYSICALOFFSETX = 112,
- PHYSICALOFFSETY = 113,
- VERTRES = 10,
- HORZRES = 8,
DM_ORIENTATION = 0x00000001,
DM_PAPERSIZE = 0x00000002,
DM_PAPERLENGTH = 0x00000004,
[DllImport(ExternDll.Gdi32, SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr /*HDC*/ ResetDC(HandleRef hDC, HandleRef /*DEVMODE*/ lpDevMode);
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)]
- public static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- public static extern int GetClipRgn(HandleRef hDC, HandleRef hRgn);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- public static extern int SelectClipRgn(HandleRef hDC, HandleRef hRgn);
-
[DllImport(ExternDll.Gdi32, SetLastError = true, CharSet = CharSet.Auto)]
public static extern int AddFontResourceEx(string lpszFilename, int fl, IntPtr pdv);
return AddFontResourceEx(fileName, /*FR_PRIVATE*/ 0x10, IntPtr.Zero);
}
- internal static IntPtr SaveClipRgn(IntPtr hDC)
- {
- IntPtr hTempRgn = CreateRectRgn(0, 0, 0, 0);
- IntPtr hSaveRgn = IntPtr.Zero;
- try
- {
- int result = GetClipRgn(new HandleRef(null, hDC), new HandleRef(null, hTempRgn));
- if (result > 0)
- {
- hSaveRgn = hTempRgn;
- hTempRgn = IntPtr.Zero;
- }
- }
- finally
- {
- if (hTempRgn != IntPtr.Zero)
- {
- DeleteObject(new HandleRef(null, hTempRgn));
- }
- }
-
- return hSaveRgn;
- }
-
- internal static void RestoreClipRgn(IntPtr hDC, IntPtr hRgn)
- {
- try
- {
- SelectClipRgn(new HandleRef(null, hDC), new HandleRef(null, hRgn));
- }
- finally
- {
- if (hRgn != IntPtr.Zero)
- {
- DeleteObject(new HandleRef(null, hRgn));
- }
- }
- }
-
[DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern int ExtEscape(HandleRef hDC, int nEscape, int cbInput, ref int inData, int cbOutput, [Out] out int outData);
public int biClrImportant;
}
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public unsafe struct LOGFONT
- {
- private const int LF_FACESIZE = 32;
-
- public int lfHeight;
- public int lfWidth;
- public int lfEscapement;
- public int lfOrientation;
- public int lfWeight;
- public byte lfItalic;
- public byte lfUnderline;
- public byte lfStrikeOut;
- public byte lfCharSet;
- public byte lfOutPrecision;
- public byte lfClipPrecision;
- public byte lfQuality;
- public byte lfPitchAndFamily;
- private fixed char _lfFaceName[LF_FACESIZE];
- public Span<char> lfFaceName
- {
- get { fixed (char* c = _lfFaceName) { return new Span<char>(c, LF_FACESIZE); } }
- }
-
- public override string ToString()
- {
- return
- "lfHeight=" + lfHeight + ", " +
- "lfWidth=" + lfWidth + ", " +
- "lfEscapement=" + lfEscapement + ", " +
- "lfOrientation=" + lfOrientation + ", " +
- "lfWeight=" + lfWeight + ", " +
- "lfItalic=" + lfItalic + ", " +
- "lfUnderline=" + lfUnderline + ", " +
- "lfStrikeOut=" + lfStrikeOut + ", " +
- "lfCharSet=" + lfCharSet + ", " +
- "lfOutPrecision=" + lfOutPrecision + ", " +
- "lfClipPrecision=" + lfClipPrecision + ", " +
- "lfQuality=" + lfQuality + ", " +
- "lfPitchAndFamily=" + lfPitchAndFamily + ", " +
- "lfFaceName=" + lfFaceName.ToString();
- }
- }
-
// https://devblogs.microsoft.com/oldnewthing/20101018-00/?p=12513
// https://devblogs.microsoft.com/oldnewthing/20120720-00/?p=7083
}
}
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, EntryPoint = "DeleteObject", CharSet = CharSet.Auto)]
- internal static extern int IntDeleteObject(HandleRef hObject);
-
- public static int DeleteObject(HandleRef hObject)
- {
- return IntDeleteObject(hObject);
- }
-
[DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern IntPtr SelectObject(HandleRef hdc, HandleRef obj);
public static extern int GetObject(HandleRef hObject, int nSize, ref BITMAP bm);
[DllImport(ExternDll.Gdi32, SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern int GetObject(HandleRef hObject, int nSize, ref LOGFONT lf);
+ public static extern int GetObject(HandleRef hObject, int nSize, ref Interop.User32.LOGFONT lf);
- public static unsafe int GetObject(HandleRef hObject, ref LOGFONT lp)
- => GetObject(hObject, sizeof(LOGFONT), ref lp);
+ public static unsafe int GetObject(HandleRef hObject, ref Interop.User32.LOGFONT lp)
+ => GetObject(hObject, sizeof(Interop.User32.LOGFONT), ref lp);
[DllImport(ExternDll.User32, SetLastError = true, ExactSpelling = true)]
public static extern bool GetIconInfo(HandleRef hIcon, ref ICONINFO info);
internal static extern int GdipIsOutlineVisiblePathPointI(IntPtr path, int x, int y, IntPtr pen, IntPtr graphics, out bool result);
[DllImport(LibraryName, ExactSpelling = true)]
- internal static extern int GdipCreateFontFromLogfont(IntPtr hdc, ref LOGFONT lf, out IntPtr ptr);
+ internal static extern int GdipCreateFontFromLogfont(IntPtr hdc, ref Interop.User32.LOGFONT lf, out IntPtr ptr);
[DllImport(LibraryName, ExactSpelling = true)]
- internal static extern int GdipCreateFontFromHfont(IntPtr hdc, out IntPtr font, ref LOGFONT lf);
+ internal static extern int GdipCreateFontFromHfont(IntPtr hdc, out IntPtr font, ref Interop.User32.LOGFONT lf);
[DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
internal static extern int GdipGetMetafileHeaderFromFile(string filename, IntPtr header);
internal static extern int GdipComment(HandleRef graphics, int sizeData, byte[] data);
[DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
- internal static extern int GdipCreateFontFromLogfontW(IntPtr hdc, ref LOGFONT lf, out IntPtr font);
+ internal static extern int GdipCreateFontFromLogfontW(IntPtr hdc, ref Interop.User32.LOGFONT lf, out IntPtr font);
[DllImport(LibraryName, ExactSpelling = true)]
internal static extern int GdipCreateBitmapFromStream(Interop.Ole32.IStream stream, out IntPtr bitmap);
internal static extern int GdipGetFontUnit(HandleRef font, out GraphicsUnit unit);
[DllImport(LibraryName, ExactSpelling = true)]
- internal static extern int GdipGetLogFontW(HandleRef font, HandleRef graphics, ref LOGFONT lf);
+ internal static extern int GdipGetLogFontW(HandleRef font, HandleRef graphics, ref Interop.User32.LOGFONT lf);
[DllImport(LibraryName, ExactSpelling = true)]
internal static extern int GdipCreatePen1(int argb, float width, int unit, out IntPtr pen);
{
if (s_halftonePalette != IntPtr.Zero)
{
- SafeNativeMethods.IntDeleteObject(new HandleRef(null, s_halftonePalette));
+ Interop.Gdi32.DeleteObject(s_halftonePalette);
s_halftonePalette = IntPtr.Zero;
}
}
new HandleRef(null, info.hbmColor),
sizeof(SafeNativeMethods.BITMAP),
ref bitmap);
- SafeNativeMethods.IntDeleteObject(new HandleRef(null, info.hbmColor));
+ Interop.Gdi32.DeleteObject(info.hbmColor);
_iconSize = new Size((int)bitmap.bmWidth, (int)bitmap.bmHeight);
}
else if (info.hbmMask != IntPtr.Zero)
if (info.hbmMask != IntPtr.Zero)
{
- SafeNativeMethods.IntDeleteObject(new HandleRef(null, info.hbmMask));
+ Interop.Gdi32.DeleteObject(info.hbmMask);
}
}
// The ROP is SRCCOPY, so we can be simple here and take
// advantage of clipping regions. Drawing the cursor
// is merely a matter of offsetting and clipping.
- IntPtr hSaveRgn = SafeNativeMethods.SaveClipRgn(dc);
+ IntPtr hSaveRgn = SaveClipRgn(dc);
try
{
SafeNativeMethods.IntersectClipRect(new HandleRef(this, dc), targetX, targetY, targetX + clipWidth, targetY + clipHeight);
}
finally
{
- SafeNativeMethods.RestoreClipRgn(dc, hSaveRgn);
+ RestoreClipRgn(dc, hSaveRgn);
}
}
+ private static IntPtr SaveClipRgn(IntPtr hDC)
+ {
+ IntPtr hTempRgn = Interop.Gdi32.CreateRectRgn(0, 0, 0, 0);
+ IntPtr hSaveRgn = IntPtr.Zero;
+
+ int result = Interop.Gdi32.GetClipRgn(hDC, hTempRgn);
+ if (result > 0)
+ {
+ hSaveRgn = hTempRgn;
+ hTempRgn = IntPtr.Zero;
+ }
+
+ return hSaveRgn;
+ }
+
+ private static void RestoreClipRgn(IntPtr hDC, IntPtr hRgn)
+ {
+ Interop.Gdi32.SelectClipRgn(new HandleRef(null, hDC), new HandleRef(null, hRgn));
+ }
+
internal void Draw(Graphics graphics, int x, int y)
{
Size size = Size;
if (s_bitDepth == 0)
{
- IntPtr dc = UnsafeNativeMethods.GetDC(NativeMethods.NullHandleRef);
- s_bitDepth = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, dc), SafeNativeMethods.BITSPIXEL);
- s_bitDepth *= UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, dc), SafeNativeMethods.PLANES);
- UnsafeNativeMethods.ReleaseDC(NativeMethods.NullHandleRef, new HandleRef(null, dc));
+ IntPtr dc = Interop.User32.GetDC(IntPtr.Zero);
+ s_bitDepth = Interop.Gdi32.GetDeviceCaps(dc, Interop.Gdi32.DeviceCapability.BITSPIXEL);
+ s_bitDepth *= Interop.Gdi32.GetDeviceCaps(dc, Interop.Gdi32.DeviceCapability.PLANES);
+ Interop.User32.ReleaseDC(IntPtr.Zero, dc);
// If the bitdepth is 8, make it 4 because windows does not
// choose a 256 color icon if the display is running in 256 color mode
{
if (info.hbmColor != IntPtr.Zero)
{
- SafeNativeMethods.IntDeleteObject(new HandleRef(null, info.hbmColor));
+ Interop.Gdi32.DeleteObject(info.hbmColor);
}
if (info.hbmMask != IntPtr.Zero)
{
- SafeNativeMethods.IntDeleteObject(new HandleRef(null, info.hbmMask));
+ Interop.Gdi32.DeleteObject(info.hbmMask);
}
}
}
public const int MAX_PATH = 260;
internal const int SM_REMOTESESSION = 0x1000;
- internal const int OBJ_DC = 3,
- OBJ_METADC = 4,
- OBJ_MEMDC = 10,
- OBJ_ENHMETADC = 12,
- DIB_RGB_COLORS = 0,
- BI_BITFIELDS = 3,
- BI_RGB = 0,
- BITMAPINFO_MAX_COLORSIZE = 256,
- DEFAULT_GUI_FONT = 17;
-
- internal const uint SPI_GETICONTITLELOGFONT = 0x001F;
-
- // Gets metrics associated with the nonclient area of nonminimized windows
- internal const uint SPI_GETNONCLIENTMETRICS = 41;
+ internal const int DIB_RGB_COLORS = 0;
+ internal const int BI_BITFIELDS = 3;
+ internal const int BI_RGB = 0;
+ internal const int BITMAPINFO_MAX_COLORSIZE = 256;
[StructLayout(LayoutKind.Sequential)]
internal struct BITMAPINFO_FLAT
public byte rgbRed;
public byte rgbReserved;
}
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal struct NONCLIENTMETRICS
- {
- public uint cbSize;
- public int iBorderWidth;
- public int iScrollWidth;
- public int iScrollHeight;
- public int iCaptionWidth;
- public int iCaptionHeight;
- public SafeNativeMethods.LOGFONT lfCaptionFont;
- public int iSmCaptionWidth;
- public int iSmCaptionHeight;
- public SafeNativeMethods.LOGFONT lfSmCaptionFont;
- public int iMenuWidth;
- public int iMenuHeight;
- public SafeNativeMethods.LOGFONT lfMenuFont;
- public SafeNativeMethods.LOGFONT lfStatusFont;
- public SafeNativeMethods.LOGFONT lfMessageFont;
-
- // This is supported on Windows vista and later
- public int iPaddedBorderWidth;
- }
}
}
namespace System.Drawing
{
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal struct LOGFONT
- {
- internal int lfHeight;
- internal uint lfWidth;
- internal uint lfEscapement;
- internal uint lfOrientation;
- internal uint lfWeight;
- internal byte lfItalic;
- internal byte lfUnderline;
- internal byte lfStrikeOut;
- internal byte lfCharSet;
- internal byte lfOutPrecision;
- internal byte lfClipPrecision;
- internal byte lfQuality;
- internal byte lfPitchAndFamily;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
- internal string lfFaceName;
- }
-
[StructLayout(LayoutKind.Sequential)]
internal struct GdipImageCodecInfo
{
Interop.Kernel32.GlobalUnlock(new HandleRef(this, _modeHandle));
}
- // int horizontalResolution = Windows.GetDeviceCaps(dc.Hdc, SafeNativeMethods.HORZRES);
- // int verticalResolution = Windows.GetDeviceCaps(dc.Hdc, SafeNativeMethods.VERTRES);
-
_graphics = Graphics.FromHdcInternal(_dc.Hdc);
if (_graphics != null && document.OriginAtMargins)
// Adjust the origin of the graphics object to be at the
// user-specified margin location
//
- int dpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), SafeNativeMethods.LOGPIXELSX);
- int dpiY = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), SafeNativeMethods.LOGPIXELSY);
- int hardMarginX_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), SafeNativeMethods.PHYSICALOFFSETX);
- int hardMarginY_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), SafeNativeMethods.PHYSICALOFFSETY);
+ int dpiX = Interop.Gdi32.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), Interop.Gdi32.DeviceCapability.LOGPIXELSX);
+ int dpiY = Interop.Gdi32.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), Interop.Gdi32.DeviceCapability.LOGPIXELSY);
+ int hardMarginX_DU = Interop.Gdi32.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), Interop.Gdi32.DeviceCapability.PHYSICALOFFSETX);
+ int hardMarginY_DU = Interop.Gdi32.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), Interop.Gdi32.DeviceCapability.PHYSICALOFFSETY);
float hardMarginX = hardMarginX_DU * 100 / dpiX;
float hardMarginY = hardMarginY_DU * 100 / dpiY;
try
{
- int dpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.LOGPIXELSX);
- int hardMarginX_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.PHYSICALOFFSETX);
+ int dpiX = Interop.Gdi32.GetDeviceCaps(new HandleRef(dc, dc.Hdc), Interop.Gdi32.DeviceCapability.LOGPIXELSX);
+ int hardMarginX_DU = Interop.Gdi32.GetDeviceCaps(new HandleRef(dc, dc.Hdc), Interop.Gdi32.DeviceCapability.PHYSICALOFFSETX);
hardMarginX = hardMarginX_DU * 100 / dpiX;
}
finally
try
{
- int dpiY = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.LOGPIXELSY);
- int hardMarginY_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.PHYSICALOFFSETY);
+ int dpiY = Interop.Gdi32.GetDeviceCaps(new HandleRef(dc, dc.Hdc), Interop.Gdi32.DeviceCapability.LOGPIXELSY);
+ int hardMarginY_DU = Interop.Gdi32.GetDeviceCaps(new HandleRef(dc, dc.Hdc), Interop.Gdi32.DeviceCapability.PHYSICALOFFSETY);
hardMarginY = hardMarginY_DU * 100 / dpiY;
}
finally
try
{
- int dpiX = UnsafeNativeMethods.GetDeviceCaps(hdc, SafeNativeMethods.LOGPIXELSX);
- int dpiY = UnsafeNativeMethods.GetDeviceCaps(hdc, SafeNativeMethods.LOGPIXELSY);
+ int dpiX = Interop.Gdi32.GetDeviceCaps(hdc, Interop.Gdi32.DeviceCapability.LOGPIXELSX);
+ int dpiY = Interop.Gdi32.GetDeviceCaps(hdc, Interop.Gdi32.DeviceCapability.LOGPIXELSY);
if (!Landscape)
{
//
// Need to convert the printable area to 100th of an inch from the device units
- printableArea.X = (float)UnsafeNativeMethods.GetDeviceCaps(hdc, SafeNativeMethods.PHYSICALOFFSETX) * 100 / dpiX;
- printableArea.Y = (float)UnsafeNativeMethods.GetDeviceCaps(hdc, SafeNativeMethods.PHYSICALOFFSETY) * 100 / dpiY;
- printableArea.Width = (float)UnsafeNativeMethods.GetDeviceCaps(hdc, SafeNativeMethods.HORZRES) * 100 / dpiX;
- printableArea.Height = (float)UnsafeNativeMethods.GetDeviceCaps(hdc, SafeNativeMethods.VERTRES) * 100 / dpiY;
+ printableArea.X = (float)Interop.Gdi32.GetDeviceCaps(hdc, Interop.Gdi32.DeviceCapability.PHYSICALOFFSETX) * 100 / dpiX;
+ printableArea.Y = (float)Interop.Gdi32.GetDeviceCaps(hdc, Interop.Gdi32.DeviceCapability.PHYSICALOFFSETY) * 100 / dpiY;
+ printableArea.Width = (float)Interop.Gdi32.GetDeviceCaps(hdc, Interop.Gdi32.DeviceCapability.HORZRES) * 100 / dpiX;
+ printableArea.Height = (float)Interop.Gdi32.GetDeviceCaps(hdc, Interop.Gdi32.DeviceCapability.VERTRES) * 100 / dpiY;
}
else
{
//
// Need to convert the printable area to 100th of an inch from the device units
- printableArea.Y = (float)UnsafeNativeMethods.GetDeviceCaps(hdc, SafeNativeMethods.PHYSICALOFFSETX) * 100 / dpiX;
- printableArea.X = (float)UnsafeNativeMethods.GetDeviceCaps(hdc, SafeNativeMethods.PHYSICALOFFSETY) * 100 / dpiY;
- printableArea.Height = (float)UnsafeNativeMethods.GetDeviceCaps(hdc, SafeNativeMethods.HORZRES) * 100 / dpiX;
- printableArea.Width = (float)UnsafeNativeMethods.GetDeviceCaps(hdc, SafeNativeMethods.VERTRES) * 100 / dpiY;
+ printableArea.Y = (float)Interop.Gdi32.GetDeviceCaps(hdc, Interop.Gdi32.DeviceCapability.PHYSICALOFFSETX) * 100 / dpiX;
+ printableArea.X = (float)Interop.Gdi32.GetDeviceCaps(hdc, Interop.Gdi32.DeviceCapability.PHYSICALOFFSETY) * 100 / dpiY;
+ printableArea.Height = (float)Interop.Gdi32.GetDeviceCaps(hdc, Interop.Gdi32.DeviceCapability.HORZRES) * 100 / dpiX;
+ printableArea.Width = (float)Interop.Gdi32.GetDeviceCaps(hdc, Interop.Gdi32.DeviceCapability.VERTRES) * 100 / dpiY;
}
}
finally
{
// Adjust the origin of the graphics object to be at the
// user-specified margin location
- int dpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), SafeNativeMethods.LOGPIXELSX);
- int dpiY = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), SafeNativeMethods.LOGPIXELSY);
- int hardMarginX_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), SafeNativeMethods.PHYSICALOFFSETX);
- int hardMarginY_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), SafeNativeMethods.PHYSICALOFFSETY);
+ int dpiX = Interop.Gdi32.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), Interop.Gdi32.DeviceCapability.LOGPIXELSX);
+ int dpiY = Interop.Gdi32.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), Interop.Gdi32.DeviceCapability.LOGPIXELSY);
+ int hardMarginX_DU = Interop.Gdi32.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), Interop.Gdi32.DeviceCapability.PHYSICALOFFSETX);
+ int hardMarginY_DU = Interop.Gdi32.GetDeviceCaps(new HandleRef(_dc, _dc.Hdc), Interop.Gdi32.DeviceCapability.PHYSICALOFFSETY);
float hardMarginX = hardMarginX_DU * 100 / dpiX;
float hardMarginY = hardMarginY_DU * 100 / dpiY;
{
// Adjust the origin of the graphics object to be at the user-specified margin location
// Note: Graphics.FromHdc internally calls SaveDC(hdc), we can still use the saved hdc to get the resolution.
- int dpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.LOGPIXELSX);
- int dpiY = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.LOGPIXELSY);
- int hardMarginX_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.PHYSICALOFFSETX);
- int hardMarginY_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.PHYSICALOFFSETY);
+ int dpiX = Interop.Gdi32.GetDeviceCaps(new HandleRef(dc, dc.Hdc), Interop.Gdi32.DeviceCapability.LOGPIXELSX);
+ int dpiY = Interop.Gdi32.GetDeviceCaps(new HandleRef(dc, dc.Hdc), Interop.Gdi32.DeviceCapability.LOGPIXELSY);
+ int hardMarginX_DU = Interop.Gdi32.GetDeviceCaps(new HandleRef(dc, dc.Hdc), Interop.Gdi32.DeviceCapability.PHYSICALOFFSETX);
+ int hardMarginY_DU = Interop.Gdi32.GetDeviceCaps(new HandleRef(dc, dc.Hdc), Interop.Gdi32.DeviceCapability.PHYSICALOFFSETY);
float hardMarginX = hardMarginX_DU * 100 / dpiX;
float hardMarginY = hardMarginY_DU * 100 / dpiY;
{
get
{
- return GetDeviceCaps(SafeNativeMethods.TECHNOLOGY, SafeNativeMethods.DT_RASPRINTER) == SafeNativeMethods.DT_PLOTTER;
+ return GetDeviceCaps(Interop.Gdi32.DeviceCapability.TECHNOLOGY, Interop.Gdi32.DeviceTechnology.DT_RASPRINTER) == Interop.Gdi32.DeviceTechnology.DT_PLOTTER;
}
}
{
get
{
- return GetDeviceCaps(SafeNativeMethods.BITSPIXEL, 1) > 1;
+ return GetDeviceCaps(Interop.Gdi32.DeviceCapability.BITSPIXEL, 1) > 1;
}
}
internal DeviceContext CreateDeviceContext(IntPtr hdevmode)
{
IntPtr modePointer = Interop.Kernel32.GlobalLock(hdevmode);
- DeviceContext dc = DeviceContext.CreateDC(DriverName, PrinterNameInternal, (string)null, new HandleRef(null, modePointer));
+ DeviceContext dc = DeviceContext.CreateDC(DriverName, PrinterNameInternal, (string)null, modePointer);
Interop.Kernel32.GlobalUnlock(hdevmode);
return dc;
}
internal DeviceContext CreateInformationContext(IntPtr hdevmode)
{
IntPtr modePointer = Interop.Kernel32.GlobalLock(hdevmode);
- DeviceContext dc = DeviceContext.CreateIC(DriverName, PrinterNameInternal, (string)null, new HandleRef(null, modePointer));
+ DeviceContext dc = DeviceContext.CreateIC(DriverName, PrinterNameInternal, (string)null, modePointer);
Interop.Kernel32.GlobalUnlock(hdevmode);
return dc;
}
}
}
- private int GetDeviceCaps(int capability, int defaultValue)
+ private int GetDeviceCaps(Interop.Gdi32.DeviceCapability capability, int defaultValue)
{
- DeviceContext dc = CreateInformationContext(DefaultPageSettings);
- int result = defaultValue;
-
- try
+ using (DeviceContext dc = CreateInformationContext(DefaultPageSettings))
{
- result = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), capability);
+ return Interop.Gdi32.GetDeviceCaps(new HandleRef(dc, dc.Hdc), capability);
}
- catch (InvalidPrinterException)
- {
- // do nothing, will return defaultValue.
- }
- finally
- {
- dc.Dispose();
- }
-
- return result;
}
/// <summary>
throw new ArgumentNullException(nameof(regionHandle));
}
- // On Windows HRGN are (old) GDI objects. Deskop .NET does not check the return code of IntDeleteObject
- SafeNativeMethods.IntDeleteObject(new HandleRef(this, regionHandle));
+ Interop.Gdi32.DeleteObject(new HandleRef(this, regionHandle));
}
}
}
{
private IntPtr _handle;
- public static ScreenDC Create()
+ public static ScreenDC Create() => new ScreenDC
{
- return new ScreenDC
- {
- _handle = UnsafeNativeMethods.GetDC(NativeMethods.NullHandleRef)
- };
- }
+ _handle = Interop.User32.GetDC(IntPtr.Zero)
+ };
public static implicit operator IntPtr(ScreenDC screenDC) => screenDC._handle;
- public void Dispose()
- {
- UnsafeNativeMethods.ReleaseDC(NativeMethods.NullHandleRef, new HandleRef(null, _handle));
- }
+ public void Dispose() => Interop.User32.ReleaseDC(IntPtr.Zero, _handle);
}
}
{
public static partial class SystemFonts
{
- private static unsafe bool GetNonClientMetrics(out NativeMethods.NONCLIENTMETRICS metrics)
+ private static unsafe bool GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics)
{
- metrics = new NativeMethods.NONCLIENTMETRICS { cbSize = (uint)sizeof(NativeMethods.NONCLIENTMETRICS) };
+ metrics = new Interop.User32.NONCLIENTMETRICS { cbSize = (uint)sizeof(Interop.User32.NONCLIENTMETRICS) };
fixed (void* m = &metrics)
{
- return UnsafeNativeMethods.SystemParametersInfo(NativeMethods.SPI_GETNONCLIENTMETRICS, metrics.cbSize, m, 0);
+ return Interop.User32.SystemParametersInfoW(Interop.User32.SystemParametersAction.SPI_GETNONCLIENTMETRICS, metrics.cbSize, m, 0);
}
}
{
Font captionFont = null;
- if (GetNonClientMetrics(out NativeMethods.NONCLIENTMETRICS metrics))
+ if (GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics))
{
captionFont = GetFontFromData(metrics.lfCaptionFont);
captionFont.SetSystemFontName(nameof(CaptionFont));
{
Font smcaptionFont = null;
- if (GetNonClientMetrics(out NativeMethods.NONCLIENTMETRICS metrics))
+ if (GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics))
{
smcaptionFont = GetFontFromData(metrics.lfSmCaptionFont);
smcaptionFont.SetSystemFontName(nameof(SmallCaptionFont));
{
Font menuFont = null;
- if (GetNonClientMetrics(out NativeMethods.NONCLIENTMETRICS metrics))
+ if (GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics))
{
menuFont = GetFontFromData(metrics.lfMenuFont);
menuFont.SetSystemFontName(nameof(MenuFont));
{
Font statusFont = null;
- if (GetNonClientMetrics(out NativeMethods.NONCLIENTMETRICS metrics))
+ if (GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics))
{
statusFont = GetFontFromData(metrics.lfStatusFont);
statusFont.SetSystemFontName(nameof(StatusFont));
{
Font messageBoxFont = null;
- if (GetNonClientMetrics(out NativeMethods.NONCLIENTMETRICS metrics))
+ if (GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics))
{
messageBoxFont = GetFontFromData(metrics.lfMessageFont);
messageBoxFont.SetSystemFontName(nameof(MessageBoxFont));
{
Font iconTitleFont = null;
- var itfont = new SafeNativeMethods.LOGFONT();
- if (UnsafeNativeMethods.SystemParametersInfo(NativeMethods.SPI_GETICONTITLELOGFONT, (uint)sizeof(SafeNativeMethods.LOGFONT), &itfont, 0))
+ var itfont = new Interop.User32.LOGFONT();
+ if (Interop.User32.SystemParametersInfoW(Interop.User32.SystemParametersAction.SPI_GETICONTITLELOGFONT, (uint)sizeof(Interop.User32.LOGFONT), &itfont, 0))
{
iconTitleFont = GetFontFromData(itfont);
iconTitleFont.SetSystemFontName(nameof(IconTitleFont));
// First try DEFAULT_GUI.
if (defaultFont == null)
{
- IntPtr handle = UnsafeNativeMethods.GetStockObject(NativeMethods.DEFAULT_GUI_FONT);
+ IntPtr handle = Interop.Gdi32.GetStockObject(Interop.Gdi32.StockObject.DEFAULT_GUI_FONT);
try
{
using (Font fontInWorldUnits = Font.FromHfont(handle))
return new Font(font.FontFamily, font.SizeInPoints, font.Style, GraphicsUnit.Point, font.GdiCharSet, font.GdiVerticalFont);
}
- private static Font GetFontFromData(SafeNativeMethods.LOGFONT logFont)
+ private static Font GetFontFromData(Interop.User32.LOGFONT logFont)
{
Font font = null;
try
[DllImport(ExternDll.Kernel32, SetLastError = true, ExactSpelling = true, EntryPoint = "RtlMoveMemory")]
public static extern void CopyMemory(HandleRef destData, HandleRef srcData, int size);
- [DllImport(ExternDll.User32, SetLastError = true, ExactSpelling = true)]
- public static extern IntPtr GetDC(HandleRef hWnd);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)]
- public static extern bool DeleteDC(HandleRef hDC);
-
- [DllImport(ExternDll.User32, SetLastError = true, ExactSpelling = true)]
- public static extern int ReleaseDC(HandleRef hWnd, HandleRef hDC);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)]
- public static extern IntPtr CreateCompatibleDC(HandleRef hDC);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)]
- public static extern IntPtr GetStockObject(int nIndex);
-
[DllImport(ExternDll.Kernel32, SetLastError = true)]
public static extern int GetSystemDefaultLCID();
[DllImport(ExternDll.User32, SetLastError = true, ExactSpelling = true)]
public static extern int GetSystemMetrics(int nIndex);
-
- [DllImport(ExternDll.User32, SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern unsafe bool SystemParametersInfo(uint uiAction, uint uiParam, void* pvParam, uint fWinIni);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- public static extern int GetDeviceCaps(HandleRef hDC, int nIndex);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- public static extern int GetObjectType(HandleRef hObject);
}
}
return;
}
- IntPtr hDC = UnsafeNativeMethods.GetDC(NativeMethods.NullHandleRef);
+ IntPtr hDC = Interop.User32.GetDC(IntPtr.Zero);
if (hDC != IntPtr.Zero)
{
- s_deviceDpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), SafeNativeMethods.LOGPIXELSX);
- s_deviceDpiY = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), SafeNativeMethods.LOGPIXELSY);
+ s_deviceDpiX = Interop.Gdi32.GetDeviceCaps(hDC, Interop.Gdi32.DeviceCapability.LOGPIXELSX);
+ s_deviceDpiY = Interop.Gdi32.GetDeviceCaps(hDC, Interop.Gdi32.DeviceCapability.LOGPIXELSY);
- UnsafeNativeMethods.ReleaseDC(NativeMethods.NullHandleRef, new HandleRef(null, hDC));
+ Interop.User32.ReleaseDC(IntPtr.Zero, hDC);
}
s_isInitialized = true;
private void CacheInitialState()
{
Debug.Assert(_hDC != IntPtr.Zero, "Cannot get initial state without a valid HDC");
- _hCurrentPen = _hInitialPen = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, _hDC), IntNativeMethods.OBJ_PEN);
- _hCurrentBrush = _hInitialBrush = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, _hDC), IntNativeMethods.OBJ_BRUSH);
- _hCurrentBmp = _hInitialBmp = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, _hDC), IntNativeMethods.OBJ_BITMAP);
- _hCurrentFont = _hInitialFont = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, _hDC), IntNativeMethods.OBJ_FONT);
+ _hCurrentPen = _hInitialPen = Interop.Gdi32.GetCurrentObject(new HandleRef(this, _hDC), Interop.Gdi32.ObjectType.OBJ_PEN);
+ _hCurrentBrush = _hInitialBrush = Interop.Gdi32.GetCurrentObject(new HandleRef(this, _hDC), Interop.Gdi32.ObjectType.OBJ_BRUSH);
+ _hCurrentBmp = _hInitialBmp = Interop.Gdi32.GetCurrentObject(new HandleRef(this, _hDC), Interop.Gdi32.ObjectType.OBJ_BITMAP);
+ _hCurrentFont = _hInitialFont = Interop.Gdi32.GetCurrentObject(new HandleRef(this, _hDC), Interop.Gdi32.ObjectType.OBJ_FONT);
}
if (dcType == DeviceContextType.Display)
{
- _hWnd = IntUnsafeNativeMethods.WindowFromDC(new HandleRef(this, _hDC));
+ _hWnd = Interop.User32.WindowFromDC(new HandleRef(this, _hDC));
}
#if TRACK_HDC
- Debug.WriteLine( DbgUtil.StackTraceToStr( string.Format("DeviceContext( hDC=0x{0:X8}, Type={1} )", unchecked((int) hDC), dcType) ));
+ Debug.WriteLine(DbgUtil.StackTraceToStr($"DeviceContext(hDC=0x{(int)hDC:X8}, Type={dcType})"));
#endif
}
-
-
/// <summary>
/// CreateDC creates a DeviceContext object wrapping an hdc created with the Win32 CreateDC function.
/// </summary>
- public static DeviceContext CreateDC(string driverName, string deviceName, string fileName, HandleRef devMode)
+ public static DeviceContext CreateDC(string driverName, string deviceName, string fileName, IntPtr devMode)
{
// Note: All input params can be null but not at the same time. See MSDN for information.
-
- IntPtr hdc = IntUnsafeNativeMethods.CreateDC(driverName, deviceName, fileName, devMode);
+ IntPtr hdc = Interop.Gdi32.CreateDCW(driverName, deviceName, fileName, devMode);
return new DeviceContext(hdc, DeviceContextType.NamedDevice);
}
/// <summary>
/// CreateIC creates a DeviceContext object wrapping an hdc created with the Win32 CreateIC function.
/// </summary>
- public static DeviceContext CreateIC(string driverName, string deviceName, string fileName, HandleRef devMode)
+ public static DeviceContext CreateIC(string driverName, string deviceName, string fileName, IntPtr devMode)
{
// Note: All input params can be null but not at the same time. See MSDN for information.
- IntPtr hdc = IntUnsafeNativeMethods.CreateIC(driverName, deviceName, fileName, devMode);
+ IntPtr hdc = Interop.Gdi32.CreateICW(driverName, deviceName, fileName, devMode);
return new DeviceContext(hdc, DeviceContextType.Information);
}
// Win2K+: (See CreateCompatibleDC in the MSDN).
// In this case the thread that calls CreateCompatibleDC owns the HDC that is created. When this thread is destroyed,
// the HDC is no longer valid.
-
- IntPtr compatibleDc = IntUnsafeNativeMethods.CreateCompatibleDC(new HandleRef(null, hdc));
+ IntPtr compatibleDc = Interop.Gdi32.CreateCompatibleDC(hdc);
return new DeviceContext(compatibleDc, DeviceContextType.Memory);
}
break;
case DeviceContextType.Information:
case DeviceContextType.NamedDevice:
- IntUnsafeNativeMethods.DeleteDC(new HandleRef(this, _hDC));
+ Interop.Gdi32.DeleteDC(new HandleRef(this, _hDC));
_hDC = IntPtr.Zero;
break;
case DeviceContextType.Memory:
- IntUnsafeNativeMethods.DeleteDC(new HandleRef(this, _hDC));
+ Interop.Gdi32.DeleteDC(new HandleRef(this, _hDC));
_hDC = IntPtr.Zero;
break;
// case DeviceContextType.Metafile: - not yet supported.
// Note: for common DCs, GetDC assigns default attributes to the DC each time it is retrieved.
// For example, the default font is System.
- _hDC = UnsafeNativeMethods.GetDC(new HandleRef(this, _hWnd));
+ _hDC = Interop.User32.GetDC(new HandleRef(this, _hWnd));
#if TRACK_HDC
Debug.WriteLine( DbgUtil.StackTraceToStr( string.Format("hdc[0x{0:x8}]=DC.GetHdc(hWnd=0x{1:x8})", unchecked((int) _hDC), unchecked((int) _hWnd))));
#endif
#if TRACK_HDC
int retVal =
#endif
- UnsafeNativeMethods.ReleaseDC(new HandleRef(this, _hWnd), new HandleRef(this, _hDC));
+ Interop.User32.ReleaseDC(new HandleRef(this, _hWnd), new HandleRef(this, _hDC));
// Note: retVal == 0 means it was not released but doesn't necessarily means an error; class or private DCs are never released.
#if TRACK_HDC
Debug.WriteLine( DbgUtil.StackTraceToStr( string.Format("[ret={0}]=DC.ReleaseDC(hDc=0x{1:x8}, hWnd=0x{2:x8})", retVal, unchecked((int) _hDC), unchecked((int) _hWnd))));
bool result =
#endif
// Note: Don't use the Hdc property here, it would force handle creation.
- IntUnsafeNativeMethods.RestoreDC(new HandleRef(this, _hDC), -1);
+ Interop.Gdi32.RestoreDC(new HandleRef(this, _hDC), -1);
#if TRACK_HDC
// Note: Winforms may call this method during app exit at which point the DC may have been finalized already causing this assert to popup.
Debug.WriteLine( DbgUtil.StackTraceToStr( string.Format("ret[0]=DC.RestoreHdc(hDc=0x{1:x8}, state={2})", result, unchecked((int) _hDC), restoreState) ));
public int SaveHdc()
{
HandleRef hdc = new HandleRef(this, _hDC);
- int state = IntUnsafeNativeMethods.SaveDC(hdc);
+ int state = Interop.Gdi32.SaveDC(hdc);
if (_contextStack == null)
{
HandleRef hdc = new HandleRef(this, _hDC);
HandleRef hRegion = new HandleRef(region, region.HRegion);
- IntUnsafeNativeMethods.SelectClipRgn(hdc, hRegion);
+ Interop.Gdi32.SelectClipRgn(hdc, hRegion);
}
///<summary>
WindowsRegion clip = new WindowsRegion(0, 0, 0, 0);
try
{
- int result = IntUnsafeNativeMethods.GetClipRgn(new HandleRef(this, _hDC), new HandleRef(clip, clip.HRegion));
+ int result = Interop.Gdi32.GetClipRgn(new HandleRef(this, _hDC), new HandleRef(clip, clip.HRegion));
// If the function succeeds and there is a clipping region for the given device context, the return value is 1.
if (result == 1)
{
Debug.Assert(clip.HRegion != IntPtr.Zero);
- wr.CombineRegion(clip, wr, RegionCombineMode.AND); //1 = AND (or Intersect)
+ wr.CombineRegion(clip, wr, Interop.Gdi32.CombineMode.RGN_AND);
}
SetClip(wr);
/// </summary>
public void TranslateTransform(int dx, int dy)
{
- IntNativeMethods.POINT orgn = new IntNativeMethods.POINT();
- IntUnsafeNativeMethods.OffsetViewportOrgEx(new HandleRef(this, _hDC), dx, dy, orgn);
+ var origin = new Point();
+ Interop.Gdi32.OffsetViewportOrgEx(new HandleRef(this, _hDC), dx, dy, ref origin);
}
/// <summary>
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.InteropServices;
-
-namespace System.Drawing.Internal
-{
- internal partial class IntNativeMethods
- {
- public const int OBJ_PEN = 1;
- public const int OBJ_BRUSH = 2;
- public const int OBJ_FONT = 6;
- public const int OBJ_BITMAP = 7;
-
- public enum RegionFlags
- {
- ERROR = 0,
- NULLREGION = 1,
- SIMPLEREGION = 2,
- COMPLEXREGION = 3,
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public struct RECT
- {
- public int left;
- public int top;
- public int right;
- public int bottom;
-
- public Size Size => new Size(right - left, bottom - top);
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public class POINT
- {
- public int x;
- public int y;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
- public class LOGFONT
- {
- public int lfHeight;
- public int lfWidth;
- public int lfEscapement;
- public int lfOrientation;
- public int lfWeight;
- public byte lfItalic;
- public byte lfUnderline;
- public byte lfStrikeOut;
- public byte lfCharSet;
- public byte lfOutPrecision;
- public byte lfClipPrecision;
- public byte lfQuality;
- public byte lfPitchAndFamily;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
- public string lfFaceName;
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Runtime.InteropServices;
-
-namespace System.Drawing.Internal
-{
- /// <summary>
- /// 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.
- /// </summary>
- internal static partial class IntSafeNativeMethods
- {
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)]
- public static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Drawing.Internal
-{
- internal static partial class IntUnsafeNativeMethods
- {
- /// <summary>
- /// NOTE: DeleteDC is to be used to delete the hdc created from CreateCompatibleDC ONLY. All other hdcs should
- /// be deleted with DeleteHDC.
- /// </summary>
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)]
- public static extern bool DeleteDC(HandleRef hDC);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern IntPtr CreateDC(string lpszDriverName, string lpszDeviceName, string lpszOutput, HandleRef /*DEVMODE*/ lpInitData);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern IntPtr CreateIC(string lpszDriverName, string lpszDeviceName, string lpszOutput, HandleRef /*DEVMODE*/ lpInitData);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)]
- public static extern IntPtr CreateCompatibleDC(HandleRef hDC);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)]
- public static extern int SaveDC(HandleRef hDC);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)]
- public static extern bool RestoreDC(HandleRef hDC, int nSavedDC);
-
- [DllImport(ExternDll.User32, SetLastError = true, ExactSpelling = true)]
- public static extern IntPtr WindowFromDC(HandleRef hDC);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, EntryPoint = "OffsetViewportOrgEx", CharSet = CharSet.Auto)]
- public static extern bool IntOffsetViewportOrgEx(HandleRef hDC, int nXOffset, int nYOffset, [In, Out] IntNativeMethods.POINT point);
-
- public static bool OffsetViewportOrgEx(HandleRef hDC, int nXOffset, int nYOffset, [In, Out] IntNativeMethods.POINT point)
- {
- bool retVal = IntOffsetViewportOrgEx(hDC, nXOffset, nYOffset, point);
- DbgUtil.AssertWin32(retVal, "OffsetViewportOrgEx([hdc=0x{0:X8}], dx=[{1}], dy=[{2}], [out pPoint]) failed.", hDC.Handle, nXOffset, nYOffset);
- return retVal;
- }
-
- // Region.
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, EntryPoint = "CombineRgn", CharSet = CharSet.Auto)]
- public static extern IntNativeMethods.RegionFlags IntCombineRgn(HandleRef hRgnDest, HandleRef hRgnSrc1, HandleRef hRgnSrc2, RegionCombineMode combineMode);
-
- public static IntNativeMethods.RegionFlags CombineRgn(HandleRef hRgnDest, HandleRef hRgnSrc1, HandleRef hRgnSrc2, RegionCombineMode combineMode)
- {
- Debug.Assert(hRgnDest.Wrapper != null && hRgnDest.Handle != IntPtr.Zero, "Destination region is invalid");
- Debug.Assert(hRgnSrc1.Wrapper != null && hRgnSrc1.Handle != IntPtr.Zero, "Source region 1 is invalid");
- Debug.Assert(hRgnSrc2.Wrapper != null && hRgnSrc2.Handle != IntPtr.Zero, "Source region 2 is invalid");
-
- if (hRgnDest.Wrapper == null || hRgnSrc1.Wrapper == null || hRgnSrc2.Wrapper == null)
- {
- return IntNativeMethods.RegionFlags.ERROR;
- }
-
- // Note: CombineRgn can return Error when no regions are combined, this is not an error condition.
- return IntCombineRgn(hRgnDest, hRgnSrc1, hRgnSrc2, combineMode);
- }
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, EntryPoint = "GetClipRgn", CharSet = CharSet.Auto)]
- public static extern int IntGetClipRgn(HandleRef hDC, HandleRef hRgn);
-
- public static int GetClipRgn(HandleRef hDC, HandleRef hRgn)
- {
- int retVal = IntGetClipRgn(hDC, hRgn);
- DbgUtil.AssertWin32(retVal != -1, "IntGetClipRgn([hdc=0x{0:X8}], [hRgn]) failed.", hDC.Handle);
- return retVal;
- }
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, EntryPoint = "SelectClipRgn", CharSet = CharSet.Auto)]
- public static extern IntNativeMethods.RegionFlags IntSelectClipRgn(HandleRef hDC, HandleRef hRgn);
-
- public static IntNativeMethods.RegionFlags SelectClipRgn(HandleRef hDC, HandleRef hRgn)
- {
- IntNativeMethods.RegionFlags result = IntSelectClipRgn(hDC, hRgn);
- DbgUtil.AssertWin32(result != IntNativeMethods.RegionFlags.ERROR, "SelectClipRgn([hdc=0x{0:X8}], [hRegion=0x{1:X8}]) failed.", hDC.Handle, hRgn.Handle);
- return result;
- }
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, EntryPoint = "GetRgnBox", CharSet = CharSet.Auto)]
- public static extern IntNativeMethods.RegionFlags IntGetRgnBox(HandleRef hRgn, [In, Out] ref IntNativeMethods.RECT clipRect);
-
- public static IntNativeMethods.RegionFlags GetRgnBox(HandleRef hRgn, [In, Out] ref IntNativeMethods.RECT clipRect)
- {
- IntNativeMethods.RegionFlags result = IntGetRgnBox(hRgn, ref clipRect);
- DbgUtil.AssertWin32(result != IntNativeMethods.RegionFlags.ERROR, "GetRgnBox([hRegion=0x{0:X8}], [out rect]) failed.", hRgn.Handle);
- return result;
- }
-
- // Font.
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern IntPtr CreateFontIndirect(ref SafeNativeMethods.LOGFONT lf);
-
- // Common.
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)]
- public static extern bool DeleteObject(HandleRef hObject);
-
- [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, EntryPoint = "GetCurrentObject", CharSet = CharSet.Auto)]
- public static extern IntPtr IntGetCurrentObject(HandleRef hDC, int uObjectType);
-
- public static IntPtr GetCurrentObject(HandleRef hDC, int uObjectType)
- {
- IntPtr hGdiObj = IntGetCurrentObject(hDC, uObjectType);
- // If the selected object is a region the return value is HGI_ERROR on failure.
- DbgUtil.AssertWin32(hGdiObj != IntPtr.Zero, "GetObject(hdc=[0x{0:X8}], type=[{1}]) failed.", hDC, uObjectType);
- return hGdiObj;
- }
- }
-}
/// Combines region1 & region2 into this region. The regions cannot be null. The three regions need not be
/// distinct. For example, the sourceRgn1 can equal this region.
/// </summary>
- public IntNativeMethods.RegionFlags CombineRegion(WindowsRegion region1, WindowsRegion region2, RegionCombineMode mode)
+ public Interop.RegionType CombineRegion(WindowsRegion region1, WindowsRegion region2, Interop.Gdi32.CombineMode mode)
{
- return IntUnsafeNativeMethods.CombineRgn(new HandleRef(this, HRegion), new HandleRef(region1, region1.HRegion), new HandleRef(region2, region2.HRegion), mode);
+ return Interop.Gdi32.CombineRgn(new HandleRef(this, HRegion), new HandleRef(region1, region1.HRegion), new HandleRef(region2, region2.HRegion), mode);
}
private void CreateRegion(Rectangle rect)
{
Debug.Assert(_nativeHandle == IntPtr.Zero, "nativeHandle should be null, we're leaking handle");
- _nativeHandle = IntSafeNativeMethods.CreateRectRgn(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height);
+ _nativeHandle = Interop.Gdi32.CreateRectRgn(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height);
_ownHandle = true;
}
if (_ownHandle)
{
- IntUnsafeNativeMethods.DeleteObject(new HandleRef(this, _nativeHandle));
+ Interop.Gdi32.DeleteObject(new HandleRef(this, _nativeHandle));
}
_nativeHandle = IntPtr.Zero;
return new Rectangle(-int.MaxValue, -int.MaxValue, int.MaxValue, int.MaxValue);
}
- var rect = new IntNativeMethods.RECT();
- IntUnsafeNativeMethods.GetRgnBox(new HandleRef(this, _nativeHandle), ref rect);
+ var rect = new Interop.Gdi32.RECT();
+ Interop.Gdi32.GetRgnBox(new HandleRef(this, _nativeHandle), ref rect);
return new Rectangle(new Point(rect.left, rect.top), rect.Size);
}
}