diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerUtils.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerUtils.cs index 8bfc91b5a2f..da7f7bf9a92 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerUtils.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerUtils.cs @@ -12,7 +12,9 @@ using System.Drawing.Imaging; using System.Globalization; using System.Windows.Forms.Design.Behavior; +using Windows.Win32; using static Interop; +using Gdi = Windows.Win32.Graphics.Gdi; namespace System.Windows.Forms.Design { @@ -418,7 +420,7 @@ public static void GenerateSnapShotWithBitBlt(Control control, ref Image image) using var destDC = new DeviceContextHdcScope(gDest, applyGraphicsState: false); // Perform our bitblit operation to push the image into the dest bitmap - Gdi32.BitBlt( + PInvoke.BitBlt( destDC, 0, 0, @@ -427,7 +429,7 @@ public static void GenerateSnapShotWithBitBlt(Control control, ref Image image) controlDC, 0, 0, - Gdi32.ROP.SRCCOPY); + Gdi.ROP_CODE.SRCCOPY); } /// diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.BeginPath.cs b/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.BeginPath.cs deleted file mode 100644 index c4668711ca6..00000000000 --- a/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.BeginPath.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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; - -internal static partial class Interop -{ - internal static partial class Gdi32 - { - [LibraryImport(Libraries.Gdi32)] - public static partial BOOL BeginPath(HDC hdc); - } -} diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.CreateDcScope.cs b/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.CreateDcScope.cs index 5a5c00a9a7d..73e78edaa2c 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.CreateDcScope.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.CreateDcScope.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Gdi = Windows.Win32.Graphics.Gdi; + internal static partial class Interop { internal static partial class Gdi32 @@ -45,9 +47,10 @@ public CreateDcScope( : CreateDC(lpszDriverName, lpszDeviceName, lpszOutput, lpInitData); } - public static implicit operator HDC(in CreateDcScope dcScope) => dcScope.HDC; - public static implicit operator HGDIOBJ(in CreateDcScope dcScope) => dcScope.HDC; - public static implicit operator nint(in CreateDcScope dcScope) => dcScope.HDC.Handle; + public static implicit operator HDC(in CreateDcScope scope) => scope.HDC; + public static implicit operator HGDIOBJ(in CreateDcScope scope) => scope.HDC; + public static implicit operator nint(in CreateDcScope scope) => scope.HDC.Handle; + public static implicit operator Gdi.HDC(in CreateDcScope scope) => scope.HDC; public bool IsNull => HDC.IsNull; diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.HDC.cs b/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.HDC.cs index 8e21e2a1b5e..3029542ee4e 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.HDC.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.HDC.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Gdi = Windows.Win32.Graphics.Gdi; + internal static partial class Interop { internal static partial class Gdi32 @@ -17,6 +19,8 @@ internal static partial class Gdi32 public static implicit operator nint(HDC hdc) => hdc.Handle; public static explicit operator HDC(nint hdc) => new(hdc); public static implicit operator HGDIOBJ(HDC hdc) => new(hdc.Handle); + public static implicit operator HDC(Gdi.HDC hdc) => new(hdc.Value); + public static implicit operator Gdi.HDC(HDC hdc) => new(hdc.Handle); public static bool operator ==(HDC value1, HDC value2) => value1.Handle == value2.Handle; public static bool operator !=(HDC value1, HDC value2) => value1.Handle != value2.Handle; diff --git a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.GetDcScope.cs b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.GetDcScope.cs index 52656044cc2..3f57bc01a9f 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.GetDcScope.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.GetDcScope.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Gdi = Windows.Win32.Graphics.Gdi; + internal static partial class Interop { internal static partial class User32 @@ -51,8 +53,9 @@ public GetDcScope(IntPtr hwnd, IntPtr hrgnClip, DCX flags) public bool IsNull => HDC.IsNull; - public static implicit operator IntPtr(in GetDcScope dcScope) => dcScope.HDC.Handle; - public static implicit operator Gdi32.HDC(in GetDcScope dcScope) => dcScope.HDC; + public static implicit operator IntPtr(in GetDcScope scope) => scope.HDC.Handle; + public static implicit operator Gdi32.HDC(in GetDcScope scope) => scope.HDC; + public static implicit operator Gdi.HDC(in GetDcScope scope) => scope.HDC; public void Dispose() { diff --git a/src/System.Windows.Forms.Primitives/src/NativeMethods.txt b/src/System.Windows.Forms.Primitives/src/NativeMethods.txt index 5a133efbaa5..e4cbc95c23a 100644 --- a/src/System.Windows.Forms.Primitives/src/NativeMethods.txt +++ b/src/System.Windows.Forms.Primitives/src/NativeMethods.txt @@ -1,10 +1,11 @@ -GetCurrentProcess +BitBlt +DuplicateHandle +GetCurrentProcess +GetCurrentProcessId GetCurrentThread GetCurrentThreadId -DuplicateHandle GlobalAlloc +GlobalFree GlobalLock -GlobalUnlock -GetCurrentProcessId GlobalReAlloc -GlobalFree +GlobalUnlock diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/DeviceContextHdcScope.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/DeviceContextHdcScope.cs index 8c0e76e1ffb..996bb939b99 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/DeviceContextHdcScope.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/DeviceContextHdcScope.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Drawing; using static Interop; +using Gdi = Windows.Win32.Graphics.Gdi; namespace System.Windows.Forms { @@ -211,6 +212,7 @@ public unsafe DeviceContextHdcScope( } public static implicit operator Gdi32.HDC(in DeviceContextHdcScope scope) => scope.HDC; + public static implicit operator Gdi.HDC(in DeviceContextHdcScope scope) => scope.HDC; public static implicit operator nint(in DeviceContextHdcScope scope) => scope.HDC.Handle; [Conditional("DEBUG")] diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.BitBlt.cs b/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.BitBlt.cs similarity index 73% rename from src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.BitBlt.cs rename to src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.BitBlt.cs index 697a5582f2e..b8fdba0330e 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.BitBlt.cs +++ b/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.BitBlt.cs @@ -2,24 +2,13 @@ // 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; +using Windows.Win32.Foundation; +using Windows.Win32.Graphics.Gdi; -internal static partial class Interop +namespace Windows.Win32 { - internal static partial class Gdi32 + internal static partial class PInvoke { - [LibraryImport(Libraries.Gdi32, SetLastError = true)] - public static partial BOOL BitBlt( - HDC hdc, - int x, - int y, - int cx, - int cy, - HDC hdcSrc, - int x1, - int y1, - ROP rop); - public static BOOL BitBlt( IHandle hdc, int x, @@ -29,7 +18,7 @@ public static BOOL BitBlt( HDC hdcSrc, int x1, int y1, - ROP rop) + ROP_CODE rop) { BOOL result = BitBlt( (HDC)hdc.Handle, @@ -54,7 +43,7 @@ public static BOOL BitBlt( IHandle hdcSrc, int x1, int y1, - ROP rop) + ROP_CODE rop) { BOOL result = BitBlt( hdc, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs index f5d17f86803..c3e3813126b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs @@ -16,10 +16,11 @@ using System.Text; using System.Windows.Forms.Automation; using System.Windows.Forms.Layout; -using Windows.Win32; using Microsoft.Win32; +using Windows.Win32; using static Interop; using Encoding = System.Text.Encoding; +using Gdi = Windows.Win32.Graphics.Gdi; using IComDataObject = System.Runtime.InteropServices.ComTypes.IDataObject; namespace System.Windows.Forms @@ -5390,7 +5391,7 @@ public void DrawToBitmap(Bitmap bitmap, Rectangle targetBounds) // Now BLT the result to the destination bitmap. using Graphics destGraphics = Graphics.FromImage(bitmap); using var desthDC = new DeviceContextHdcScope(destGraphics, applyGraphicsState: false); - Gdi32.BitBlt( + PInvoke.BitBlt( desthDC, targetBounds.X, targetBounds.Y, @@ -5399,7 +5400,7 @@ public void DrawToBitmap(Bitmap bitmap, Rectangle targetBounds) hDc, 0, 0, - Gdi32.ROP.SRCCOPY); + Gdi.ROP_CODE.SRCCOPY); } /// diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ControlPaint.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ControlPaint.cs index ca192d72c1b..57a857af3f8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ControlPaint.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ControlPaint.cs @@ -9,7 +9,9 @@ using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Runtime.InteropServices; +using Windows.Win32; using static Interop; +using Gdi = Windows.Win32.Graphics.Gdi; namespace System.Windows.Forms { @@ -332,12 +334,12 @@ public static IntPtr CreateHBitmapColorMask(Bitmap bitmap, IntPtr monochromeMask Gdi32.SetBkColor(targetDC, 0x00ffffff); // white Gdi32.SetTextColor(targetDC, 0x00000000); // black - Gdi32.BitBlt( + PInvoke.BitBlt( targetDC, 0, 0, size.Width, size.Height, sourceDC, 0, 0, - (Gdi32.ROP)0x220326); // RasterOp.SOURCE.Invert().AndWith(RasterOp.TARGET).GetRop()); + (Gdi.ROP_CODE)0x220326); // RasterOp.SOURCE.Invert().AndWith(RasterOp.TARGET).GetRop()); return (IntPtr)colorMask; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.cs index e54b87fdbd9..f2d9f6a849f 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.cs @@ -14,6 +14,7 @@ using Windows.Win32; using static Interop; using static Windows.Win32.System.Memory.GLOBAL_ALLOC_FLAGS; +using Gdi = Windows.Win32.Graphics.Gdi; using IComDataObject = System.Runtime.InteropServices.ComTypes.IDataObject; namespace System.Windows.Forms @@ -136,7 +137,7 @@ private static Gdi32.HBITMAP GetCompatibleBitmap(Bitmap bm) // Select the new bitmap into a compatible DC and render the blt the original bitmap. using var destinationBitmapSelection = new Gdi32.SelectObjectScope(destinationDC, bitmap); - Gdi32.BitBlt( + PInvoke.BitBlt( destinationDC, 0, 0, @@ -145,7 +146,7 @@ private static Gdi32.HBITMAP GetCompatibleBitmap(Bitmap bm) sourceDC, 0, 0, - Gdi32.ROP.SRCCOPY); + Gdi.ROP_CODE.SRCCOPY); return bitmap; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStrip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStrip.cs index 5a78c4eedb3..193fd5cd647 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStrip.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStrip.cs @@ -15,6 +15,8 @@ using System.Text; using System.Windows.Forms.Layout; using Microsoft.Win32; +using Windows.Win32; +using Windows.Win32.Graphics.Gdi; using static Interop; namespace System.Windows.Forms @@ -2908,7 +2910,7 @@ private protected override void PrintToMetaFileRecursive(Gdi32.HDC hDC, IntPtr l (nint)(User32.PRF.CHILDREN | User32.PRF.CLIENT | User32.PRF.ERASEBKGND | User32.PRF.NONCLIENT)); // Now BLT the result to the destination bitmap. - Gdi32.BitBlt( + PInvoke.BitBlt( hDC, bounds.X, bounds.Y, @@ -2917,7 +2919,7 @@ private protected override void PrintToMetaFileRecursive(Gdi32.HDC hDC, IntPtr l imageHdc, 0, 0, - Gdi32.ROP.SRCCOPY); + ROP_CODE.SRCCOPY); } protected override bool ProcessCmdKey(ref Message m, Keys keyData) @@ -3868,7 +3870,7 @@ protected override void OnPaint(PaintEventArgs e) // PERF - consider - we only actually need to copy the clipping rect. // copy the background from the toolstrip onto the offscreen bitmap - Gdi32.BitBlt( + PInvoke.BitBlt( ItemHdcInfo, 0, 0, @@ -3877,7 +3879,7 @@ protected override void OnPaint(PaintEventArgs e) toolStripHDC, item.Bounds.X, item.Bounds.Y, - Gdi32.ROP.SRCCOPY); + ROP_CODE.SRCCOPY); // Paint the item into the offscreen bitmap using (PaintEventArgs itemPaintEventArgs = new PaintEventArgs(itemGraphics, clippingRect)) @@ -3886,7 +3888,7 @@ protected override void OnPaint(PaintEventArgs e) } // copy the item back onto the toolstrip - Gdi32.BitBlt( + PInvoke.BitBlt( toolStripHDC, item.Bounds.X, item.Bounds.Y, @@ -3895,7 +3897,7 @@ protected override void OnPaint(PaintEventArgs e) ItemHdcInfo, 0, 0, - Gdi32.ROP.SRCCOPY); + ROP_CODE.SRCCOPY); GC.KeepAlive(ItemHdcInfo); }