Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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,
Expand All @@ -427,7 +429,7 @@ public static void GenerateSnapShotWithBitBlt(Control control, ref Image image)
controlDC,
0,
0,
Gdi32.ROP.SRCCOPY);
Gdi.ROP_CODE.SRCCOPY);
}

/// <summary>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down
11 changes: 6 additions & 5 deletions src/System.Windows.Forms.Primitives/src/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
GetCurrentProcess
BitBlt
DuplicateHandle
GetCurrentProcess
GetCurrentProcessId
GetCurrentThread
GetCurrentThreadId
DuplicateHandle
GlobalAlloc
GlobalFree
GlobalLock
GlobalUnlock
GetCurrentProcessId
GlobalReAlloc
GlobalFree
GlobalUnlock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.Drawing;
using static Interop;
using Gdi = Windows.Win32.Graphics.Gdi;

namespace System.Windows.Forms
{
Expand Down Expand Up @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -54,7 +43,7 @@ public static BOOL BitBlt(
IHandle hdcSrc,
int x1,
int y1,
ROP rop)
ROP_CODE rop)
{
BOOL result = BitBlt(
hdc,
Expand Down
7 changes: 4 additions & 3 deletions src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -5399,7 +5400,7 @@ public void DrawToBitmap(Bitmap bitmap, Rectangle targetBounds)
hDc,
0,
0,
Gdi32.ROP.SRCCOPY);
Gdi.ROP_CODE.SRCCOPY);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines 10 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Are these sorted? If not, please have these sorted (via the context menu):
image

Ditto below


namespace System.Windows.Forms
{
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -145,7 +146,7 @@ private static Gdi32.HBITMAP GetCompatibleBitmap(Bitmap bm)
sourceDC,
0,
0,
Gdi32.ROP.SRCCOPY);
Gdi.ROP_CODE.SRCCOPY);

return bitmap;
}
Expand Down
14 changes: 8 additions & 6 deletions src/System.Windows.Forms/src/System/Windows/Forms/ToolStrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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))
Expand All @@ -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,
Expand All @@ -3895,7 +3897,7 @@ protected override void OnPaint(PaintEventArgs e)
ItemHdcInfo,
0,
0,
Gdi32.ROP.SRCCOPY);
ROP_CODE.SRCCOPY);

GC.KeepAlive(ItemHdcInfo);
}
Expand Down