BREAKING CHANGES: I have dramatically reduced dependencies of almost all assemblies on .NET runtime assemblies not part of core System assemblies, most specifically System.Drawing and System.Windows.Forms. This forced the removal of some overloaded methods and the replacement of leveraged structures and enums with native equivalents. I added Vanara.Windows.Shell.Common which has all the content from Vanara.WIndows.Shell that did not have dependencies. I extracted all extension methods from Gdi32 and User32 and moved them to Vanara.Windows.Extensions.

pull/279/head
dahall 2022-01-14 07:32:51 -07:00
parent 62326772d4
commit 0bb9797e2f
116 changed files with 774 additions and 667 deletions

View File

@ -26,9 +26,6 @@ CorrespondingAction, FileAttributeConstant, FileOpConstant, FilePermissionConsta
</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('net2')) Or $(TargetFramework.StartsWith('net3')) Or $(TargetFramework.StartsWith('net4')) ">
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net35' ">
<Reference Include="WindowsBase" />
</ItemGroup>

View File

@ -373,7 +373,7 @@ namespace Vanara.PInvoke
// POINT ptScreen, IAccessible **ppacc, VARIANT *pvarChild );
[DllImport(Lib.Oleacc, SetLastError = false, ExactSpelling = true)]
[PInvokeData("oleacc.h", MSDNShortId = "b781b74f-5c36-4a65-a9b1-ecf7f8e5b531")]
public static extern HRESULT AccessibleObjectFromPoint(System.Drawing.Point ptScreen, out IAccessible ppacc, [MarshalAs(UnmanagedType.Struct)] out object pvarChild);
public static extern HRESULT AccessibleObjectFromPoint(POINT ptScreen, out IAccessible ppacc, [MarshalAs(UnmanagedType.Struct)] out object pvarChild);
/// <summary>Retrieves the address of the specified interface for the object associated with the specified window.</summary>
/// <param name="hwnd">
@ -508,7 +508,7 @@ namespace Vanara.PInvoke
// HWND hwndApp, HWND hwndTarget, POINT ptTarget );
[DllImport(Lib.Oleacc, SetLastError = false, ExactSpelling = true)]
[PInvokeData("oleacc.h", MSDNShortId = "CB533913-95A7-45D5-B0D3-E931E4F73B2E")]
public static extern HRESULT AccNotifyTouchInteraction(HWND hwndApp, HWND hwndTarget, System.Drawing.Point ptTarget);
public static extern HRESULT AccNotifyTouchInteraction(HWND hwndApp, HWND hwndTarget, POINT ptTarget);
/// <summary>
/// Sets system values that indicate whether an assistive technology (AT) application's current state affects functionality that is

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using static Vanara.PInvoke.User32;
@ -109,7 +108,7 @@ namespace Vanara.PInvoke
public SplitButtonInfoStyle uSplitButtonInfoStyle;
/// <summary>A SIZE structure that specifies the size of the glyph in himlGlyph.</summary>
public Size size;
public SIZE size;
/// <summary>Initializes a new instance of the <see cref="BUTTON_SPLITINFO"/> struct and sets the uSplitStyle value.</summary>
/// <param name="buttonInfoStyle">The style.</param>

View File

@ -144,11 +144,11 @@ namespace Vanara.PInvoke
/// <summary>Gets the item rectangle.</summary>
/// <value>The item rectangle.</value>
public System.Drawing.Rectangle ItemRectangle => rcItem;
public RECT ItemRectangle => rcItem;
/// <summary>Gets the button rectangle.</summary>
/// <value>The button rectangle.</value>
public System.Drawing.Rectangle ButtonRectangle => rcButton;
public RECT ButtonRectangle => rcButton;
}
/// <summary>Contains information used with the CBEN_DRAGBEGIN notification code.</summary>

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
@ -950,7 +949,7 @@ namespace Vanara.PInvoke
public sealed class HDHITTESTINFO
{
/// <summary>A POINT structure that contains the point to be hit test, in client coordinates.</summary>
public Point pt;
public POINT pt;
/// <summary>
/// The variable that receives information about the results of a hit test. Two of these values can be combined, such as when the
@ -1035,13 +1034,6 @@ namespace Vanara.PInvoke
/// <param name="text">The text.</param>
public HDITEM(string text = null) => Text = text;
/// <summary>Gets or sets the bitmap. Aligned to the <see cref="hbm"/> field.</summary>
public Bitmap Bitmap
{
get => hbm.IsNull ? null : Image.FromHbitmap((IntPtr)hbm);
set { hbm = value?.GetHbitmap() ?? IntPtr.Zero; EnumExtensions.SetFlags(ref mask, HeaderItemMask.HDI_BITMAP); }
}
/// <summary>Gets or sets a value indicating whether this <see cref="HDITEM"/> is checked.</summary>
/// <value><c>true</c> if checked; otherwise, <c>false</c>.</value>
public bool Checked

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using static Vanara.PInvoke.Gdi32;
@ -567,7 +566,7 @@ namespace Vanara.PInvoke
/// </param>
/// <param name="riid">An IID for the image list.</param>
/// <returns>The address of a pointer to the interface for the image list if successful, NULL otherwise.</returns>
IImageList GetDragImage(out Point ppt, out Point pptHotspot, in Guid riid);
IImageList GetDragImage(out POINT ppt, out POINT pptHotspot, in Guid riid);
/// <summary>Gets the flags of an image.</summary>
/// <param name="i">A value of type int that contains the index of the images whose flags need to be retrieved.</param>
@ -810,7 +809,7 @@ namespace Vanara.PInvoke
/// </param>
/// <param name="riid">An IID for the image list.</param>
/// <returns>The address of a pointer to the interface for the image list if successful, NULL otherwise.</returns>
new IImageList GetDragImage(out Point ppt, out Point pptHotspot, in Guid riid);
new IImageList GetDragImage(out POINT ppt, out POINT pptHotspot, in Guid riid);
/// <summary>Gets the flags of an image.</summary>
/// <param name="i">A value of type int that contains the index of the images whose flags need to be retrieved.</param>
@ -908,10 +907,10 @@ namespace Vanara.PInvoke
/// <summary>Gets the dimensions of images in an image list. All images in an image list have the same dimensions.</summary>
/// <param name="il">The <see cref="IImageList"/> instance.</param>
/// <returns>The size of images.</returns>
public static Size GetIconSize(this IImageList il)
public static SIZE GetIconSize(this IImageList il)
{
il.GetIconSize(out var cx, out var cy);
return new Size(cx, cy);
return new SIZE(cx, cy);
}
/// <summary>Get an image list interface from an image list handle.</summary>
@ -1382,7 +1381,7 @@ namespace Vanara.PInvoke
/// <param name="size">
/// A value that contains the width and height, in pixels, of the images in the image list. All images in an image list have the same dimensions.
/// </param>
public static void SetIconSize(this IImageList il, Size size) => il.SetIconSize(size.Width, size.Height);
public static void SetIconSize(this IImageList il, SIZE size) => il.SetIconSize(size.Width, size.Height);
/// <summary>Contains information about an image in an image list. This structure is used with the IImageList::GetImageInfo function.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb761393")]

View File

@ -1,4 +1,3 @@
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -47,7 +46,7 @@ namespace Vanara.PInvoke
// int LBItemFromPt( HWND hLB, POINT pt, BOOL bAutoScroll); https://msdn.microsoft.com/en-us/library/windows/desktop/bb761724(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb761724")]
public static extern int LBItemFromPt(HWND hLB, Point pt, [MarshalAs(UnmanagedType.Bool)] bool bAutoScroll);
public static extern int LBItemFromPt(HWND hLB, POINT pt, [MarshalAs(UnmanagedType.Bool)] bool bAutoScroll);
/// <summary>Changes the specified single-selection list box to a drag list box.</summary>
/// <param name="hLB">

View File

@ -1,6 +1,5 @@
using System;
using System.Drawing;
using System.Linq;
//using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Vanara.Extensions;
@ -1186,11 +1185,11 @@ namespace Vanara.PInvoke
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/commctrl/nf-commctrl-listview_getitemindexrect
[PInvokeData("commctrl.h", MSDNShortId = "listview_getitemindexrect")]
public static bool ListView_GetItemIndexRect(HWND hwnd, in LVITEMINDEX plvii, int iSubItem, ListViewItemRect code, out Rectangle prc)
public static bool ListView_GetItemIndexRect(HWND hwnd, in LVITEMINDEX plvii, int iSubItem, ListViewItemRect code, out RECT prc)
{
var rc = new RECT((int)code, iSubItem, 0, 0);
var lr = SendMessage(hwnd, ListViewMessage.LVM_GETITEMINDEXRECT, in plvii, ref rc);
prc = lr == IntPtr.Zero ? Rectangle.Empty : (Rectangle)rc;
prc = lr == IntPtr.Zero ? RECT.Empty : rc;
return lr != IntPtr.Zero;
}
@ -1371,7 +1370,7 @@ namespace Vanara.PInvoke
public IntPtr lParam;
/// <summary>POINT structure with the initial search position. It is valid only if LVFI_NEARESTXY is set in the flags member.</summary>
public Point pt;
public POINT pt;
/// <summary>Virtual key code that specifies the direction to search.</summary>
public ConsoleKey vkDirection;
@ -1401,7 +1400,7 @@ namespace Vanara.PInvoke
/// <summary>Initializes a new instance of the <see cref="LVFINDINFO"/> struct.</summary>
/// <param name="point">The initial search position.</param>
/// <param name="searchDirection">The search direction.</param>
public LVFINDINFO(Point point, ConsoleKey searchDirection) : this()
public LVFINDINFO(POINT point, ConsoleKey searchDirection) : this()
{
flags = ListViewFindInfoFlag.LVFI_NEARESTXY;
pt = point;
@ -1494,7 +1493,7 @@ namespace Vanara.PInvoke
public struct LVHITTESTINFO
{
/// <summary>The position to hit test, in client coordinates.</summary>
public Point pt;
public POINT pt;
/// <summary>
/// The variable that receives information about the results of a hit test. This member can be one or more of the following values:
@ -1526,7 +1525,7 @@ namespace Vanara.PInvoke
/// <summary>Initializes a new instance of the <see cref="LVHITTESTINFO"/> class.</summary>
/// <param name="pt">The pt.</param>
public LVHITTESTINFO(Point pt) : this() => this.pt = pt;
public LVHITTESTINFO(POINT pt) : this() => this.pt = pt;
}
/// <summary>Used to describe insertion points.</summary>
@ -1633,7 +1632,7 @@ namespace Vanara.PInvoke
/// <summary>Gets or sets the size of an individual tile.</summary>
/// <value>The size of an individual tile.</value>
public Size TileSize
public SIZE TileSize
{
get => sizeTile;
set { sizeTile = value; dwMask |= ListViewTileViewMask.LVTVIM_TILESIZE; dwFlags |= ListViewTileViewFlag.LVTVIF_FIXEDSIZE; }
@ -1711,7 +1710,7 @@ namespace Vanara.PInvoke
/// POINT structure that indicates the location at which the event occurred. This member is undefined for notification messages
/// that do not use it.
/// </summary>
public Point ptAction;
public POINT ptAction;
/// <summary>Application-defined value of the item. This member is undefined for notification messages that do not use it.</summary>
public IntPtr lParam;
@ -1766,31 +1765,31 @@ namespace Vanara.PInvoke
public int yOffset;
/// <summary>Initializes a new instance of the <see cref="LVBKIMAGE"/> class.</summary>
/// <param name="bmp">The BMP.</param>
/// <param name="isWatermark">if set to <c>true</c> [is watermark].</param>
/// <param name="isWatermarkAlphaBlended">if set to <c>true</c> [is watermark alpha blended].</param>
public LVBKIMAGE(Bitmap bmp, bool isWatermark, bool isWatermarkAlphaBlended)
/// <param name="bmp">The handle of the background bitmap.</param>
/// <param name="isWatermark">if set to <c>true</c> a watermark bitmap is applied.</param>
/// <param name="isWatermarkAlphaBlended">if set to <c>true</c> the watermark is alpha blended.</param>
public LVBKIMAGE(HBITMAP bmp, bool isWatermark, bool isWatermarkAlphaBlended)
{
Bitmap = bmp;
hBmp = bmp;
ulFlags = isWatermark ? ListViewBkImageFlag.LVBKIF_TYPE_WATERMARK : ListViewBkImageFlag.LVBKIF_SOURCE_HBITMAP;
if (isWatermark && isWatermarkAlphaBlended)
ulFlags |= ListViewBkImageFlag.LVBKIF_FLAG_ALPHABLEND;
}
/// <summary>Initializes a new instance of the <see cref="LVBKIMAGE"/> class.</summary>
/// <param name="bmp">The BMP.</param>
/// <param name="isTiled">if set to <c>true</c> [is tiled].</param>
public LVBKIMAGE(Bitmap bmp, bool isTiled)
/// <param name="bmp">The handle of the background bitmap.</param>
/// <param name="isTiled">if set to <c>true</c>, the bitmap image is tiled.</param>
public LVBKIMAGE(HBITMAP bmp, bool isTiled)
{
Bitmap = bmp;
hBmp = bmp;
ulFlags = ListViewBkImageFlag.LVBKIF_SOURCE_HBITMAP;
if (isTiled)
ulFlags |= ListViewBkImageFlag.LVBKIF_STYLE_TILE;
}
/// <summary>Initializes a new instance of the <see cref="LVBKIMAGE"/> class.</summary>
/// <param name="url">The URL.</param>
/// <param name="isTiled">if set to <c>true</c> [is tiled].</param>
/// <param name="url">The URL of the background image.</param>
/// <param name="isTiled">if set to <c>true</c>, the bitmap image is tiled.</param>
public LVBKIMAGE(string url, bool isTiled)
{
Url = url;
@ -1813,14 +1812,6 @@ namespace Vanara.PInvoke
pszImage = new StrPtrAuto(cchImageMax = 1024);
}
/// <summary>Gets or sets the bitmap.</summary>
/// <value>The bitmap.</value>
public Bitmap Bitmap
{
get => hBmp.IsNull ? null : System.Drawing.Image.FromHbitmap((IntPtr)hBmp);
set => hBmp = value?.GetHbitmap() ?? IntPtr.Zero;
}
/// <summary>Gets or sets the URL.</summary>
/// <value>The URL.</value>
public string Url

View File

@ -1,7 +1,5 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke
@ -648,7 +646,7 @@ namespace Vanara.PInvoke
public struct TCHITTESTINFO
{
/// <summary>Position to hit test, in client coordinates.</summary>
public Point pt;
public POINT pt;
/// <summary>Variable that receives the results of a hit test. The tab control sets this member to one of the following values:</summary>
public TabControlHitTestFlags flags;

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Vanara.InteropServices;
using static Vanara.PInvoke.User32;
@ -935,7 +934,7 @@ namespace Vanara.PInvoke
public HWND hwnd;
/// <summary>Client coordinates of the point to test.</summary>
public Point pt;
public POINT pt;
/// <summary>
/// TOOLINFO structure. If the point specified by pt is in the tool specified by hwnd, this structure receives information about

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
@ -702,7 +701,7 @@ namespace Vanara.PInvoke
/// POINT structure that contains the client coordinates of the mouse at the time the event occurred that caused the notification
/// message to be sent.
/// </summary>
public Point ptDrag;
public POINT ptDrag;
}
/// <summary>
@ -880,7 +879,7 @@ namespace Vanara.PInvoke
public struct TVHITTESTINFO
{
/// <summary>Client coordinates of the point to test.</summary>
public Point pt;
public POINT pt;
/// <summary>Variable that receives information about the results of a hit test.</summary>
public TreeViewHitTestFlags flags;
@ -1462,7 +1461,7 @@ namespace Vanara.PInvoke
/// <summary>Gets the bounds.</summary>
/// <value>The bounds.</value>
public Rectangle Bounds => prc.ToStructure<RECT>();
public RECT Bounds => prc.ToStructure<RECT>();
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
void IDisposable.Dispose() => Marshal.FreeCoTaskMem(prc);

View File

@ -1375,7 +1375,7 @@ namespace Vanara.PInvoke
/// <para>Type: <c><c>POINT</c></c></para>
/// <para>A <c>POINT</c> structure that contains the client coordinates of the mouse when the click occurred.</para>
/// </summary>
public System.Drawing.Point pt;
public POINT pt;
/// <summary>
/// <para>Type: <c><c>LPARAM</c></c></para>

View File

@ -2568,7 +2568,7 @@ namespace Vanara.PInvoke
/// <c>PSD_INHUNDREDTHSOFMILLIMETERS</c> flag indicates the units of measurement.
/// </para>
/// </summary>
public System.Drawing.Point ptPaperSize;
public POINT ptPaperSize;
/// <summary>
/// <para>Type: <c>RECT</c></para>

View File

@ -645,7 +645,7 @@ namespace Vanara.PInvoke
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[DllImport(Lib.DwmApi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dwmapi.h")]
public static extern HRESULT DwmRenderGesture(GESTURE_TYPE gt, uint cContacts, ref uint pdwPointerID, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Drawing.Point[] pPoints);
public static extern HRESULT DwmRenderGesture(GESTURE_TYPE gt, uint cContacts, ref uint pdwPointerID, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] POINT[] pPoints);
/// <summary>
/// Sets a static, iconic bitmap to display a live preview (also known as a Peek preview) of a window or tab. The taskbar can use
@ -661,7 +661,7 @@ namespace Vanara.PInvoke
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[DllImport(Lib.DwmApi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dwmapi.h")]
public static extern HRESULT DwmSetIconicLivePreviewBitmap(HWND hwnd, HBITMAP hbmp, in System.Drawing.Point pptClient, DWM_SETICONICPREVIEW_Flags dwSITFlags);
public static extern HRESULT DwmSetIconicLivePreviewBitmap(HWND hwnd, HBITMAP hbmp, in POINT pptClient, DWM_SETICONICPREVIEW_Flags dwSITFlags);
/// <summary>
/// Sets a static, iconic bitmap to display a live preview (also known as a Peek preview) of a window or tab. The taskbar can use
@ -747,7 +747,7 @@ namespace Vanara.PInvoke
/// <param name="ptTether">The tether.</param>
[DllImport(Lib.DwmApi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dwmapi.h")]
public static extern HRESULT DwmTetherContact(uint dwPointerID, [MarshalAs(UnmanagedType.Bool)] bool fEnable, System.Drawing.Point ptTether);
public static extern HRESULT DwmTetherContact(uint dwPointerID, [MarshalAs(UnmanagedType.Bool)] bool fEnable, POINT ptTether);
/// <summary>Coordinates the animations of tool windows with the Desktop Window Manager (DWM).</summary>
/// <param name="hwnd">Handle to the window.</param>
@ -828,10 +828,6 @@ namespace Vanara.PInvoke
dwFlags = DWM_BLURBEHIND_Mask.DWM_BB_ENABLE;
}
/// <summary>Gets the region.</summary>
/// <value>The region.</value>
public System.Drawing.Region Region => System.Drawing.Region.FromHrgn((IntPtr)hRgnBlur);
/// <summary>Gets or sets a value indicating whether the window's colorization should transition to match the maximized windows.</summary>
/// <value><c>true</c> if the window's colorization should transition to match the maximized windows; otherwise, <c>false</c>.</value>
public bool TransitionOnMaximized
@ -844,14 +840,16 @@ namespace Vanara.PInvoke
}
}
#if SYSDRAW
/// <summary>Sets the region.</summary>
/// <param name="graphics">The graphics.</param>
/// <param name="region">The region.</param>
public void SetRegion(System.Drawing.Graphics graphics, System.Drawing.Region region)
public void SetRegion(Graphics graphics, Region region)
{
hRgnBlur = region.GetHrgn(graphics);
dwFlags |= DWM_BLURBEHIND_Mask.DWM_BB_BLURREGION;
}
#endif
}
/// <summary>Structure to get colorization information using the <see cref="DwmpGetColorizationParameters"/> function.</summary>

View File

@ -0,0 +1,72 @@
using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
using static Vanara.PInvoke.Gdi32;
namespace Vanara.PInvoke
{
/// <summary>Extension methods to convert GdiObj handle variants to their .NET equivalents.</summary>
public static class GdiObjExtensions
{
/// <summary>Converts the generic GDI object handle to a specific handle.</summary>
/// <typeparam name="T">The handle type to which to convert.</typeparam>
/// <param name="hObj">The generic GDI object handle.</param>
/// <returns>The converted handle of type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException">The conversion type specified is not valid for the supplied GDI object.</exception>
public static T ConvertTo<T>(this IGraphicsObjectHandle hObj) where T : IGraphicsObjectHandle
{
var ot = GetObjectType(hObj.DangerousGetHandle());
if (ot == 0) Win32Error.ThrowLastError();
if (!CorrespondingTypeAttribute.CanGet(ot, typeof(T)))
throw new ArgumentException($"The conversion type specified is not valid for the supplied GDI object.");
return (T)(object)hObj.DangerousGetHandle();
}
/// <summary>Draws on a device context (<see cref="SafeHDC"/>) via a DIB section. This is useful when you need to draw on a transparent background.</summary>
/// <param name="hdc">The device context.</param>
/// <param name="bounds">The bounds of the device context to paint.</param>
/// <param name="drawMethod">The draw method.</param>
public static void DrawViaDIB(this SafeHDC hdc, in RECT bounds, Action<SafeHDC, RECT> drawMethod) => DrawViaDIB((HDC)hdc, bounds, drawMethod);
/// <summary>Draws on a device context (<see cref="HDC"/>) via a DIB section. This is useful when you need to draw on a transparent background.</summary>
/// <param name="hdc">The device context.</param>
/// <param name="bounds">The bounds of the device context to paint.</param>
/// <param name="drawMethod">The draw method.</param>
public static void DrawViaDIB(this in HDC hdc, in RECT bounds, Action<SafeHDC, RECT> drawMethod)
{
// Create a memory DC so we can work off screen
using var memoryHdc = CreateCompatibleDC(hdc);
// Create a device-independent bitmap and select it into our DC
var info = new BITMAPINFO(bounds.Width, -bounds.Height);
using (memoryHdc.SelectObject(CreateDIBSection(hdc, info, DIBColorMode.DIB_RGB_COLORS, out var pBits)))
{
// Call method
drawMethod(memoryHdc, bounds);
// Copy to foreground
BitBlt(hdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, RasterOperationMode.SRCCOPY);
}
}
/// <summary>Determines whether the bitmap is a bottom-up DIB.</summary>
/// <param name="hbmp">The handle of the bitmap to assess.</param>
/// <returns><see langword="true"/> if the specified bitmap is a bottom-up DIB; otherwise, <see langword="false"/>.</returns>
public static bool IsBottomUpDIB(this in HBITMAP hbmp)
{
var dibSz = Marshal.SizeOf(typeof(DIBSECTION));
using var mem = GetObject(hbmp, dibSz);
return mem.Size == dibSz && mem.ToStructure<DIBSECTION>().dsBmih.biHeight > 0;
}
/// <summary>Determines whether the bitmap is a bottom-up DIB.</summary>
/// <param name="hbmp">The handle of the bitmap to assess.</param>
/// <returns><see langword="true"/> if the specified bitmap is a bottom-up DIB; otherwise, <see langword="false"/>.</returns>
public static bool IsDIB(this in HBITMAP hbmp)
{
var dibSz = Marshal.SizeOf(typeof(DIBSECTION));
using var mem = GetObject(hbmp, dibSz);
return mem.Size == dibSz;
}
}
}

View File

@ -6,9 +6,6 @@
<PropertyGroup>
<Description>PInvoke API (methods, structures and constants) imported from Windows Gdi32.dll</Description>
<AssemblyTitle>$(AssemblyName)</AssemblyTitle>
<!--<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>-->
<TargetFrameworks>net20;net35;net40;net45;net5.0;net6.0;netstandard2.0;netcoreapp2.0;netcoreapp2.1;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<AssemblyName>Vanara.PInvoke.Gdi32</AssemblyName>
<PackageId>$(AssemblyName)</PackageId>
@ -28,7 +25,4 @@ ABC ABCFLOAT AXESLIST AXISINFO BITMAP BITMAPCOREHEADER BITMAPCOREINFO BITMAPFILE
<ProjectReference Include="..\..\Core\Vanara.Core.csproj" />
<ProjectReference Include="..\Shared\Vanara.PInvoke.Shared.csproj" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) Or $(TargetFramework.StartsWith('netcore')) ">
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
</ItemGroup>
</Project>

View File

@ -1248,27 +1248,27 @@ namespace Vanara.PInvoke
/// <summary>This member is reserved and must be zero.</summary>
public byte rgbReserved;
/// <summary>Gets or sets the color associated with the <see cref="RGBQUAD"/> structure.</summary>
/// <value>The color.</value>
public System.Drawing.Color Color
{
get => System.Drawing.Color.FromArgb(rgbReserved, rgbRed, rgbGreen, rgbBlue);
set { rgbReserved = value.A; rgbBlue = value.B; rgbGreen = value.G; rgbRed = value.R; }
}
/// <summary>Gets a value indicating whether any transparency is defined.</summary>
/// <value><see langword="true"/> if this value is transparent; otherwise, <see langword="false"/>.</value>
public bool IsTransparent => rgbReserved == 0;
/// <summary>Performs an implicit conversion from <see cref="System.Drawing.Color"/> to <see cref="RGBQUAD"/>.</summary>
/// <param name="c">The c.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator RGBQUAD(System.Drawing.Color c) => new() { Color = c };
/// <summary>Gets or sets the color associated with the <see cref="RGBQUAD"/> structure.</summary>
/// <value>The color.</value>
public COLORREF Color
{
get => new(rgbRed, rgbGreen, rgbBlue) { A = rgbReserved };
set { rgbReserved = value.A; rgbBlue = value.B; rgbGreen = value.G; rgbRed = value.R; }
}
/// <summary>Performs an implicit conversion from <see cref="RGBQUAD"/> to <see cref="System.Drawing.Color"/>.</summary>
/// <summary>Performs an implicit conversion from <see cref="COLORREF"/> to <see cref="RGBQUAD"/>.</summary>
/// <param name="c">The c.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator System.Drawing.Color(RGBQUAD c) => c.Color;
public static implicit operator RGBQUAD(COLORREF c) => new() { Color = c };
/// <summary>Performs an implicit conversion from <see cref="RGBQUAD"/> to <see cref="COLORREF"/>.</summary>
/// <param name="c">The c.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator COLORREF(RGBQUAD c) => c.Color;
}
/// <summary>Provides a safe handle to a <see cref="BITMAPINFO"/> structure.</summary>

View File

@ -1620,7 +1620,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "2a56c71b-2e96-418b-8625-a808d76e0c85")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PlgBlt(HDC hdcDest, [In, MarshalAs(UnmanagedType.LPArray, SizeConst = 3)] System.Drawing.Point[] lpPoint,
public static extern bool PlgBlt(HDC hdcDest, [In, MarshalAs(UnmanagedType.LPArray, SizeConst = 3)] POINT[] lpPoint,
HDC hdcSrc, int xSrc, int ySrc, int width, int height, HBITMAP hbmMask, int xMask, int yMask);
/// <summary>

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -344,7 +343,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "0b938237-cb06-4776-86f8-14478abcee00")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetBrushOrgEx(HDC hdc, out Point lppt);
public static extern bool GetBrushOrgEx(HDC hdc, out POINT lppt);
/// <summary>
/// <para>
@ -481,7 +480,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "dcc7575a-49fd-4306-8baa-57e9e0d5ed1f")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetBrushOrgEx(HDC hdc, int x, int y, in Point lppt);
public static extern bool SetBrushOrgEx(HDC hdc, int x, int y, in POINT lppt);
/// <summary>
/// <c>SetDCBrushColor</c> function sets the current device context (DC) brush color to the specified color value. If the device

View File

@ -1,5 +1,4 @@
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
@ -132,7 +131,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "0106867c-e8c5-4826-8cba-60c29e1d021a")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DPtoLP(HDC hdc, [In, Out] Point[] lppt, int c);
public static extern bool DPtoLP(HDC hdc, [In, Out] POINT[] lppt, int c);
/// <summary>The <c>GetCurrentPositionEx</c> function retrieves the current position in logical coordinates.</summary>
/// <param name="hdc">A handle to the device context.</param>
@ -146,7 +145,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "23a5ac58-2b88-42d3-ab02-8edb8ef187cc")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCurrentPositionEx(HDC hdc, out Point lppt);
public static extern bool GetCurrentPositionEx(HDC hdc, out POINT lppt);
/// <summary>The <c>GetGraphicsMode</c> function retrieves the current graphics mode for the specified device context.</summary>
/// <param name="hdc">A handle to the device context.</param>
@ -274,7 +273,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "6e6c7090-edf4-46a3-8bcd-10a00c0cf847")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetViewportOrgEx(HDC hdc, out Point lppoint);
public static extern bool GetViewportOrgEx(HDC hdc, out POINT lppoint);
/// <summary>This function retrieves the x-extent and y-extent of the window for the specified device context.</summary>
/// <param name="hdc">A handle to the device context.</param>
@ -304,7 +303,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "9579ed10-6d4c-4724-af8b-22cab5b6ff5e")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowOrgEx(HDC hdc, out Point lppoint);
public static extern bool GetWindowOrgEx(HDC hdc, out POINT lppoint);
/// <summary>The <c>GetWorldTransform</c> function retrieves the current world-space to page-space transformation.</summary>
/// <param name="hdc">A handle to the device context.</param>
@ -331,7 +330,7 @@ namespace Vanara.PInvoke
/// <returns>The height in pixels.</returns>
public static int LogicalHeightToDeviceWidth(int height, HDC hdc = default)
{
var pts = new[] { new Point(0, height) };
var pts = new[] { new POINT(0, height) };
LPtoDP(hdc.IsNull ? SafeHDC.ScreenCompatibleDCHandle : hdc, pts, 1);
return pts[0].Y;
}
@ -342,7 +341,7 @@ namespace Vanara.PInvoke
/// <returns>The width in pixels.</returns>
public static int LogicalWidthToDeviceWidth(int width, HDC hdc = default)
{
var pts = new[] { new Point(width, 0) };
var pts = new[] { new POINT(width, 0) };
LPtoDP(hdc.IsNull ? SafeHDC.ScreenCompatibleDCHandle : hdc, pts, 1);
return pts[0].X;
}
@ -385,7 +384,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "670a16fb-842e-4250-9ad7-dc08e849c2ba")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool LPtoDP(HDC hdc, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] Point[] lppt, int c);
public static extern bool LPtoDP(HDC hdc, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] POINT[] lppt, int c);
/// <summary>
/// The <c>ModifyWorldTransform</c> function changes the world transformation for a device context using the specified mode.
@ -462,7 +461,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "54311cbe-1c54-4193-8991-891dbd0856bf")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool OffsetViewportOrgEx(HDC hdc, int x, int y, out Point lppt);
public static extern bool OffsetViewportOrgEx(HDC hdc, int x, int y, out POINT lppt);
/// <summary>
/// The <c>OffsetWindowOrgEx</c> function modifies the window origin for a device context using the specified horizontal and vertical offsets.
@ -483,7 +482,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "085f40ac-d91f-4853-8ad1-1fc5da08b981")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool OffsetWindowOrgEx(HDC hdc, int x, int y, out Point lppt);
public static extern bool OffsetWindowOrgEx(HDC hdc, int x, int y, out POINT lppt);
/// <summary>
/// The <c>ScaleViewportExtEx</c> function modifies the viewport for a device context using the ratios formed by the specified
@ -766,7 +765,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "d3b6326e-9fec-42a1-8d2e-d1ad4fcc79a4")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetViewportOrgEx(HDC hdc, int x, int y, out Point lppt);
public static extern bool SetViewportOrgEx(HDC hdc, int x, int y, out POINT lppt);
/// <summary>
/// The <c>SetWindowExtEx</c> function sets the horizontal and vertical extents of the window for a device context by using the
@ -854,7 +853,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "75409b5a-c003-49f2-aceb-a28330b92b0a")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowOrgEx(HDC hdc, int x, int y, out Point lppt);
public static extern bool SetWindowOrgEx(HDC hdc, int x, int y, out POINT lppt);
/// <summary>
/// The <c>SetWorldTransform</c> function sets a two-dimensional linear transformation between world space and page space for the

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using Vanara.InteropServices;
@ -758,7 +757,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "795c6a69-7146-4d1a-abf9-ce1d740ca946")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetDCOrgEx(HDC hdc, out Point lppt);
public static extern bool GetDCOrgEx(HDC hdc, out POINT lppt);
/// <summary>The <c>GetDCPenColor</c> function retrieves the current pen color for the specified device context (DC).</summary>
/// <param name="hdc">A handle to the DC whose brush color is to be returned.</param>

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Vanara.InteropServices;
@ -496,7 +495,7 @@ namespace Vanara.PInvoke
public struct DISPLAYCONFIG_DESKTOP_IMAGE_INFO
{
/// <summary>A POINTL structure that specifies the size of the VidPn source surface that is being displayed on the monitor.</summary>
public Point PathSourceSize;
public POINT PathSourceSize;
/// <summary>
/// A RECTL structure that defines where the desktop image will be positioned within path source. Region must be completely
@ -958,7 +957,7 @@ namespace Vanara.PInvoke
/// A POINTL structure that specifies the position in the desktop coordinate space of the upper-left corner of this source
/// surface. The source surface that is located at (0, 0) is always the primary source surface.
/// </summary>
public Point position;
public POINT position;
}
/// <summary>

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
@ -4859,7 +4858,7 @@ namespace Vanara.PInvoke
public uint gmBlackBoxY;
/// <summary>The x- and y-coordinates of the upper left corner of the smallest rectangle that completely encloses the glyph.</summary>
public Point gmptGlyphOrigin;
public POINT gmptGlyphOrigin;
/// <summary>The horizontal distance from the origin of the current character cell to the origin of the next character cell.</summary>
public short gmCellIncX;
@ -5300,22 +5299,22 @@ namespace Vanara.PInvoke
public uint otmusMinimumPPEM;
/// <summary>The recommended horizontal and vertical size for subscripts in this font.</summary>
public Point otmptSubscriptSize;
public POINT otmptSubscriptSize;
/// <summary>
/// The recommended horizontal and vertical offset for subscripts in this font. The subscript offset is measured from the
/// character origin to the origin of the subscript character.
/// </summary>
public Point otmptSubscriptOffset;
public POINT otmptSubscriptOffset;
/// <summary>The recommended horizontal and vertical size for superscripts in this font.</summary>
public Point otmptSuperscriptSize;
public POINT otmptSuperscriptSize;
/// <summary>
/// The recommended horizontal and vertical offset for superscripts in this font. The superscript offset is measured from the
/// character base line to the base line of the superscript character.
/// </summary>
public Point otmptSuperscriptOffset;
public POINT otmptSuperscriptOffset;
/// <summary>The width of the strikeout stroke for this font. Typically, this is the width of the em dash for the font.</summary>
public uint otmsStrikeoutSize;

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -291,7 +290,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getpath int GetPath( HDC hdc, LPPOINT apt, LPBYTE aj, int cpt );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "2dc7736a-03fc-4623-a566-6c3e368da174")]
public static extern int GetPath(HDC hdc, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] Point[] apt, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] VertexType[] aj, int cpt);
public static extern int GetPath(HDC hdc, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] POINT[] apt, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] VertexType[] aj, int cpt);
/// <summary>
/// The <c>PathToRegion</c> function creates a region from the path that is selected into the specified device context. The resulting

View File

@ -742,7 +742,7 @@ namespace Vanara.PInvoke
/// one pixel wide on raster devices. The <c>y</c> member in the <c>POINT</c> structure for <c>lopnWidth</c> is not used.
/// </para>
/// </summary>
public System.Drawing.Point lopnWidth;
public POINT lopnWidth;
/// <summary>
/// <para>The pen color. To generate a COLORREF structure, use the RGB macro.</para>

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -1393,10 +1392,10 @@ namespace Vanara.PInvoke
public struct DRAWPATRECT
{
/// <summary>The upper-left corner of the rectangle, in logical units.</summary>
public Point ptPosition;
public POINT ptPosition;
/// <summary>The lower-right corner of the rectangle, in logical units.</summary>
public Point ptSize;
public POINT ptSize;
/// <summary>
/// <para>The style of the rectangle. It can be one of the following.</para>

View File

@ -34,6 +34,17 @@ namespace Vanara.PInvoke
RGN_COPY = 5,
}
/// <summary>The fill mode used to determine which pixels are in the region.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")]
public enum RGN_FILLMODE
{
/// <summary>Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line).</summary>
ALTERNATE,
/// <summary>Selects winding mode (fills any region with a nonzero winding value).</summary>
WINDING
}
/// <summary>The type of the resulting region.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")]
public enum RGN_TYPE
@ -209,7 +220,7 @@ namespace Vanara.PInvoke
// int cPoint, int iMode );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "dd7ad6de-c5f2-46e4-8d28-24caaa48ba3a")]
public static extern SafeHRGN CreatePolygonRgn(System.Drawing.Point pptl, int cPoint, System.Drawing.Drawing2D.FillMode iMode);
public static extern SafeHRGN CreatePolygonRgn(POINT pptl, int cPoint, RGN_FILLMODE iMode);
/// <summary>The <c>CreatePolyPolygonRgn</c> function creates a region consisting of a series of polygons. The polygons can overlap.</summary>
/// <param name="pptl">
@ -250,7 +261,7 @@ namespace Vanara.PInvoke
// *pptl, const INT *pc, int cPoly, int iMode );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "1113d3dc-8e3f-436c-a5a8-191785bc7fcc")]
public static extern SafeHRGN CreatePolyPolygonRgn([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] System.Drawing.Point[] pptl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] int[] pc, int cPoly, System.Drawing.Drawing2D.FillMode iMode);
public static extern SafeHRGN CreatePolyPolygonRgn([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] POINT[] pptl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] int[] pc, int cPoly, RGN_FILLMODE iMode);
/// <summary>The <c>CreateRectRgn</c> function creates a rectangular region.</summary>
/// <param name="x1">Specifies the x-coordinate of the upper-left corner of the region in logical units.</param>
@ -414,7 +425,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getpolyfillmode int GetPolyFillMode( HDC hdc );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "febf96fb-bf2e-4eb2-ab5f-89741a1decad")]
public static extern System.Drawing.Drawing2D.FillMode GetPolyFillMode(HDC hdc);
public static extern RGN_FILLMODE GetPolyFillMode(HDC hdc);
/// <summary>
/// The <c>GetRegionData</c> function fills the specified buffer with data describing a region. This data includes the dimensions of
@ -611,7 +622,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-setpolyfillmode int SetPolyFillMode( HDC hdc, int mode );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "233926c4-2658-405d-89b6-05ece844623d")]
public static extern System.Drawing.Drawing2D.FillMode SetPolyFillMode(HDC hdc, System.Drawing.Drawing2D.FillMode mode);
public static extern RGN_FILLMODE SetPolyFillMode(HDC hdc, RGN_FILLMODE mode);
/// <summary>The <c>SetRectRgn</c> function converts a region into a rectangular region with the specified coordinates.</summary>
/// <param name="hrgn">Handle to the region.</param>

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -43,12 +42,6 @@ namespace Vanara.PInvoke
hOld = SelectObject(hdc, hObj);
}
/// <summary>Initializes a new instance of the <see cref="GdiObjectContext"/> class.</summary>
/// <param name="dc">The device context into which <paramref name="hObj"/> is selected.</param>
/// <param name="hObj">The graphics object to select.</param>
/// <exception cref="ArgumentNullException">dc - Device context cannot be null.</exception>
public GdiObjectContext(IDeviceContext dc, HGDIOBJ hObj) : this(new SafeHDC(dc ?? throw new ArgumentNullException(nameof(dc), "Device context cannot be null.")), hObj) { }
/// <inheritdoc/>
void IDisposable.Dispose() => SelectObject(hDC, hOld);
}
@ -77,10 +70,6 @@ namespace Vanara.PInvoke
/// <returns>The result of the conversion.</returns>
public static implicit operator HGDIOBJ(SafeHBITMAP h) => h.handle;
/// <summary>Creates a <see cref="Bitmap"/> from an <see cref="SafeHBITMAP"/> preserving transparency, if possible.</summary>
/// <returns>The Bitmap instance. If this is a <c>NULL</c> handle, <see langword="null"/> is returned.</returns>
public Bitmap ToBitmap() => ((HBITMAP)this).ToBitmap();
/// <inheritdoc/>
protected override bool InternalReleaseHandle() => DeleteObject(this);
}
@ -116,8 +105,6 @@ namespace Vanara.PInvoke
/// <summary>A SafeHandle to track DC handles.</summary>
public class SafeHDC : SafeHANDLE
{
private readonly IDeviceContext idc;
/// <summary>Initializes a new instance of the <see cref="SafeHDC"/> class and assigns an existing handle.</summary>
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
/// <param name="ownsHandle">
@ -125,52 +112,30 @@ namespace Vanara.PInvoke
/// </param>
public SafeHDC(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// <summary>Initializes a new instance of the <see cref="SafeHDC"/> class.</summary>
/// <param name="dc">An <see cref="IDeviceContext"/> instance.</param>
public SafeHDC(IDeviceContext dc) : base(IntPtr.Zero)
{
if (dc == null) return;
idc = dc;
SetHandle(dc.GetHdc());
}
private SafeHDC() : base() { }
/// <summary>Gets the screen compatible device context handle.</summary>
/// <value>The screen compatible device context handle.</value>
public static SafeHDC ScreenCompatibleDCHandle => CreateCompatibleDC(HDC.NULL);
/// <summary>Performs an explicit conversion from <see cref="SafeHDC"/> to <see cref="Graphics"/>.</summary>
/// <param name="hdc">The HDC.</param>
/// <returns>The result of the conversion.</returns>
public static explicit operator Graphics(SafeHDC hdc) => Graphics.FromHdc(hdc.handle);
/// <summary>Performs an implicit conversion from <see cref="SafeHDC"/> to <see cref="HDC"/>.</summary>
/// <param name="h">The safe handle instance.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator HDC(SafeHDC h) => h.handle;
/// <summary>Performs an implicit conversion from <see cref="Graphics"/> to <see cref="SafeHDC"/>.</summary>
/// <param name="graphics">The <see cref="Graphics"/> instance.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator SafeHDC(Graphics graphics) => new SafeHDC(graphics);
/// <summary>Gets the compatible device context handle.</summary>
/// <returns>A device context handle.</returns>
public SafeHDC GetCompatibleDCHandle() => CreateCompatibleDC(this);
public SafeHDC GetCompatibleDCHandle() => CreateCompatibleDC(handle);
/// <summary>Creates a context into which a graphics object is selected.</summary>
/// <param name="hObject">The graphics object to select.</param>
/// <returns>A selection context for the graphics object.</returns>
public GdiObjectContext SelectObject(HGDIOBJ hObject) => new GdiObjectContext(this, hObject);
public GdiObjectContext SelectObject(HGDIOBJ hObject) => new GdiObjectContext(handle, hObject);
/// <inheritdoc/>
protected override bool InternalReleaseHandle()
{
if (idc == null)
return DeleteDC(this);
idc.ReleaseHdc();
return true;
return DeleteDC(handle);
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -319,7 +318,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "af11eeb7-4036-4a90-8685-9b5719f79e01")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveToEx(HDC hdc, int x, int y, out Point lppt);
public static extern bool MoveToEx(HDC hdc, int x, int y, out POINT lppt);
/// <summary>
/// The <c>Pie</c> function draws a pie-shaped wedge bounded by the intersection of an ellipse and two radials. The pie is outlined
@ -382,7 +381,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "d1622574-c65e-4265-9a17-22bb4d2cae0e")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PolyBezier(HDC hdc, [In] Point[] apt, uint cpt);
public static extern bool PolyBezier(HDC hdc, [In] POINT[] apt, uint cpt);
/// <summary>The <c>PolyBezierTo</c> function draws one or more Bézier curves.</summary>
/// <param name="hdc">A handle to a device context.</param>
@ -409,7 +408,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "0c8d6d6d-d0a3-4188-91ad-934e6f054862")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PolyBezierTo(HDC hdc, [In] Point[] apt, uint cpt);
public static extern bool PolyBezierTo(HDC hdc, [In] POINT[] apt, uint cpt);
/// <summary>The <c>PolyDraw</c> function draws a set of line segments and Bézier curves.</summary>
/// <param name="hdc">A handle to a device context.</param>
@ -486,7 +485,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "5fd3f285-dcf3-4cd0-915a-236ba7902353")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PolyDraw(HDC hdc, [In] Point[] apt, [In] VertexType[] aj, int cpt);
public static extern bool PolyDraw(HDC hdc, [In] POINT[] apt, [In] VertexType[] aj, int cpt);
/// <summary>
/// The <c>Polygon</c> function draws a polygon consisting of two or more vertices connected by straight lines. The polygon is
@ -511,7 +510,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "2f958b91-039a-4e02-b727-be142bb18b06")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Polygon(HDC hdc, [In] System.Drawing.Point[] apt, int cpt);
public static extern bool Polygon(HDC hdc, [In] POINT[] apt, int cpt);
/// <summary>The <c>Polyline</c> function draws a series of line segments by connecting the points in the specified array.</summary>
/// <param name="hdc">A handle to a device context.</param>
@ -529,7 +528,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "55481dd0-3db7-4131-b383-4d0036943e60")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Polyline(HDC hdc, [In] Point[] apt, int cpt);
public static extern bool Polyline(HDC hdc, [In] POINT[] apt, int cpt);
/// <summary>The <c>PolylineTo</c> function draws one or more straight lines.</summary>
/// <param name="hdc">A handle to the device context.</param>
@ -553,7 +552,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "76020742-b651-4244-82c3-13034573c306")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PolylineTo(HDC hdc, [In] Point[] apt, uint cpt);
public static extern bool PolylineTo(HDC hdc, [In] POINT[] apt, uint cpt);
/// <summary>
/// The <c>PolyPolygon</c> function draws a series of closed polygons. Each polygon is outlined by using the current pen and filled
@ -587,7 +586,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "ac0a2802-c8b0-4cd7-9521-5b179f2c70b9")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PolyPolygon(HDC hdc, [In] System.Drawing.Point[] apt, [In] int[] asz, int csz);
public static extern bool PolyPolygon(HDC hdc, [In] POINT[] apt, [In] int[] asz, int csz);
/// <summary>The <c>PolyPolyline</c> function draws multiple series of connected line segments.</summary>
/// <param name="hdc">A handle to the device context.</param>
@ -613,7 +612,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "71a9273f-321b-4efb-ac73-5979f8151d05")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PolyPolyline(HDC hdc, [In] Point[] apt, [In] uint[] asz, uint csz);
public static extern bool PolyPolyline(HDC hdc, [In] POINT[] apt, [In] uint[] asz, uint csz);
/// <summary>
/// The <c>Rectangle</c> function draws a rectangle. The rectangle is outlined by using the current pen and filled by using the

View File

@ -7162,7 +7162,7 @@ namespace Vanara.PInvoke
/// new process calls <c>CreateWindow</c> to create an overlapped window if the x or y parameter of <c>CreateWindow</c> is CW_USEDEFAULT.
/// </para>
/// </summary>
public System.Drawing.Point WindowPosition { get => new System.Drawing.Point((int)dwX, (int)dwY); set { dwX = (uint)value.X; dwY = (uint)value.Y; dwFlags = dwFlags.SetFlags(STARTF.STARTF_USEPOSITION, value != System.Drawing.Point.Empty); } }
public POINT WindowPosition { get => new POINT((int)dwX, (int)dwY); set { dwX = (uint)value.X; dwY = (uint)value.Y; dwFlags = dwFlags.SetFlags(STARTF.STARTF_USEPOSITION, value != POINT.Empty); } }
/// <summary>
/// <para>The height of the window if a new window is created, in pixels.</para>

View File

@ -1446,7 +1446,7 @@ namespace Vanara.PInvoke
/// <remarks>The scroll position affects the image in both preview and overlay modes.</remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-capsetscrollpos void capSetScrollPos( hwnd, lpP );
[PInvokeData("vfw.h", MSDNShortId = "NF:vfw.capSetScrollPos")]
public static bool capSetScrollPos(HWND hwnd, System.Drawing.Point lpP) => AVICapSM(hwnd, capMessage.WM_CAP_SET_SCROLL, 0, lpP) != 0;
public static bool capSetScrollPos(HWND hwnd, POINT lpP) => AVICapSM(hwnd, capMessage.WM_CAP_SET_SCROLL, 0, lpP) != 0;
/// <summary>
/// The <c>capSetUserData</c> macro associates a <c>LONG_PTR</c> data value with a capture window. You can use this macro or
@ -1633,7 +1633,7 @@ namespace Vanara.PInvoke
public bool fScale;
/// <summary>The x- and y-offset of the pixel displayed in the upper left corner of the client area of the window.</summary>
public System.Drawing.Point ptScroll;
public POINT ptScroll;
/// <summary>Default palette flag. The value of this member is <c>TRUE</c> if the capture driver is using its default palette.</summary>
[MarshalAs(UnmanagedType.Bool)]

View File

@ -224,7 +224,7 @@ namespace Vanara.PInvoke
public bool fScale;
/// <summary>The x- and y-offset of the pixel displayed in the upper left corner of the client area of the window.</summary>
public System.Drawing.Point ptScroll;
public POINT ptScroll;
/// <summary>Default palette flag. The value of this member is <c>TRUE</c> if the capture driver is using its default palette.</summary>
[MarshalAs(UnmanagedType.Bool)]

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Vanara.InteropServices;
@ -2217,7 +2216,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/ocidl/nf-ocidl-iolecontrolsite-transformcoords HRESULT TransformCoords(
// POINTL *pPtlHimetric, POINTF *pPtfContainer, DWORD dwFlags );
[PreserveSig]
HRESULT TransformCoords(ref Point pPtlHimetric, ref PointF pPtfContainer, XFORMCOORDS dwFlags);
HRESULT TransformCoords(ref POINT pPtlHimetric, ref POINTF pPtfContainer, XFORMCOORDS dwFlags);
/// <summary>Passes a keystroke to the control site for processing.</summary>
/// <param name="pMsg">A pointer to the MSG structure describing the keystroke to be processed.</param>
@ -8711,7 +8710,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/ocidl/nf-ocidl-iviewobjectex-queryhitpoint HRESULT QueryHitPoint( DWORD
// dwAspect, LPCRECT pRectBounds, POINT ptlLoc, LONG lCloseHint, DWORD *pHitResult );
[PreserveSig]
HRESULT QueryHitPoint(DVASPECT2 dwAspect, in RECT pRectBounds, Point ptlLoc, int lCloseHint, out HITRESULT pHitResult);
HRESULT QueryHitPoint(DVASPECT2 dwAspect, in RECT pRectBounds, POINT ptlLoc, int lCloseHint, out HITRESULT pHitResult);
/// <summary>Indicates whether any point in a rectangle is within a given drawing aspect of an object.</summary>
/// <param name="dwAspect">The requested drawing aspect.</param>
@ -9087,6 +9086,23 @@ namespace Vanara.PInvoke
public bool fLicVerified;
}
/// <summary>
/// Contains information that is used to convert between container units, expressed in floating point, and control units, expressed
/// in <c>HIMETRIC</c>. The <c>POINTF</c> structure specifically holds the floating point container units. Controls do not attempt to
/// interpret either value in the structure.
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/api/ocidl/ns-ocidl-pointf typedef struct tagPOINTF { FLOAT x; FLOAT y; } POINTF, *LPPOINTF;
[PInvokeData("ocidl.h", MSDNShortId = "NS:ocidl.tagPOINTF")]
[StructLayout(LayoutKind.Sequential)]
public struct POINTF
{
/// <summary>The x coordinates of the point in units that the container finds convenient.</summary>
public float x;
/// <summary>The y coordinates of the point in units that the container finds convenient.</summary>
public float y;
}
/// <summary>
/// Contains parameters used to describe a property page to a property frame. A property page fills a caller-provided structure in
/// the IPropertyPage::GetPageInfo method.

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
@ -255,7 +254,7 @@ namespace Vanara.PInvoke
// PSPropertyBag_ReadPOINTL( IPropertyBag *propBag, LPCWSTR propName, POINTL *value );
[DllImport(Lib.PropSys, SetLastError = false, ExactSpelling = true)]
[PInvokeData("propsys.h", MSDNShortId = "B8F66DF9-A366-41a7-8311-B9E1CDE14ADB")]
public static extern HRESULT PSPropertyBag_ReadPOINTL(IPropertyBag propBag, [MarshalAs(UnmanagedType.LPWStr)] string propName, out Point value);
public static extern HRESULT PSPropertyBag_ReadPOINTL(IPropertyBag propBag, [MarshalAs(UnmanagedType.LPWStr)] string propName, out POINT value);
/// <summary>
/// <para>Retrieves the property coordinates stored in a POINTS structure of a specified property bag.</para>
@ -816,7 +815,7 @@ namespace Vanara.PInvoke
// PSPropertyBag_WritePOINTL( IPropertyBag *propBag, LPCWSTR propName, const POINTL *value );
[DllImport(Lib.PropSys, SetLastError = false, ExactSpelling = true)]
[PInvokeData("propsys.h", MSDNShortId = "881A9D35-DF77-44d1-86DF-D6BC97AC0DD4")]
public static extern HRESULT PSPropertyBag_WritePOINTL(IPropertyBag propBag, [MarshalAs(UnmanagedType.LPWStr)] string propName, in Point value);
public static extern HRESULT PSPropertyBag_WritePOINTL(IPropertyBag propBag, [MarshalAs(UnmanagedType.LPWStr)] string propName, in POINT value);
/// <summary>
/// <para>Stores the property coordinates in aPOINTS structure of a specified property bag.</para>

View File

@ -5,10 +5,6 @@ using System.Runtime.InteropServices.ComTypes;
using static Vanara.PInvoke.Ole32;
using static Vanara.PInvoke.Opc;
using XPS_POINT = System.Drawing.PointF;
using XPS_RECT = System.Drawing.RectangleF;
using XPS_SIZE = System.Drawing.SizeF;
namespace Vanara.PInvoke
{
public static partial class XpsObjectModel

View File

@ -4,8 +4,6 @@ using System.Runtime.InteropServices;
using Vanara.InteropServices;
using static Vanara.PInvoke.Ole32;
using static Vanara.PInvoke.Opc;
using XPS_RECT = System.Drawing.RectangleF;
using XPS_SIZE = System.Drawing.SizeF;
namespace Vanara.PInvoke
{

View File

@ -6,9 +6,6 @@ using Vanara.InteropServices;
using static Vanara.PInvoke.Opc;
using static Vanara.PInvoke.UrlMon;
using XPS_POINT = System.Drawing.PointF;
using XPS_RECT = System.Drawing.RectangleF;
namespace Vanara.PInvoke
{
/// <summary>Interfaces and supporting enums and structures for XPS programming.</summary>
@ -5116,5 +5113,55 @@ namespace Vanara.PInvoke
[MethodImpl(MethodImplOptions.InternalCall)]
XPS_IMAGE_TYPE GetImageType();
}
/// <summary>Represents an x- and y-coordinate pair in two-dimensional space.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/xpsobjectmodel/ns-xpsobjectmodel-xps_point typedef struct
// __MIDL___MIDL_itf_xpsobjectmodel_0000_0000_0017 { FLOAT x; FLOAT y; } XPS_POINT;
[PInvokeData("xpsobjectmodel.h", MSDNShortId = "NS:xpsobjectmodel.__MIDL___MIDL_itf_xpsobjectmodel_0000_0000_0017")]
[StructLayout(LayoutKind.Sequential)]
public struct XPS_POINT
{
/// <summary>The x-coordinate of a point.</summary>
public float x;
/// <summary>The y-coordinate of a point.</summary>
public float y;
}
/// <summary>Describes the width, height, and location of a rectangle.</summary>
/// <remarks>The measurement units depend on the context and are not specified in the structure.</remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/xpsobjectmodel/ns-xpsobjectmodel-xps_rect typedef struct
// __MIDL___MIDL_itf_xpsobjectmodel_0000_0000_0019 { FLOAT x; FLOAT y; FLOAT width; FLOAT height; } XPS_RECT;
[PInvokeData("xpsobjectmodel.h", MSDNShortId = "NS:xpsobjectmodel.__MIDL___MIDL_itf_xpsobjectmodel_0000_0000_0019")]
[StructLayout(LayoutKind.Sequential)]
public struct XPS_RECT
{
/// <summary>The x-coordinate of the rectangle's left side.</summary>
public float x;
/// <summary>The y-coordinate of the rectangle's top side.</summary>
public float y;
/// <summary>A non-negative value that represents the object's size in the horizontal (x) dimension.</summary>
public float width;
/// <summary>A non-negative value that represents the object's size in the vertical (y) dimension.</summary>
public float height;
}
/// <summary>Describes the size of an object.</summary>
/// <remarks>The measurement units are not specified in the structure.</remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/xpsobjectmodel/ns-xpsobjectmodel-xps_size typedef struct
// __MIDL___MIDL_itf_xpsobjectmodel_0000_0000_0018 { FLOAT width; FLOAT height; } XPS_SIZE;
[PInvokeData("xpsobjectmodel.h", MSDNShortId = "NS:xpsobjectmodel.__MIDL___MIDL_itf_xpsobjectmodel_0000_0000_0018")]
[StructLayout(LayoutKind.Sequential)]
public struct XPS_SIZE
{
/// <summary>A non-negative value that represents the object's size in the horizontal (x) dimension.</summary>
public float width;
/// <summary>A non-negative value that represents the object's size in the vertical (y) dimension.</summary>
public float height;
}
}
}

View File

@ -6,10 +6,6 @@ using Vanara.InteropServices;
using static Vanara.PInvoke.Opc;
using static Vanara.PInvoke.UrlMon;
using XPS_POINT = System.Drawing.PointF;
using XPS_RECT = System.Drawing.RectangleF;
using XPS_SIZE = System.Drawing.SizeF;
namespace Vanara.PInvoke
{
public static partial class XpsObjectModel

View File

@ -1,4 +1,6 @@
using System.Runtime.InteropServices;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
@ -24,6 +26,10 @@ namespace Vanara.PInvoke
[FieldOffset(2)]
public byte B;
/// <summary>The transparency.</summary>
[FieldOffset(3)]
public byte A;
private const uint CLR_NONE = 0xFFFFFFFF;
private const uint CLR_DEFAULT = 0xFF000000;
@ -34,6 +40,7 @@ namespace Vanara.PInvoke
public COLORREF(byte r, byte g, byte b)
{
Value = 0;
A = 0;
R = r;
G = g;
B = b;
@ -46,26 +53,63 @@ namespace Vanara.PInvoke
R = 0;
G = 0;
B = 0;
A = 0;
Value = value & 0x00FFFFFF;
}
/// <summary>Initializes a new instance of the <see cref="COLORREF"/> struct.</summary>
/// <param name="color">The color.</param>
public COLORREF(System.Drawing.Color color) : this(color.R, color.G, color.B)
public COLORREF(Color color) : this(color.R, color.G, color.B)
{
if (color == System.Drawing.Color.Transparent)
if (color == Color.Transparent)
Value = CLR_NONE;
}
/// <summary>Performs an implicit conversion from <see cref="COLORREF"/> to <see cref="System.Drawing.Color"/>.</summary>
/// <summary>A method to darken a color by a percentage of the difference between the color and Black.</summary>
/// <param name="percent">The percentage by which to darken the original color.</param>
/// <returns>
/// The return color's Alpha value will be unchanged, but the RGB content will have been increased by the specified percentage. If
/// percent is 100 then the returned Color will be Black with original Alpha.
/// </returns>
public COLORREF Darken(float percent)
{
if (percent < 0 || percent > 1.0)
throw new ArgumentOutOfRangeException(nameof(percent));
return new(Conv(R), Conv(G), Conv(B)) { Value = Value };
byte Conv(byte c) => (byte)(c - (int)(c * percent));
}
/// <summary>A method to lighten a color by a percentage of the difference between the color and Black.</summary>
/// <param name="percent">The percentage by which to lighten the original color.</param>
/// <returns>
/// The return color's Alpha value will be unchanged, but the RGB content will have been decreased by the specified percentage. If
/// percent is 100 then the returned Color will be White with original Alpha.
/// </returns>
public COLORREF Lighten(float percent)
{
if (percent < 0 || percent > 1.0)
throw new ArgumentOutOfRangeException(nameof(percent));
return new(Conv(R), Conv(G), Conv(B)) { Value = Value };
byte Conv(byte c) => (byte)(c + (int)((255f - c) * percent));
}
/// <summary>Gets the 32-bit ARGB value of this <see cref="COLORREF"/> structure.</summary>
/// <returns>The 32-bit ARGB value of this <see cref="COLORREF"/> structure.</returns>
public int ToArgb() => unchecked((int)Value);
/// <summary>Performs an implicit conversion from <see cref="COLORREF"/> to <see cref="Color"/>.</summary>
/// <param name="cr">The <see cref="COLORREF"/> value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator System.Drawing.Color(COLORREF cr) => cr.Value == CLR_NONE ? System.Drawing.Color.Transparent : System.Drawing.Color.FromArgb(cr.R, cr.G, cr.B);
public static implicit operator Color(COLORREF cr) => cr.Value == CLR_NONE ? Color.Transparent : Color.FromArgb(cr.R, cr.G, cr.B);
/// <summary>Performs an implicit conversion from <see cref="System.Drawing.Color"/> to <see cref="COLORREF"/>.</summary>
/// <param name="clr">The <see cref="System.Drawing.Color"/> value.</param>
/// <summary>Performs an implicit conversion from <see cref="Color"/> to <see cref="COLORREF"/>.</summary>
/// <param name="clr">The <see cref="Color"/> value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator COLORREF(System.Drawing.Color clr) => new(clr);
public static implicit operator COLORREF(Color clr) => new(clr);
/// <summary>Performs an implicit conversion from <see cref="System.ValueTuple{R, G, B}"/> to <see cref="COLORREF"/>.</summary>
/// <param name="clr">The tuple containing the R, G, and B values.</param>
@ -89,6 +133,6 @@ namespace Vanara.PInvoke
public static COLORREF Default = new(0xFF000000);
/// <inheritdoc />
public override string ToString() => ((System.Drawing.Color)this).ToString();
public override string ToString() => ((Color)this).ToString();
}
}

View File

@ -2,6 +2,7 @@
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Drawing;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
@ -69,15 +70,15 @@ namespace Vanara.PInvoke
/// <returns>The <see cref="SIZE"/> that results from the conversion.</returns>
public static explicit operator SIZE(POINT p) => new(p.X, p.Y);
/// <summary>Performs an implicit conversion from <see cref="POINT"/> to <see cref="System.Drawing.Point"/>.</summary>
/// <summary>Performs an implicit conversion from <see cref="POINT"/> to <see cref="Point"/>.</summary>
/// <param name="p">The <see cref="POINT"/>.</param>
/// <returns>The <see cref="System.Drawing.Point"/> result of the conversion.</returns>
public static implicit operator System.Drawing.Point(POINT p) => new(p.X, p.Y);
/// <returns>The <see cref="Point"/> result of the conversion.</returns>
public static implicit operator Point(POINT p) => new(p.X, p.Y);
/// <summary>Performs an implicit conversion from <see cref="System.Drawing.Point"/> to <see cref="POINT"/>.</summary>
/// <param name="p">The <see cref="System.Drawing.Point"/>.</param>
/// <summary>Performs an implicit conversion from <see cref="Point"/> to <see cref="POINT"/>.</summary>
/// <param name="p">The <see cref="Point"/>.</param>
/// <returns>The <see cref="POINT"/> result of the conversion.</returns>
public static implicit operator POINT(System.Drawing.Point p) => new(p.X, p.Y);
public static implicit operator POINT(Point p) => new(p.X, p.Y);
/// <summary>Translates a <see cref="POINT"/> by the negative of a given <see cref="SIZE"/>.</summary>
/// <param name="pt">The <see cref="POINT"/> to translate.</param>
@ -130,7 +131,7 @@ namespace Vanara.PInvoke
public override bool Equals(object obj) => obj switch
{
POINT p => Equals(p),
System.Drawing.Point p => Equals((POINT)p),
Point p => Equals((POINT)p),
_ => false
};

View File

@ -26,10 +26,10 @@ namespace Vanara.PInvoke
/// <summary>The y-coordinate of the upper-left corner of the rectangle.</summary>
public int top;
/// <summary>he x-coordinate of the lower-right corner of the rectangle.</summary>
/// <summary>The x-coordinate of the lower-right corner of the rectangle.</summary>
public int right;
/// <summary>he y-coordinate of the lower-right corner of the rectangle.</summary>
/// <summary>The y-coordinate of the lower-right corner of the rectangle.</summary>
public int bottom;
/// <summary>Initializes a new instance of the <see cref="RECT"/> struct.</summary>
@ -51,6 +51,18 @@ namespace Vanara.PInvoke
{
}
/// <summary>The x-coordinate of the upper-left corner of the rectangle.</summary>
public int Left { get => left; set => left = value; }
/// <summary>The x-coordinate of the lower-right corner of the rectangle.</summary>
public int Right { get => right; set => right = value; }
/// <summary>The y-coordinate of the upper-left corner of the rectangle.</summary>
public int Top { get => top; set => top = value; }
/// <summary>The y-coordinate of the lower-right corner of the rectangle.</summary>
public int Bottom { get => bottom; set => bottom = value; }
/// <summary>Gets or sets the x-coordinate of the upper-left corner of this <see cref="RECT"/> structure.</summary>
/// <value>The x-coordinate of the upper-left corner of this <see cref="RECT"/> structure. The default is 0.</value>
public int X

View File

@ -1,4 +1,5 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -24,10 +25,16 @@ namespace Vanara.PInvoke
cy = height;
}
/// <summary>Specifies the rectangle's height. The units depend on which function uses this.</summary>
public int Height { get => cy; set => cy = value; }
/// <summary>Gets a value indicating whether this instance is empty.</summary>
/// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
public bool IsEmpty => cx == 0 && cy == 0;
/// <summary>Specifies the rectangle's width. The units depend on which function uses this.</summary>
public int Width { get => cx; set => cx = value; }
/// <summary>Tests whether two <see cref="SIZE"/> structures are equal.</summary>
/// <param name="sz1">The <see cref="SIZE"/> structure on the left side of the equality operator.</param>
/// <param name="sz2">The <see cref="SIZE"/> structure on the right side of the equality operator.</param>
@ -51,7 +58,7 @@ namespace Vanara.PInvoke
public override bool Equals(object obj) => obj switch
{
SIZE sz => Equals(sz),
System.Drawing.Size msz => Equals((SIZE)msz),
Size msz => Equals((SIZE)msz),
_ => false
};
@ -59,23 +66,23 @@ namespace Vanara.PInvoke
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
public override int GetHashCode() => IsEmpty ? 0 : cx.GetHashCode() ^ cy.GetHashCode();
/// <summary>Converts this structure to a <see cref="System.Drawing.Size"/> structure.</summary>
/// <returns>An equivalent <see cref="System.Drawing.Size"/> structure.</returns>
public System.Drawing.Size ToSize() => this;
/// <summary>Converts this structure to a <see cref="Size"/> structure.</summary>
/// <returns>An equivalent <see cref="Size"/> structure.</returns>
public Size ToSize() => this;
/// <summary>Returns a <see cref="string"/> that represents this instance.</summary>
/// <returns>A <see cref="string"/> that represents this instance.</returns>
public override string ToString() => $"{{cx={cx}, cy={cy}}}";
/// <summary>Performs an implicit conversion from <see cref="SIZE"/> to <see cref="System.Drawing.Size"/>.</summary>
/// <summary>Performs an implicit conversion from <see cref="SIZE"/> to <see cref="Size"/>.</summary>
/// <param name="s">The <see cref="SIZE"/>.</param>
/// <returns>The <see cref="System.Drawing.Size"/> result of the conversion.</returns>
public static implicit operator System.Drawing.Size(SIZE s) => new(s.cx, s.cy);
/// <returns>The <see cref="Size"/> result of the conversion.</returns>
public static implicit operator Size(SIZE s) => new(s.cx, s.cy);
/// <summary>Performs an implicit conversion from <see cref="System.Drawing.Size"/> to <see cref="SIZE"/>.</summary>
/// <param name="s">The <see cref="System.Drawing.Size"/>.</param>
/// <summary>Performs an implicit conversion from <see cref="Size"/> to <see cref="SIZE"/>.</summary>
/// <param name="s">The <see cref="Size"/>.</param>
/// <returns>The <see cref="SIZE"/> result of the conversion.</returns>
public static implicit operator SIZE(System.Drawing.Size s) => new(s.Width, s.Height);
public static implicit operator SIZE(Size s) => new(s.Width, s.Height);
/// <summary>Represents a SIZE structures whose values are set to zero.</summary>
public static readonly SIZE Empty = new();

View File

@ -1,7 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
@ -193,7 +192,7 @@ namespace Vanara.PInvoke
/// <para>Type: <c>POINT</c></para>
/// <para>The drop point. The coordinates depend on <c>fNC</c>.</para>
/// </summary>
public System.Drawing.Point pt;
public POINT pt;
/// <summary>
/// <para>Type: <c>BOOL</c></para>
@ -284,7 +283,7 @@ namespace Vanara.PInvoke
/// <para>Type: <c>POINTL</c></para>
/// <para>The screen coordinates of the file object.</para>
/// </summary>
public Point pointl;
public POINT pointl;
/// <summary>
/// <para>Type: <c>DWORD</c></para>
@ -440,7 +439,7 @@ namespace Vanara.PInvoke
/// from the upper-left corner of the drag image to the location of the cursor.
/// </para>
/// </summary>
public System.Drawing.Point ptOffset;
public POINT ptOffset;
/// <summary>
/// <para>Type: <c>HBITMAP</c></para>

View File

@ -15,7 +15,7 @@ namespace Vanara.PInvoke
/// <summary/>
[PreserveSig]
HRESULT GetInvokePoint(out System.Drawing.Point value);
HRESULT GetInvokePoint(out POINT value);
/// <summary/>
[PreserveSig]

View File

@ -765,7 +765,7 @@ namespace Vanara.PInvoke
/// The point where the command is invoked. If the fMask member does not specify CMIC_MASK_PTINVOKE, this member is ignored. This
/// member is not valid prior to Internet Explorer 4.0.
/// </summary>
public System.Drawing.Point ptInvoke;
public POINT ptInvoke;
/// <summary>
/// Initializes a new instance of the <see cref="CMINVOKECOMMANDINFOEX"/> struct with a menu-identifier offset of the command to

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -801,7 +800,7 @@ namespace Vanara.PInvoke
/// structure's <c>x</c> member and the minimum height is given in the <c>y</c> member.
/// </para>
/// </summary>
public Size ptMinSize;
public SIZE ptMinSize;
/// <summary>
/// <para>Type: <c>POINTL</c></para>
@ -811,7 +810,7 @@ namespace Vanara.PInvoke
/// should be used.
/// </para>
/// </summary>
public Size ptMaxSize;
public SIZE ptMaxSize;
/// <summary>
/// <para>Type: <c>POINTL</c></para>
@ -821,7 +820,7 @@ namespace Vanara.PInvoke
/// </para>
/// <para>The <c>dwModeFlags</c> member must contain the DBIMF_VARIABLEHEIGHT flag; otherwise, <c>ptIntegral</c> is ignored.</para>
/// </summary>
public Size ptIntegral;
public SIZE ptIntegral;
/// <summary>
/// <para>Type: <c>POINTL</c></para>
@ -831,7 +830,7 @@ namespace Vanara.PInvoke
/// band is not guaranteed to be this size.
/// </para>
/// </summary>
public Size ptActual;
public SIZE ptActual;
/// <summary>
/// <para>Type: <c>WCHAR[256]</c></para>

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
@ -239,7 +238,7 @@ namespace Vanara.PInvoke
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idroptargethelper-dragenter HRESULT
// DragEnter( HWND hwndTarget, IDataObject *pDataObject, POINT *ppt, DWORD dwEffect );
void DragEnter([In] HWND hwndTarget, [In] IDataObject pDataObject, in Point ppt, [In] Ole32.DROPEFFECT dwEffect);
void DragEnter([In] HWND hwndTarget, [In] IDataObject pDataObject, in POINT ppt, [In] Ole32.DROPEFFECT dwEffect);
/// <summary>Notifies the drag-image manager that the drop target's IDropTarget::DragLeave method has been called.</summary>
/// <remarks>
@ -264,7 +263,7 @@ namespace Vanara.PInvoke
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idroptargethelper-dragover HRESULT
// DragOver( POINT *ppt, DWORD dwEffect );
void DragOver(in Point ppt, [In] Ole32.DROPEFFECT dwEffect);
void DragOver(in POINT ppt, [In] Ole32.DROPEFFECT dwEffect);
/// <summary>Notifies the drag-image manager that the drop target's IDropTarget::Drop method has been called.</summary>
/// <param name="pDataObject">
@ -285,7 +284,7 @@ namespace Vanara.PInvoke
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idroptargethelper-drop HRESULT Drop(
// IDataObject *pDataObject, POINT *ppt, DWORD dwEffect );
void Drop([In] IDataObject pDataObject, in Point ppt, Ole32.DROPEFFECT dwEffect);
void Drop([In] IDataObject pDataObject, in POINT ppt, Ole32.DROPEFFECT dwEffect);
/// <summary>Notifies the drag-image manager to show or hide the drag image.</summary>
/// <param name="fShow">

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using static Vanara.PInvoke.OleAut32;
@ -107,7 +106,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-iexecutecommand-setposition HRESULT
// SetPosition( POINT pt );
[PreserveSig]
HRESULT SetPosition(Point pt);
HRESULT SetPosition(POINT pt);
/// <summary>Sets the specified window's visual state.</summary>
/// <param name="nShow">

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using static Vanara.PInvoke.Ole32;
@ -317,20 +316,20 @@ namespace Vanara.PInvoke
/// <summary>Gets the position of an item in the folder's view.</summary>
/// <param name="pidl">A pointer to an ITEMIDLIST interface.</param>
/// <returns>The position of the item's upper-left corner.</returns>
Point GetItemPosition([In] PIDL pidl);
POINT GetItemPosition([In] PIDL pidl);
/// <summary>
/// Gets a POINT structure containing the width (x) and height (y) dimensions, including the surrounding white space, of an item.
/// </summary>
/// <returns>The current sizing dimensions of the items in the folder's view.</returns>
Point GetSpacing();
POINT GetSpacing();
/// <summary>
/// Gets a pointer to a POINT structure containing the default width (x) and height (y) measurements of an item, including the
/// surrounding white space.
/// </summary>
/// <returns>The default sizing dimensions of the items in the folder's view.</returns>
Point GetDefaultSpacing();
POINT GetDefaultSpacing();
/// <summary>Gets the current state of the folder's Auto Arrange mode.</summary>
/// <returns>Returns S_OK if the folder is in Auto Arrange mode; S_FALSE if it is not.</returns>
@ -350,7 +349,7 @@ namespace Vanara.PInvoke
/// name="apidl"/> should be positioned.
/// </param>
/// <param name="dwFlags">One of the _SVSIF constants that specifies the type of selection to apply.</param>
void SelectAndPositionItems([In] uint cidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] apidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] Point[] apt, [In] SVSIF dwFlags);
void SelectAndPositionItems([In] uint cidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] apidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] POINT[] apt, [In] SVSIF dwFlags);
}
/// <summary>
@ -412,20 +411,20 @@ namespace Vanara.PInvoke
/// <summary>Gets the position of an item in the folder's view.</summary>
/// <param name="pidl">A pointer to an ITEMIDLIST interface.</param>
/// <returns>The position of the item's upper-left corner.</returns>
new Point GetItemPosition([In] PIDL pidl);
new POINT GetItemPosition([In] PIDL pidl);
/// <summary>
/// Gets a POINT structure containing the width (x) and height (y) dimensions, including the surrounding white space, of an item.
/// </summary>
/// <returns>The current sizing dimensions of the items in the folder's view.</returns>
new Point GetSpacing();
new POINT GetSpacing();
/// <summary>
/// Gets a pointer to a POINT structure containing the default width (x) and height (y) measurements of an item, including the
/// surrounding white space.
/// </summary>
/// <returns>The default sizing dimensions of the items in the folder's view.</returns>
new Point GetDefaultSpacing();
new POINT GetDefaultSpacing();
/// <summary>Gets the current state of the folder's Auto Arrange mode.</summary>
/// <returns>Returns S_OK if the folder is in Auto Arrange mode; S_FALSE if it is not.</returns>
@ -445,7 +444,7 @@ namespace Vanara.PInvoke
/// name="apidl"/> should be positioned.
/// </param>
/// <param name="dwFlags">One of the _SVSIF constants that specifies the type of selection to apply.</param>
new void SelectAndPositionItems([In] uint cidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] apidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] Point[] apt, [In] SVSIF dwFlags);
new void SelectAndPositionItems([In] uint cidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] apidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] POINT[] apt, [In] SVSIF dwFlags);
/// <summary>Groups the view by the given property key and direction.</summary>
/// <param name="key">

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Vanara.InteropServices;
@ -631,7 +630,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-iusernotificationcallback-onballoonuserclick HRESULT
// OnBalloonUserClick( POINT *pt );
[PreserveSig]
HRESULT OnBalloonUserClick(ref Point pt);
HRESULT OnBalloonUserClick(ref POINT pt);
/// <summary>
/// Called when the user clicks the icon in the notification area. The applications may launch some customary UI in response.
@ -650,7 +649,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-iusernotificationcallback-onleftclick HRESULT
// OnLeftClick( POINT *pt );
[PreserveSig]
HRESULT OnLeftClick(ref Point pt);
HRESULT OnLeftClick(ref POINT pt);
/// <summary>
/// Called when the user right-clicks (or presses SHIFT+F10) the icon in the notification area. The application should show its
@ -671,7 +670,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-iusernotificationcallback-oncontextmenu HRESULT
// OnContextMenu( POINT *pt );
[PreserveSig]
HRESULT OnContextMenu(ref Point pt);
HRESULT OnContextMenu(ref POINT pt);
}
}
}

View File

@ -849,7 +849,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-inamespacetreecontrol-hittest HRESULT
// HitTest( POINT *ppt, IShellItem **ppsiOut );
[PreserveSig]
HRESULT HitTest(in System.Drawing.Point ppt, out IShellItem ppsiOut);
HRESULT HitTest(in POINT ppt, out IShellItem ppsiOut);
/// <summary>Gets the RECT structure that describes the size and position of a given item.</summary>
/// <param name="psi">
@ -1261,7 +1261,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-inamespacetreecontrol-hittest HRESULT
// HitTest( POINT *ppt, IShellItem **ppsiOut );
[PreserveSig]
new HRESULT HitTest(in System.Drawing.Point ppt, out IShellItem ppsiOut);
new HRESULT HitTest(in POINT ppt, out IShellItem ppsiOut);
/// <summary>Gets the RECT structure that describes the size and position of a given item.</summary>
/// <param name="psi">

View File

@ -1552,7 +1552,7 @@ namespace Vanara.PInvoke
/// <param name="pidlItem">A pointer to an ITEMIDLIST structure that uniquely identifies the item of interest.</param>
/// <param name="flags">One of the _SVSIF constants that specify the type of selection to apply.</param>
/// <param name="point">A pointer to a POINT structure containing the new position.</param>
void SelectAndPositionItem(IntPtr pidlItem, SVSIF flags, in System.Drawing.Point point);
void SelectAndPositionItem(IntPtr pidlItem, SVSIF flags, in POINT point);
}
/// <summary>
@ -1793,7 +1793,7 @@ namespace Vanara.PInvoke
/// <param name="pidlItem">A pointer to an ITEMIDLIST structure that uniquely identifies the item of interest.</param>
/// <param name="flags">One of the _SVSIF constants that specify the type of selection to apply.</param>
/// <param name="point">A pointer to a POINT structure containing the new position.</param>
new void SelectAndPositionItem(IntPtr pidlItem, SVSIF flags, in System.Drawing.Point point);
new void SelectAndPositionItem(IntPtr pidlItem, SVSIF flags, in POINT point);
/// <summary>
/// Requests the creation of a new Shell view window. The view can be either the right pane of Windows Explorer or the client

View File

@ -1414,7 +1414,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("shellapi.h", MSDNShortId = "87794ab0-a075-4a1f-869f-5998bdc57a1d")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DragQueryPoint(HDROP hDrop, ref System.Drawing.Point ppt);
public static extern bool DragQueryPoint(HDROP hDrop, ref POINT ppt);
/// <summary>Creates a duplicate of a specified icon.</summary>
/// <param name="hInst">Type: <c>HINSTANCE</c></param>

View File

@ -3,7 +3,6 @@ using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using Vanara.InteropServices;
using POINT = System.Drawing.Point;
using TS_ATTRID = System.Guid;
using TsViewCookie = System.UInt32;

View File

@ -646,7 +646,7 @@ namespace Vanara.PInvoke
/// <summary>Not currently used.</summary>
/// <param name="click">Contains one of the TfLBIClick values that indicate which mouse button was used to click the balloon.</param>
/// <param name="pt">
/// Pointer to a System.Drawing.Point structure that contains the position of the mouse cursor, in screen coordinates, at the
/// Pointer to a Point structure that contains the position of the mouse cursor, in screen coordinates, at the
/// time of the click event.
/// </param>
/// <param name="prcArea">Pointer to a RECT structure that contains the bounding rectangle, in screen coordinates, of the balloon.</param>
@ -668,10 +668,10 @@ namespace Vanara.PInvoke
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/ctfutb/nf-ctfutb-itflangbaritemballoon-onclick HRESULT OnClick( TfLBIClick
// click, System.Drawing.Point pt, const RECT *prcArea );
// click, Point pt, const RECT *prcArea );
[Obsolete("Not currently used.")]
[PreserveSig]
HRESULT OnClick([In] TfLBIClick click, [In] System.Drawing.Point pt, in RECT prcArea);
HRESULT OnClick([In] TfLBIClick click, [In] POINT pt, in RECT prcArea);
/// <summary>Obtains the preferred size,in pixels, of the balloon.</summary>
/// <param name="pszDefault">Pointer to a SIZE structure that contains the default size, in pixels, of the balloon.</param>
@ -875,7 +875,7 @@ namespace Vanara.PInvoke
/// <summary>Not currently used.</summary>
/// <param name="click">Contains one of the TfLBIClick values that indicate which mouse button was used to click the bitmap.</param>
/// <param name="pt">
/// Pointer to a System.Drawing.Point structure that contains the position of the mouse cursor, in screen coordinates, at the
/// Pointer to a Point structure that contains the position of the mouse cursor, in screen coordinates, at the
/// time of the click event.
/// </param>
/// <param name="prcArea">Pointer to a RECT structure that contains the bounding rectangle, in screen coordinates, of the bitmap.</param>
@ -897,10 +897,10 @@ namespace Vanara.PInvoke
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/ctfutb/nf-ctfutb-itflangbaritembitmap-onclick HRESULT OnClick( TfLBIClick
// click, System.Drawing.Point pt, const RECT *prcArea );
// click, Point pt, const RECT *prcArea );
[Obsolete("Not currently used.")]
[PreserveSig]
HRESULT OnClick([In] TfLBIClick click, [In] System.Drawing.Point pt, in RECT prcArea);
HRESULT OnClick([In] TfLBIClick click, [In] POINT pt, in RECT prcArea);
/// <summary>Obtains the preferred size, in pixels, of the bitmap.</summary>
/// <param name="pszDefault">Pointer to a SIZE structure that contains the default size, in pixels, of the bitmap.</param>
@ -1116,7 +1116,7 @@ namespace Vanara.PInvoke
/// <summary>This method is not used if the button item does not have the TF_LBI_STYLE_BTN_BUTTON style.</summary>
/// <param name="click">Contains a TfLBIClick value that indicates which mouse button was used to click the button.</param>
/// <param name="pt">
/// Pointer to a System.Drawing.Point structure that contains the position, in screen coordinates, of the mouse cursor at the
/// Pointer to a Point structure that contains the position, in screen coordinates, of the mouse cursor at the
/// time of the click event.
/// </param>
/// <param name="prcArea">Pointer to a RECT structure that contains the bounding rectangle, in screen coordinates, of the button.</param>
@ -1138,9 +1138,9 @@ namespace Vanara.PInvoke
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/ctfutb/nf-ctfutb-itflangbaritembitmapbutton-onclick HRESULT OnClick(
// TfLBIClick click, System.Drawing.Point pt, const RECT *prcArea );
// TfLBIClick click, Point pt, const RECT *prcArea );
[PreserveSig]
HRESULT OnClick([In] TfLBIClick click, [In] System.Drawing.Point pt, in RECT prcArea);
HRESULT OnClick([In] TfLBIClick click, [In] POINT pt, in RECT prcArea);
/// <summary>This method is not used if the button item does not have the TF_LBI_STYLE_BTN_MENU style.</summary>
/// <param name="pMenu">
@ -1454,7 +1454,7 @@ namespace Vanara.PInvoke
/// <summary>This method is not used if the button item does not have the TF_LBI_STYLE_BTN_BUTTON style.</summary>
/// <param name="click">Contains one of the TfLBIClick values that indicate which mouse button was used to click the button.</param>
/// <param name="pt">
/// Pointer to a System.Drawing.Point structure that contains the position of the mouse cursor, in screen coordinates, at the
/// Pointer to a Point structure that contains the position of the mouse cursor, in screen coordinates, at the
/// time of the click event.
/// </param>
/// <param name="prcArea">Pointer to a RECT structure that contains the bounding rectangle, in screen coordinates, of the button.</param>
@ -1476,9 +1476,9 @@ namespace Vanara.PInvoke
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/ctfutb/nf-ctfutb-itflangbaritembutton-onclick HRESULT OnClick( TfLBIClick
// click, System.Drawing.Point pt, const RECT *prcArea );
// click, Point pt, const RECT *prcArea );
[PreserveSig]
HRESULT OnClick([In] TfLBIClick click, [In] System.Drawing.Point pt, in RECT prcArea);
HRESULT OnClick([In] TfLBIClick click, [In] POINT pt, in RECT prcArea);
/// <summary>This method is not used if the button item does not have the TF_LBI_STYLE_BTN_MENU style.</summary>
/// <param name="pMenu">

View File

@ -3407,7 +3407,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextowner-getacpfrompoint HRESULT GetACPFromPoint(
// const POINT *ptScreen, DWORD dwFlags, LONG *pacp );
[PreserveSig]
HRESULT GetACPFromPoint(in System.Drawing.Point ptScreen, GXFPF dwFlags, out int pacp);
HRESULT GetACPFromPoint(in POINT ptScreen, GXFPF dwFlags, out int pacp);
/// <summary>
/// The <c>ITfContextOwner::GetTextExt</c> method returns the bounding box, in screen coordinates, of the text at a specified

View File

@ -195,7 +195,7 @@ namespace Vanara.PInvoke
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextview-getrangefrompoint HRESULT GetRangeFromPoint(
// TfEditCookie ec, const POINT *ppt, DWORD dwFlags, ITfRange **ppRange );
ITfRange GetRangeFromPoint([In] TfEditCookie ec, in System.Drawing.Point ppt, GXFPF dwFlags);
ITfRange GetRangeFromPoint([In] TfEditCookie ec, in POINT ppt, GXFPF dwFlags);
/// <summary>
/// The <c>ITfContextView::GetTextExt</c> method returns the bounding box, in screen coordinates, of a range of text.

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using static Vanara.PInvoke.Gdi32;
@ -43,12 +42,6 @@ namespace Vanara.PInvoke
/// </summary>
public HBITMAP hbmColor;
/// <summary>Gets the color bitmap associated with the icon.</summary>
public Bitmap Bitmap => Image.FromHbitmap((IntPtr)hbmColor);
/// <summary>Gets the AND bitmap mask associated with the icon.</summary>
public Bitmap Mask => Image.FromHbitmap((IntPtr)hbmMask);
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
void IDisposable.Dispose()
{

View File

@ -30,9 +30,6 @@ ACCEL ACCESSTIMEOUT ALTTABINFO ANIMATIONINFO AUDIODESCRIPTION BSMINFO CBTACTIVAT
<ProjectReference Include="..\Kernel32\Vanara.PInvoke.Kernel32.csproj" />
<ProjectReference Include="..\Gdi32\Vanara.PInvoke.Gdi32.csproj" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) Or $(TargetFramework.StartsWith('netcore')) ">
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Extensions\" />
</ItemGroup>

View File

@ -1,4 +1,3 @@
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -126,7 +125,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCaretPos(out Point lpPoint);
public static extern bool GetCaretPos(out POINT lpPoint);
/// <summary>
/// Removes the caret from the screen. Hiding a caret does not destroy its current shape or invalidate the insertion point.

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -57,7 +56,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "3b1e2699-7f5f-444d-9072-f2ca7c8fa511")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ClientToScreen(HWND hWnd, ref Point lpPoint);
public static extern bool ClientToScreen(HWND hWnd, ref POINT lpPoint);
/// <summary>Retrieves the screen auto-rotation preferences for the current process.</summary>
/// <param name="pOrientation">
@ -133,7 +132,7 @@ namespace Vanara.PInvoke
/// </returns>
[PInvokeData("WinUser.h", MSDNShortId = "")]
[DllImport(Lib.User32, ExactSpelling = true, SetLastError = true)]
public static extern int MapWindowPoints(HWND hWndFrom, HWND hWndTo, ref Point lpPoints, uint cPoints = 1);
public static extern int MapWindowPoints(HWND hWndFrom, HWND hWndTo, ref POINT lpPoints, uint cPoints = 1);
/// <summary>
/// The MapWindowPoints function converts (maps) a set of points from a coordinate space relative to one window to a coordinate space
@ -165,7 +164,7 @@ namespace Vanara.PInvoke
/// </returns>
[PInvokeData("WinUser.h", MSDNShortId = "")]
[DllImport(Lib.User32, ExactSpelling = true, SetLastError = true)]
public static extern int MapWindowPoints(HWND hWndFrom, HWND hWndTo, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] Point[] lpPoints, [MarshalAs(UnmanagedType.U4)] int cPoints);
public static extern int MapWindowPoints(HWND hWndFrom, HWND hWndTo, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] POINT[] lpPoints, [MarshalAs(UnmanagedType.U4)] int cPoints);
/// <summary>The ScreenToClient function converts the screen coordinates of a specified point on the screen to client-area coordinates.</summary>
/// <param name="hWnd">A handle to the window whose client area will be used for the conversion.</param>
@ -177,7 +176,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, ExactSpelling = true, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
[System.Security.SecurityCritical]
public static extern bool ScreenToClient(HWND hWnd, [In, Out] ref Point lpPoint);
public static extern bool ScreenToClient(HWND hWnd, [In, Out] ref POINT lpPoint);
/// <summary>Sets the orientation preferences of the display.</summary>
/// <param name="orientation">The orientation.</param>

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -220,7 +219,7 @@ namespace Vanara.PInvoke
/// <para>The return value is a safe handle to the newly created image.</para>
/// </returns>
[PInvokeData("winuser.h")]
public static SafeHCURSOR CopyCursor(HCURSOR h, Size desiredSize = default, CopyImageOptions options = 0)
public static SafeHCURSOR CopyCursor(HCURSOR h, SIZE desiredSize = default, CopyImageOptions options = 0)
{
var hret = CopyImage(h.DangerousGetHandle(), LoadImageType.IMAGE_CURSOR, desiredSize.Width, desiredSize.Height, options);
if (hret == HANDLE.NULL) Win32Error.ThrowLastError();
@ -416,7 +415,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getcursorpos")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorPos(out System.Drawing.Point lpPoint);
public static extern bool GetCursorPos(out POINT lpPoint);
/// <summary>
/// <para>Retrieves the position of the cursor in physical coordinates.</para>
@ -438,7 +437,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getphysicalcursorpos")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPhysicalCursorPos(out System.Drawing.Point lpPoint);
public static extern bool GetPhysicalCursorPos(out POINT lpPoint);
/// <summary>
/// <para>Loads the specified cursor resource from the executable (.EXE) file associated with an application instance.</para>
@ -980,7 +979,7 @@ namespace Vanara.PInvoke
/// <para>Type: <c>POINT</c></para>
/// <para>A structure that receives the screen coordinates of the cursor.</para>
/// </summary>
public System.Drawing.Point ptScreenPos;
public POINT ptScreenPos;
}
/// <summary>Provides a <see cref="SafeHandle"/> to a Windows that disposes a created HCURSOR instance at disposal using DestroyCursor.</summary>

View File

@ -1,6 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.InteropServices;
@ -2357,10 +2356,10 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-gettabbedtextextenta DWORD GetTabbedTextExtentA( HDC hdc,
// LPCSTR lpString, int chCount, int nTabPositions, const INT *lpnTabStopPositions );
[PInvokeData("winuser.h", MSDNShortId = "3444bb8d-4a30-47d4-b211-01f7cba39975")]
public static Size GetTabbedTextExtent(HDC hdc, string lpString, int[] lpnTabStopPositions)
public static SIZE GetTabbedTextExtent(HDC hdc, string lpString, int[] lpnTabStopPositions)
{
var ret = GetTabbedTextExtent(hdc, lpString, lpString?.Length ?? 0, lpnTabStopPositions?.Length ?? 0, lpnTabStopPositions);
return new Size(Macros.LOWORD(ret), Macros.HIWORD(ret));
return new SIZE(Macros.LOWORD(ret), Macros.HIWORD(ret));
}
/// <summary>The <c>GetUserObjectSecurity</c> function retrieves security information for the specified user object.</summary>
@ -2990,32 +2989,32 @@ namespace Vanara.PInvoke
public struct MINMAXINFO
{
/// <summary>Reserved; do not use.</summary>
public Point reserved;
public POINT reserved;
/// <summary>
/// The maximized width (x member) and the maximized height (y member) of the window. For top-level windows, this value is based
/// on the width of the primary monitor.
/// </summary>
public Size maxSize;
public SIZE maxSize;
/// <summary>
/// The position of the left side of the maximized window (x member) and the position of the top of the maximized window (y
/// member). For top-level windows, this value is based on the position of the primary monitor.
/// </summary>
public Point maxPosition;
public POINT maxPosition;
/// <summary>
/// The minimum tracking width (x member) and the minimum tracking height (y member) of the window. This value can be obtained
/// programmatically from the system metrics SM_CXMINTRACK and SM_CYMINTRACK (see the GetSystemMetrics function).
/// </summary>
public Size minTrackSize;
public SIZE minTrackSize;
/// <summary>
/// The maximum tracking width (x member) and the maximum tracking height (y member) of the window. This value is based on the
/// size of the virtual screen and can be obtained programmatically from the system metrics SM_CXMAXTRACK and SM_CYMAXTRACK (see
/// the GetSystemMetrics function).
/// </summary>
public Size maxTrackSize;
public SIZE maxTrackSize;
}
/// <summary>Contains information about the size and position of a window.</summary>

View File

@ -469,7 +469,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "C9ABDC73-1E96-42F1-B34D-3A649DDF02A6")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool LogicalToPhysicalPointForPerMonitorDPI(HWND hWnd, ref System.Drawing.Point lpPoint);
public static extern bool LogicalToPhysicalPointForPerMonitorDPI(HWND hWnd, ref POINT lpPoint);
/// <summary>
/// Converts a point in a window from logical coordinates into physical coordinates, regardless of the dots per inch (dpi) awareness
@ -515,7 +515,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "DC744BFC-4410-4878-BEA7-382550DDF9E3")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PhysicalToLogicalPointForPerMonitorDPI(HWND hWnd, ref System.Drawing.Point lpPoint);
public static extern bool PhysicalToLogicalPointForPerMonitorDPI(HWND hWnd, ref POINT lpPoint);
/// <summary>Overrides the default per-monitor DPI scaling behavior of a child window in a dialog.</summary>
/// <param name="hWnd">A handle for the window whose behavior will be modified.</param>

View File

@ -1268,7 +1268,7 @@ namespace Vanara.PInvoke
/// <para>Type: <c>POINT</c></para>
/// <para>The x- and y-coordinates of the cursor, in screen coordinates.</para>
/// </summary>
public System.Drawing.Point pt;
public POINT pt;
/// <summary>
/// <para>Type: <c>HWND</c></para>
@ -1305,7 +1305,7 @@ namespace Vanara.PInvoke
/// <para>Type: <c>POINT</c></para>
/// <para>The x- and y-coordinates of the cursor, in screen coordinates.</para>
/// </summary>
public System.Drawing.Point pt;
public POINT pt;
/// <summary>
/// <para>Type: <c>HWND</c></para>
@ -1368,7 +1368,7 @@ namespace Vanara.PInvoke
/// <para>Type: <c>POINT</c></para>
/// <para>The x- and y-coordinates of the cursor, in per-monitor-aware screen coordinates.</para>
/// </summary>
public System.Drawing.Point pt;
public POINT pt;
/// <summary>
/// <para>Type: <c>DWORD</c></para>

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using static Vanara.PInvoke.Gdi32;
using static Vanara.PInvoke.Kernel32;
@ -151,7 +150,7 @@ namespace Vanara.PInvoke
/// <returns>
/// <para>The return value is a safe handle to the newly created image.</para>
/// </returns>
public static SafeHICON CopyIcon(HICON h, Size desiredSize = default, CopyImageOptions options = 0)
public static SafeHICON CopyIcon(HICON h, SIZE desiredSize = default, CopyImageOptions options = 0)
{
var hret = CopyImage(h.DangerousGetHandle(), LoadImageType.IMAGE_ICON, desiredSize.Width, desiredSize.Height, options);
if (hret == HANDLE.NULL) Win32Error.ThrowLastError();
@ -851,6 +850,26 @@ namespace Vanara.PInvoke
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetIconInfoEx(HICON hicon, ref ICONINFOEX piconinfo);
/// <summary>Gets the size of an icon from its handle.</summary>
/// <param name="hIcon">The icon handle.</param>
/// <returns>The size of the icon in pixels.</returns>
public static SIZE GetSize(this HICON hIcon)
{
using ICONINFO info = new();
Win32Error.ThrowLastErrorIfFalse(GetIconInfo(hIcon, info));
if (!info.hbmColor.IsNull)
{
var bmp = GetObject<BITMAP>(info.hbmColor);
return new(bmp.bmWidth, bmp.bmHeight);
}
if (!info.hbmMask.IsNull)
{
var bmp = GetObject<BITMAP>(info.hbmMask);
return new(bmp.bmWidth, bmp.bmHeight / 2);
}
return SIZE.Empty;
}
/// <summary>
/// <para>Loads the specified icon resource from the executable (.exe) file associated with an application instance.</para>
/// <para><c>Note</c> This function has been superseded by the LoadImage function.</para>
@ -1238,10 +1257,6 @@ namespace Vanara.PInvoke
public static extern uint PrivateExtractIcons(string szFileName, int nIconIndex, int cxIcon, int cyIcon,
[In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 6)] SafeHICON[] phicon, out uint piconid, uint nIcons, LoadImageOptions flags);
/// <summary>Creates a managed <see cref="System.Drawing.Bitmap"/> from this HICON instance.</summary>
/// <returns>A managed bitmap instance.</returns>
public static Bitmap ToBitmap(this HICON hIcon) => hIcon.IsNull ? null : (Bitmap)Bitmap.FromHicon((IntPtr)hIcon).Clone();
#if WPF && !NET20 && !NETSTANDARD2_0 && !NETCOREAPP2_0 && !NETCOREAPP2_1
/// <summary>Creates a <see cref="System.Windows.Media.Imaging.BitmapSource"/> from an <see cref="HICON"/>.</summary>
/// <param name="hIcon">The HICON value.</param>
@ -1272,10 +1287,6 @@ namespace Vanara.PInvoke
return new SafeHBITMAP((IntPtr)CopyImage((IntPtr)icoInfo.hbmColor, LoadImageType.IMAGE_BITMAP, 0, 0, CopyImageOptions.LR_CREATEDIBSECTION), true);
}
/// <summary>Creates a managed <see cref="System.Drawing.Icon"/> from this HICON instance.</summary>
/// <returns>A managed icon instance.</returns>
public static Icon ToIcon(this HICON hIcon) => hIcon.IsNull ? null : (Icon)Icon.FromHandle((IntPtr)hIcon).Clone();
/// <summary>
/// <para>Contains information about an icon or a cursor. Extends ICONINFO. Used by GetIconInfoEx.</para>
/// </summary>
@ -1372,15 +1383,14 @@ namespace Vanara.PInvoke
{
}
/// <summary>Gets the size of this icon in pixels.</summary>
public SIZE Size => GetSize(handle);
/// <summary>Performs an implicit conversion from <see cref="SafeHICON"/> to <see cref="HICON"/>.</summary>
/// <param name="h">The safe handle instance.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator HICON(SafeHICON h) => h.handle;
/// <summary>Creates a managed <see cref="System.Drawing.Bitmap"/>.</summary>
/// <returns>A managed bitmap instance.</returns>
public Bitmap ToBitmap() => ((HICON)this).ToBitmap();
#if WPF && !NET20 && !NETSTANDARD2_0 && !NETCOREAPP2_0 && !NETCOREAPP2_1
/// <summary>Creates a <see cref="System.Windows.Media.Imaging.BitmapSource"/> from an <see cref="SafeHICON"/>.</summary>
/// <returns>The BitmapSource instance. If this is a <c>NULL</c> handle, <see langword="null"/> is returned.</returns>
@ -1391,10 +1401,6 @@ namespace Vanara.PInvoke
/// <returns>A bitmap handle.</returns>
public SafeHBITMAP ToHBITMAP() => ((HICON)this).ToHBITMAP();
/// <summary>Creates a managed <see cref="System.Drawing.Icon"/>.</summary>
/// <returns>A managed icon instance.</returns>
public Icon ToIcon() => ((HICON)this).ToIcon();
/// <inheritdoc/>
protected override bool InternalReleaseHandle() => DestroyIcon(this);
}

View File

@ -2237,7 +2237,7 @@ namespace Vanara.PInvoke
// hMenu, POINT ptScreen );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "menuitemfrompoint.htm")]
public static extern int MenuItemFromPoint(HWND hWnd, HMENU hMenu, System.Drawing.Point ptScreen);
public static extern int MenuItemFromPoint(HWND hWnd, HMENU hMenu, POINT ptScreen);
/// <summary>
/// <para>Changes an existing menu item. This function is used to specify the content, appearance, and behavior of the menu item.</para>

View File

@ -597,7 +597,7 @@ namespace Vanara.PInvoke
// DWORD dwFlags );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "c46281bf-7e45-4628-be92-736850225a9e")]
public static extern HMONITOR MonitorFromPoint(System.Drawing.Point pt, MonitorFlags dwFlags);
public static extern HMONITOR MonitorFromPoint(POINT pt, MonitorFlags dwFlags);
/// <summary>
/// <para>

View File

@ -2008,7 +2008,7 @@ namespace Vanara.PInvoke
/// the non-predicted value (see <c>ptPixelLocationRaw</c>).
/// </para>
/// </summary>
public System.Drawing.Point ptPixelLocation;
public POINT ptPixelLocation;
/// <summary>
/// <para>Type: <c>POINT</c></para>
@ -2020,19 +2020,19 @@ namespace Vanara.PInvoke
/// the non-predicted value (see <c>ptHimetricLocationRaw</c>).
/// </para>
/// </summary>
public System.Drawing.Point ptHimetricLocation;
public POINT ptHimetricLocation;
/// <summary>
/// <para>Type: <c>POINT</c></para>
/// <para>The screen coordinates of the pointer, in pixels. For adjusted screen coordinates, see <c>ptPixelLocation</c>.</para>
/// </summary>
public System.Drawing.Point ptPixelLocationRaw;
public POINT ptPixelLocationRaw;
/// <summary>
/// <para>Type: <c>POINT</c></para>
/// <para>The screen coordinates of the pointer, in HIMETRIC units. For adjusted screen coordinates, see <c>ptHimetricLocation</c>.</para>
/// </summary>
public System.Drawing.Point ptHimetricLocationRaw;
public POINT ptHimetricLocationRaw;
/// <summary>
/// <para>Type: <c>DWORD</c></para>

View File

@ -1,4 +1,3 @@
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
@ -208,7 +207,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "8a47a238-082c-44b8-a270-5ebb4d3d9fc8")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PtInRect(in RECT lprc, Point pt);
public static extern bool PtInRect(in RECT lprc, POINT pt);
/// <summary>
/// The <c>SetRect</c> function sets the coordinates of the specified rectangle. This is equivalent to assigning the left, top,

View File

@ -4575,7 +4575,7 @@ namespace Vanara.PInvoke
/// The POINT structure that contains the screen coordinates of the mouse cursor. This is useful for providing Help based on the
/// position of the mouse cursor.
/// </summary>
public System.Drawing.Point MousePos;
public POINT MousePos;
}
/// <summary>

View File

@ -289,7 +289,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "443d12f2-9f26-4e1e-9bf3-cd97b4026399")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EvaluateProximityToPolygon(uint numVertices, [In] System.Drawing.Point[] controlPolygon, in TOUCH_HIT_TESTING_INPUT pHitTestingInput, out TOUCH_HIT_TESTING_PROXIMITY_EVALUATION pProximityEval);
public static extern bool EvaluateProximityToPolygon(uint numVertices, [In] POINT[] controlPolygon, in TOUCH_HIT_TESTING_INPUT pHitTestingInput, out TOUCH_HIT_TESTING_PROXIMITY_EVALUATION pProximityEval);
/// <summary>
/// Returns the score of a rectangle as the probable touch target, compared to all other rectangles that intersect the touch contact
@ -1437,7 +1437,7 @@ namespace Vanara.PInvoke
public uint pointerId;
/// <summary>The screen coordinates of the touch point that the touch digitizer reports.</summary>
public System.Drawing.Point point;
public POINT point;
/// <summary>
/// <para>
@ -1472,7 +1472,7 @@ namespace Vanara.PInvoke
public ushort score;
/// <summary>The adjusted touch point that hits the closest object that's identified by the value of Score.</summary>
public System.Drawing.Point adjustedPoint;
public POINT adjustedPoint;
}
/// <summary>Encapsulates data for touch input.</summary>

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
@ -947,7 +946,7 @@ namespace Vanara.PInvoke
TPM_WORKAREA = 0x10000,
}
/// <summary>Flags for <see cref="UpdateLayeredWindow(HWND, HDC, in Point, in SIZE, HDC, in Point, COLORREF, in Gdi32.BLENDFUNCTION, UpdateLayeredWindowFlags)"/></summary>
/// <summary>Flags for <see cref="UpdateLayeredWindow(HWND, HDC, in POINT, in SIZE, HDC, in POINT, COLORREF, in Gdi32.BLENDFUNCTION, UpdateLayeredWindowFlags)"/></summary>
[PInvokeData("winuser.h", MSDNShortId = "updatelayeredwindow")]
[Flags]
public enum UpdateLayeredWindowFlags
@ -1621,7 +1620,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "calculatepopupwindowposition")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CalculatePopupWindowPosition(in Point anchorPoint, in SIZE windowSize, TrackPopupMenuFlags flags, [Optional] PRECT excludeRect, out RECT popupWindowPosition);
public static extern bool CalculatePopupWindowPosition(in POINT anchorPoint, in SIZE windowSize, TrackPopupMenuFlags flags, [Optional] PRECT excludeRect, out RECT popupWindowPosition);
/// <summary>Passes message information to the specified window procedure.</summary>
/// <param name="lpPrevWndFunc">
@ -1942,7 +1941,7 @@ namespace Vanara.PInvoke
// hWndParent, POINT Point );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "childwindowfrompoint")]
public static extern HWND ChildWindowFromPoint(HWND hWndParent, Point Point);
public static extern HWND ChildWindowFromPoint(HWND hWndParent, POINT Point);
/// <summary>
/// <para>
@ -2004,7 +2003,7 @@ namespace Vanara.PInvoke
// hwnd, POINT pt, UINT flags );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "childwindowfrompointex")]
public static extern HWND ChildWindowFromPointEx(HWND hwnd, Point pt, ChildWindowSkipOptions flags);
public static extern HWND ChildWindowFromPointEx(HWND hwnd, POINT pt, ChildWindowSkipOptions flags);
/// <summary>
/// <para>Minimizes (but does not destroy) the specified window.</para>
@ -3163,7 +3162,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DragDetect(HWND hwnd, System.Drawing.Point pt);
public static extern bool DragDetect(HWND hwnd, POINT pt);
/// <summary>
/// Enables or disables mouse and keyboard input to the specified window or control. When input is disabled, the window does not
@ -5392,7 +5391,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "logicaltophysicalpoint")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool LogicalToPhysicalPoint(HWND hWnd, ref Point lpPoint);
public static extern bool LogicalToPhysicalPoint(HWND hWnd, ref POINT lpPoint);
/// <summary>
/// <para>
@ -5587,7 +5586,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "physicaltologicalpoint")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PhysicalToLogicalPoint(HWND hWnd, ref Point lpPoint);
public static extern bool PhysicalToLogicalPoint(HWND hWnd, ref POINT lpPoint);
/// <summary>
/// The <c>PrintWindow</c> function copies a visual window into the specified device context (DC), typically a printer DC.
@ -5662,7 +5661,7 @@ namespace Vanara.PInvoke
// HWND hwndParent, POINT ptParentClientCoords );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "realchildwindowfrompoint")]
public static extern HWND RealChildWindowFromPoint(HWND hwndParent, Point ptParentClientCoords);
public static extern HWND RealChildWindowFromPoint(HWND hwndParent, POINT ptParentClientCoords);
/// <summary>
/// <para>Retrieves a string that specifies the window type.</para>
@ -7314,7 +7313,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "updatelayeredwindow")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UpdateLayeredWindow(HWND hWnd, HDC hdcDst, in Point pptDst, in SIZE psize, HDC hdcSrc, in Point pptSrc, COLORREF crKey, in Gdi32.BLENDFUNCTION pblend, UpdateLayeredWindowFlags dwFlags);
public static extern bool UpdateLayeredWindow(HWND hWnd, HDC hdcDst, in POINT pptDst, in SIZE psize, HDC hdcSrc, in POINT pptSrc, COLORREF crKey, in Gdi32.BLENDFUNCTION pblend, UpdateLayeredWindowFlags dwFlags);
/// <summary>
/// <para>Updates the position, size, shape, content, and translucency of a layered window.</para>
@ -7487,7 +7486,7 @@ namespace Vanara.PInvoke
// POINT Point );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "windowfromphysicalpoint")]
public static extern HWND WindowFromPhysicalPoint(Point Point);
public static extern HWND WindowFromPhysicalPoint(POINT Point);
/// <summary>
/// <para>Retrieves a handle to the window that contains the specified point.</para>
@ -7514,7 +7513,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-windowfrompoint HWND WindowFromPoint( POINT Point );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "windowfrompoint")]
public static extern HWND WindowFromPoint(Point Point);
public static extern HWND WindowFromPoint(POINT Point);
/// <summary>
/// <para>
@ -8011,7 +8010,7 @@ namespace Vanara.PInvoke
/// <para>Type: <c>POINT</c></para>
/// <para>The top-left corner of the first icon.</para>
/// </summary>
public Point ptStart;
public POINT ptStart;
}
/// <summary>
@ -8848,13 +8847,13 @@ namespace Vanara.PInvoke
/// <para>Type: <c>POINT</c></para>
/// <para>The coordinates of the window's upper-left corner when the window is minimized.</para>
/// </summary>
public Point ptMinPosition;
public POINT ptMinPosition;
/// <summary>
/// <para>Type: <c>POINT</c></para>
/// <para>The coordinates of the window's upper-left corner when the window is maximized.</para>
/// </summary>
public Point ptMaxPosition;
public POINT ptMaxPosition;
/// <summary>
/// <para>Type: <c>RECT</c></para>

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.Extensions;
@ -1981,7 +1980,7 @@ namespace Vanara.PInvoke
// HRESULT GetThemePosition( _In_ HTHEME hTheme, _In_ int iPartId, _In_ int iStateId, _In_ int iPropId, _Out_ POINT *pPoint); https://msdn.microsoft.com/en-us/library/windows/desktop/bb759762(v=vs.85).aspx
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb759762")]
public static extern HRESULT GetThemePosition(HTHEME hTheme, int iPartId, int iStateId, int iPropId, out Point pPoint);
public static extern HRESULT GetThemePosition(HTHEME hTheme, int iPartId, int iStateId, int iPropId, out POINT pPoint);
/// <summary>Retrieves the location of the theme property definition for a property.</summary>
/// <param name="hTheme">Handle to a window's specified theme data. Use OpenThemeData to create an HTHEME.</param>
@ -2640,7 +2639,7 @@ namespace Vanara.PInvoke
// LPCRECT pRect, _In_ HRGN hrgn, _In_ POINT ptTest, _Out_ WORD *pwHitTestCode); https://msdn.microsoft.com/en-us/library/windows/desktop/bb759808(v=vs.85).aspx
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb759808")]
public static extern HRESULT HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, HitTestOptions dwOptions, in RECT pRect, HRGN hrgn, Point ptTest, out HitTestValues pwHitTestCode);
public static extern HRESULT HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, HitTestOptions dwOptions, in RECT pRect, HRGN hrgn, POINT ptTest, out HitTestValues pwHitTestCode);
/// <summary>Reports whether the current application's user interface displays using visual styles.</summary>
/// <returns>
@ -3185,7 +3184,7 @@ namespace Vanara.PInvoke
/// <para>Type: <c><c>POINT</c></c></para>
/// <para>Specifies the amount of offset, in logical coordinates, between the shadow and the text.</para>
/// </summary>
public Point ptShadowOffset;
public POINT ptShadowOffset;
/// <summary>
/// <para>Type: <c>int</c></para>
@ -3301,7 +3300,7 @@ namespace Vanara.PInvoke
/// <summary>Gets or sets the color of the outline that will be drawn around the text.</summary>
/// <value>The color of the border.</value>
public Color BorderColor
public COLORREF BorderColor
{
get => crBorder;
set
@ -3369,7 +3368,7 @@ namespace Vanara.PInvoke
/// <summary>Gets or sets the color of the shadow drawn behind the text.</summary>
/// <value>The color of the shadow.</value>
public Color ShadowColor
public COLORREF ShadowColor
{
get => crShadow;
set
@ -3381,9 +3380,9 @@ namespace Vanara.PInvoke
/// <summary>Gets or sets the amount of offset, in logical coordinates, between the shadow and the text.</summary>
/// <value>The shadow offset.</value>
public Point ShadowOffset
public POINT ShadowOffset
{
get => new Point(ptShadowOffset.X, ptShadowOffset.Y);
get => new POINT(ptShadowOffset.X, ptShadowOffset.Y);
set
{
ptShadowOffset = value;
@ -3404,7 +3403,7 @@ namespace Vanara.PInvoke
/// <summary>Gets or sets the color of the text that will be drawn.</summary>
/// <value>The color of the text.</value>
public Color TextColor
public COLORREF TextColor
{
get => crText;
set
@ -3600,7 +3599,7 @@ namespace Vanara.PInvoke
/// <summary>Initializes a new instance of the <see cref="DTBGOPTS"/> class.</summary>
/// <param name="clipRect">The rectangle to which drawing is clipped.</param>
public DTBGOPTS(Rectangle? clipRect)
public DTBGOPTS(RECT? clipRect)
{
dwSize = (uint)Marshal.SizeOf(this);
ClipRectangle = clipRect;
@ -3608,12 +3607,12 @@ namespace Vanara.PInvoke
/// <summary>Gets or sets the bounding rectangle of the clip region.</summary>
/// <value>The clip rectangle.</value>
public Rectangle? ClipRectangle
public RECT? ClipRectangle
{
get
{
Rectangle r = rcClip;
return r.IsEmpty ? (Rectangle?)null : r;
RECT r = rcClip;
return r.IsEmpty ? (RECT?)null : r;
}
set
{
@ -3638,10 +3637,10 @@ namespace Vanara.PInvoke
/// <value><c>true</c> if not mirroring; otherwise, <c>false</c>.</value>
public bool DoNotMirror { get => dwFlags.IsFlagSet(DrawThemeBackgroundFlags.DTBG_NOMIRROR); set => SetFlag(DrawThemeBackgroundFlags.DTBG_NOMIRROR, value); }
/// <summary>Performs an implicit conversion from <see cref="System.Drawing.Rectangle"/> to <see cref="DTBGOPTS"/>.</summary>
/// <summary>Performs an implicit conversion from <see cref="RECT"/> to <see cref="DTBGOPTS"/>.</summary>
/// <param name="clipRectangle">The clipping rectangle.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator DTBGOPTS(Rectangle clipRectangle) => new DTBGOPTS(clipRectangle);
public static implicit operator DTBGOPTS(RECT clipRectangle) => new DTBGOPTS(clipRectangle);
private void SetFlag(DrawThemeBackgroundFlags f, bool value) => dwFlags = dwFlags.SetFlags(f, value);
}

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
@ -547,9 +546,9 @@ namespace Vanara.PInvoke
/// <summary>Gets or sets the rectangle that is excluded from the clipping region.</summary>
/// <value>The rectangle.</value>
public Rectangle? Exclude
public RECT? Exclude
{
get => prcExclude.ToNullableStructure<Rectangle>();
get => prcExclude.ToNullableStructure<RECT>();
set
{
if (prcExclude != IntPtr.Zero) Marshal.FreeCoTaskMem(prcExclude);

View File

@ -1,5 +1,4 @@
using System;
using System.Drawing;
using Vanara.InteropServices;
namespace Vanara.PInvoke
@ -869,47 +868,47 @@ namespace Vanara.PInvoke
TMT_CLASSICVALUE = 3202,
/// <summary>The position offset from the alignment for this part. The alignment is defined by the TMT_OFFSETTYPE value.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_OFFSET = 3401,
/// <summary>The offset from the text at which text shadows are drawn.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_TEXTSHADOWOFFSET = 3402,
/// <summary>The minimum size that the normal image file can be used for before moving to the next smallest image file.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_MINSIZE = 3403,
/// <summary>The minimum size that the first small image file can be used for.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_MINSIZE1 = 3404,
/// <summary>The minimum size that the second small image file can be used for.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_MINSIZE2 = 3405,
/// <summary>The minimum size that the third small image file can be used for.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_MINSIZE3 = 3406,
/// <summary>The minimum size that the fourth small image file can be used for.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_MINSIZE4 = 3407,
/// <summary>The minimum size that the fifth small image file can be used for.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_MINSIZE5 = 3408,
/// <summary>The size of the normal image associated with this part.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_NORMALSIZE = 3409,
/// <summary>The minimum size that the sixth small image file can be used for.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_MINSIZE6 = 3410,
/// <summary>The minimum size that the seventh small image file can be used for.</summary>
[CorrespondingType(typeof(Point))]
[CorrespondingType(typeof(POINT))]
TMT_MINSIZE7 = 3411,
/// <summary>The margins used for sizing a non-true-size image.</summary>

View File

@ -2446,7 +2446,7 @@ namespace Vanara.PInvoke
/// eye in the camera frame. If the iris-recognition system is monitoring both eyes, and both eyes are in the camera
/// frame, this position is probably of the center of the pupil of the right eye of the individual.
/// </summary>
public System.Drawing.Point PupilCenter_1;
public POINT PupilCenter_1;
/// <summary>
/// The position of the center of one of the pupils of the individual to enroll. If the iris-recognition system is only
@ -2454,7 +2454,7 @@ namespace Vanara.PInvoke
/// is monitoring both eyes, and both eyes are in the camera frame, this position is probably of the center of the pupil
/// of the left eye of the individual.
/// </summary>
public System.Drawing.Point PupilCenter_2;
public POINT PupilCenter_2;
/// <summary>
/// The distance between the actual location of the iris and the ideal focal distance for the iris. This value ranges
@ -2566,7 +2566,7 @@ namespace Vanara.PInvoke
/// The offset of the camera frame for the face from the video camera, in pixels. A value of (0, 0) indicates that the
/// camera frame for the face and the video camera completely overlap.
/// </summary>
public System.Drawing.Point FrameOffset;
public POINT FrameOffset;
/// <summary>The preferred orientation for the camera.</summary>
public WINBIO_ORIENTATION MandatoryOrientation;
@ -2663,7 +2663,7 @@ namespace Vanara.PInvoke
/// The offset of the camera frame for the face from the video camera, in pixels. A value of (0, 0) indicates that the
/// camera frame for the face and the video camera completely overlap.
/// </summary>
public System.Drawing.Point FrameOffset;
public POINT FrameOffset;
/// <summary>The preferred orientation for the camera.</summary>
public WINBIO_ORIENTATION MandatoryOrientation;
@ -3234,7 +3234,7 @@ namespace Vanara.PInvoke
/// the camera frame. If the iris-recognition system is monitoring both eyes, and both eyes are in the camera frame, this
/// position is probably of the center of the pupil of the right eye of the individual.
/// </summary>
public System.Drawing.Point PupilCenter_1;
public POINT PupilCenter_1;
/// <summary>
/// The position of the center of one of the pupils of the individual to enroll. If the iris-recognition system is only
@ -3242,7 +3242,7 @@ namespace Vanara.PInvoke
/// monitoring both eyes, and both eyes are in the camera frame, this position is probably of the center of the pupil of the
/// left eye of the individual.
/// </summary>
public System.Drawing.Point PupilCenter_2;
public POINT PupilCenter_2;
/// <summary>
/// The distance between the actual location of the iris and the ideal focal distance for the iris. This value ranges from

View File

@ -66,6 +66,7 @@
<ItemGroup>
<ProjectReference Include="..\..\PInvoke\Shell32\Vanara.PInvoke.Shell32.csproj" />
<ProjectReference Include="..\..\Windows.Forms\Vanara.Windows.Forms.csproj" />
<ProjectReference Include="..\..\Windows.Shell.Common\Vanara.Windows.Shell.Common.csproj" />
<ProjectReference Include="..\..\Windows.Shell\Vanara.Windows.Shell.csproj" />
</ItemGroup>
</Project>

View File

@ -14,7 +14,7 @@ namespace Vanara.PInvoke.Tests
{
Application.EnableVisualStyles();
var f = new Form { Size = new System.Drawing.Size(100, 100) };
var btn = new TextBox { Size = new System.Drawing.Size(50, 12), Location = new System.Drawing.Point(5, 5) };
var btn = new TextBox { Size = new System.Drawing.Size(50, 12), Location = new POINT(5, 5) };
var tip = new EDITBALLOONTIP("Test", "tested");
btn.HandleCreated += (s, a) => SendMessage(btn.Handle, EditMessage.EM_SHOWBALLOONTIP, 0, ref tip);
f.Controls.Add(btn);

View File

@ -20,8 +20,10 @@ namespace Vanara.PInvoke.Tests
Assert.That(err.Succeeded);
Thread.Sleep(1000);
using (var g = wnd.CreateGraphics())
using (var hrgn = Gdi32.CreateRectRgnIndirect(new RECT(0, 0, 20, 20)))
{
bb.SetRegion(g, new Region(new Rectangle(0, 0, 20, 20)));
bb.hRgnBlur = hrgn;
bb.dwFlags |= DWM_BLURBEHIND_Mask.DWM_BB_BLURREGION;
err = DwmEnableBlurBehindWindow(wnd.Handle, bb);
Assert.That(err.Succeeded);
Thread.Sleep(1000);

View File

@ -105,7 +105,7 @@ namespace Vanara.PInvoke.Tests
}, Throws.Nothing);
var rParams = Instance.CreateRenderingParams();
pFF.Item.GetRecommendedRenderingMode(9f, 72f, DWRITE_MEASURING_MODE.DWRITE_MEASURING_MODE_NATURAL, rParams).WriteValues();
var hMon = User32.MonitorFromPoint(System.Drawing.Point.Empty, User32.MonitorFlags.MONITOR_DEFAULTTOPRIMARY);
var hMon = User32.MonitorFromPoint(POINT.Empty, User32.MonitorFlags.MONITOR_DEFAULTTOPRIMARY);
rParams = Instance.CreateMonitorRenderingParams(hMon);
pFF.Item.GetRecommendedRenderingMode(9f, 72f, DWRITE_MEASURING_MODE.DWRITE_MEASURING_MODE_NATURAL, rParams).WriteValues();
rParams = Instance.CreateCustomRenderingParams(2.2f, 1f, 1f, DWRITE_PIXEL_GEOMETRY.DWRITE_PIXEL_GEOMETRY_BGR, DWRITE_RENDERING_MODE.DWRITE_RENDERING_MODE_ALIASED);

View File

@ -61,12 +61,12 @@ namespace Vanara.PInvoke.Tests
Assert.That(r.Height == 7 && r.bottom == 12);
r.Width = 11;
Assert.That(r.Width == 11 && r.right == 21);
Assert.That(r.Location == new Point(10, 5));
Assert.That(r.Location == new POINT(10, 5));
Assert.That(r.Size == new Size(11, 7));
r.Size = new Size(5, 5);
Assert.That(r.Width, Is.EqualTo(5));
Assert.That(r.Height, Is.EqualTo(5));
r.Location = new Point(5, 5);
r.Location = new POINT(5, 5);
Assert.That(r.X, Is.EqualTo(5));
Assert.That(r.Y, Is.EqualTo(5));
r.left = 2;

View File

@ -54,12 +54,12 @@ namespace Vanara.PInvoke.Tests
Assert.That(r.Height == 7 && r.bottom == 12);
r.Width = 11;
Assert.That(r.Width == 11 && r.right == 21);
Assert.That(r.Location == new Point(10, 5));
Assert.That(r.Location == new POINT(10, 5));
Assert.That(r.Size == new Size(11, 7));
r.Size = new Size(5,5);
Assert.That(r.Width, Is.EqualTo(5));
Assert.That(r.Height, Is.EqualTo(5));
r.Location = new Point(5, 5);
r.Location = new POINT(5, 5);
Assert.That(r.X, Is.EqualTo(5));
Assert.That(r.Y, Is.EqualTo(5));
}

View File

@ -106,9 +106,9 @@ namespace Vanara.PInvoke.Tests
Assert.That(ppv, Is.Not.Null);
((IExtractIconW)ppv).Extract(icoFile, 0, 48, out var lg, 16, out var sm).ThrowIfFailed();
Assert.That(lg.IsInvalid, Is.False);
Assert.That(lg.ToIcon().Height, Is.EqualTo(48));
Assert.That(lg.Size.Height, Is.EqualTo(48));
Assert.That(sm.IsInvalid, Is.False);
Assert.That(sm.ToIcon().Height, Is.EqualTo(16));
Assert.That(sm.Size.Height, Is.EqualTo(16));
Marshal.FinalReleaseComObject(ppv);
}
@ -118,7 +118,7 @@ namespace Vanara.PInvoke.Tests
const string icoFile = @"notepad.exe";
Assert.That(SHDefExtractIcon(icoFile, -2, 0, out _, out var sm, Macros.MAKELONG(48, 16)), Is.EqualTo((HRESULT)0));
Assert.That(sm.IsInvalid, Is.False);
Assert.That(sm.ToIcon().Height, Is.EqualTo(16));
Assert.That(sm.Size.Height, Is.EqualTo(16));
}
[Test]

View File

@ -492,7 +492,10 @@ namespace Vanara.PInvoke.Tests
using (var htheme = OpenThemeData(f.Handle, "Window"))
{
Assert.That(htheme, Is.Not.EqualTo(IntPtr.Zero));
var hr = HitTestThemeBackground(htheme, new SafeHDC(f.CreateGraphics()), 1, 1, HitTestOptions.HTTB_CAPTION, f.ClientRectangle, HRGN.NULL, new Point(1, 1), out var code);
var g = f.CreateGraphics();
IntPtr hdc = g.GetHdc();
var hr = HitTestThemeBackground(htheme, hdc, 1, 1, HitTestOptions.HTTB_CAPTION, f.ClientRectangle, HRGN.NULL, new POINT(1, 1), out var code);
g.ReleaseHdc(hdc);
Assert.That(hr.Succeeded);
}
f.Close();

View File

@ -102,16 +102,20 @@ namespace Vanara.Windows.Shell.Tests
{
using (var i = new ShellItem(testDoc))
{
var sz = new Size(32, 32);
Image bmp = i.GetImage(sz, ShellItemGetImageOptions.IconOnly);
Assert.That(bmp, Is.Not.Null);
Assert.That(bmp.Size, Is.EqualTo(sz));
var sz = new SIZE(32, 32);
SafeHBITMAP bmp = i.GetImage(sz, ShellItemGetImageOptions.IconOnly);
Assert.That(bmp.IsInvalid, Is.False);
var bmi = GetObject<BITMAP>(bmp);
Assert.That(new SIZE(bmi.bmWidth, bmi.bmHeight), Is.EqualTo(sz));
}
using (var i = new ShellItem(PInvoke.Tests.TestCaseSources.LargeFile))
{
var sz = new Size(1024, 1024);
Image bmp = i.GetImage(sz, ShellItemGetImageOptions.ThumbnailOnly | ShellItemGetImageOptions.ScaleUp);
Assert.That(bmp.Size, Has.Property("Width").EqualTo(sz.Width).Or.Property("Height").EqualTo(sz.Height));
SafeHBITMAP bmp = i.GetImage(sz, ShellItemGetImageOptions.ThumbnailOnly | ShellItemGetImageOptions.ScaleUp);
Assert.That(bmp.IsInvalid, Is.False);
var bmi = GetObject<BITMAP>(bmp);
SIZE newSz = new(bmi.bmWidth, bmi.bmHeight);
Assert.That(newSz, Has.Property("Width").EqualTo(sz.Width).Or.Property("Height").EqualTo(sz.Height));
}
}

View File

@ -342,9 +342,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Vanara.PInvoke.VssApi", "PI
{39AEDD51-C627-41B9-96D3-44F481ED4E7C} = {39AEDD51-C627-41B9-96D3-44F481ED4E7C}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VssApi", "UnitTests\PInvoke\VssApi\VssApi.csproj", "{B62EE3FD-4AA8-4A99-AAB3-3A4022AEB682}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VssApi", "UnitTests\PInvoke\VssApi\VssApi.csproj", "{B62EE3FD-4AA8-4A99-AAB3-3A4022AEB682}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vanara.Windows.Shell.Common", "Windows.Shell.Common\Vanara.Windows.Shell.Common.csproj", "{B83E33E5-2C2E-4D14-8638-729FCA4E447D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vanara.Windows.Shell.Common", "Windows.Shell.Common\Vanara.Windows.Shell.Common.csproj", "{B83E33E5-2C2E-4D14-8638-729FCA4E447D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vanara.Windows.Extensions", "Windows.Extensions\Vanara.Windows.Extensions.csproj", "{AE4636A6-A15A-4A73-8F7D-D5F878276992}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -2115,6 +2117,24 @@ Global
{B83E33E5-2C2E-4D14-8638-729FCA4E447D}.Release|x64.Build.0 = Release|Any CPU
{B83E33E5-2C2E-4D14-8638-729FCA4E447D}.Release|x86.ActiveCfg = Release|Any CPU
{B83E33E5-2C2E-4D14-8638-729FCA4E447D}.Release|x86.Build.0 = Release|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Debug|x64.ActiveCfg = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Debug|x64.Build.0 = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Debug|x86.ActiveCfg = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Debug|x86.Build.0 = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.DebugNoTests|Any CPU.ActiveCfg = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.DebugNoTests|Any CPU.Build.0 = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.DebugNoTests|x64.ActiveCfg = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.DebugNoTests|x64.Build.0 = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.DebugNoTests|x86.ActiveCfg = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.DebugNoTests|x86.Build.0 = Debug|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Release|Any CPU.Build.0 = Release|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Release|x64.ActiveCfg = Release|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Release|x64.Build.0 = Release|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Release|x86.ActiveCfg = Release|Any CPU
{AE4636A6-A15A-4A73-8F7D-D5F878276992}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,150 +1,67 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
using static Vanara.PInvoke.Gdi32;
using static Vanara.PInvoke.User32;
namespace Vanara.PInvoke
{
/// <summary>Extension methods to convert GdiObj handle variants to their .NET equivalents.</summary>
public static class GdiObjExtensions
public static class GdiObjExtensions2
{
/// <summary>Converts the generic GDI object handle to a specific handle.</summary>
/// <typeparam name="T">The handle type to which to convert.</typeparam>
/// <param name="hObj">The generic GDI object handle.</param>
/// <returns>The converted handle of type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException">The conversion type specified is not valid for the supplied GDI object.</exception>
public static T ConvertTo<T>(this IGraphicsObjectHandle hObj) where T : IGraphicsObjectHandle
{
var ot = GetObjectType(hObj.DangerousGetHandle());
if (ot == 0) Win32Error.ThrowLastError();
if (!CorrespondingTypeAttribute.CanGet(ot, typeof(T)))
throw new ArgumentException($"The conversion type specified is not valid for the supplied GDI object.");
return (T)(object)hObj.DangerousGetHandle();
}
/// <summary>Draws on a device context (<see cref="Graphics"/>) via a DIB section. This is useful when you need to draw on a transparent background.</summary>
/// <param name="dc">The device context.</param>
/// <param name="bounds">The bounds of the device context to paint.</param>
/// <param name="drawMethod">The draw method.</param>
public static void DrawViaDIB(this IDeviceContext dc, in Rectangle bounds, Action<SafeHDC, Rectangle> drawMethod)
{
using var sdc = new SafeHDC(dc);
DrawViaDIB(sdc, bounds, drawMethod);
}
/// <summary>Draws on a device context (<see cref="SafeHDC"/>) via a DIB section. This is useful when you need to draw on a transparent background.</summary>
/// <summary>
/// Draws on a device context ( <see cref="SafeHDC"/>) via a DIB section. This is useful when you need to draw on a transparent background.
/// </summary>
/// <param name="hdc">The device context.</param>
/// <param name="bounds">The bounds of the device context to paint.</param>
/// <param name="drawMethod">The draw method.</param>
public static void DrawViaDIB(this SafeHDC hdc, in Rectangle bounds, Action<SafeHDC, Rectangle> drawMethod)
public static void DrawViaDIB(this IDeviceContext hdc, in RECT bounds, Action<SafeHDC, RECT> drawMethod)
{
// Create a memory DC so we can work off screen
using var memoryHdc = hdc.GetCompatibleDCHandle();
// Create a device-independent bitmap and select it into our DC
var info = new BITMAPINFO(bounds.Width, -bounds.Height);
using (memoryHdc.SelectObject(CreateDIBSection(hdc, info, DIBColorMode.DIB_RGB_COLORS, out var pBits)))
IntPtr h = hdc.GetHdc();
try { GdiObjExtensions.DrawViaDIB(h, bounds, drawMethod); }
finally { hdc.ReleaseHdc(); }
}
/// <summary>Gets the copy of the device handle in an IDeviceContext supporting GDI+.</summary>
/// <param name="dc">The <see cref="IDeviceContext"/> instance.</param>
/// <returns>A <see cref="SafeHDC"/> instance that contains a copy of the context.</returns>
public static SafeHDC GetCompatibleSafeHDC(this IDeviceContext dc)
{
if (dc is null)
{
// Call method
drawMethod(memoryHdc, bounds);
// Copy to foreground
BitBlt(hdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, RasterOperationMode.SRCCOPY);
return new(default, false);
}
SafeHDC hdc = CreateCompatibleDC(dc.GetHdc());
dc.ReleaseHdc();
return hdc;
}
/// <summary>Determines whether the bitmap is a bottom-up DIB.</summary>
/// <param name="hbmp">The handle of the bitmap to assess.</param>
/// <returns><see langword="true"/> if the specified bitmap is a bottom-up DIB; otherwise, <see langword="false"/>.</returns>
public static bool IsBottomUpDIB(this in HBITMAP hbmp)
{
var dibSz = Marshal.SizeOf(typeof(DIBSECTION));
using var mem = GetObject(hbmp, dibSz);
return mem.Size == dibSz && mem.ToStructure<DIBSECTION>().dsBmih.biHeight > 0;
}
/// <summary>Determines whether the bitmap is a bottom-up DIB.</summary>
/// <param name="hbmp">The handle of the bitmap to assess.</param>
/// <returns><see langword="true"/> if the specified bitmap is a bottom-up DIB; otherwise, <see langword="false"/>.</returns>
public static bool IsDIB(this in HBITMAP hbmp)
{
var dibSz = Marshal.SizeOf(typeof(DIBSECTION));
using var mem = GetObject(hbmp, dibSz);
return mem.Size == dibSz;
}
/// <summary>Creates a <see cref="Bitmap"/> from an <see cref="SafeHBITMAP"/> preserving transparency, if possible.</summary>
/// <param name="hbmp">The SafeHBITMAP value.</param>
/// <returns>The Bitmap instance. If <paramref name="hbmp"/> is a <c>NULL</c> handle, <see langword="null"/> is returned.</returns>
public static Bitmap ToBitmap(this SafeHBITMAP hbmp) => ToBitmap((HBITMAP)hbmp);
/// <summary>Creates a <see cref="Bitmap"/> from an <see cref="HBITMAP"/> preserving transparency, if possible.</summary>
/// <param name="hbmp">The HBITMAP value.</param>
/// <returns>The Bitmap instance. If <paramref name="hbmp"/> is a <c>NULL</c> handle, <see langword="null"/> is returned.</returns>
public static Bitmap ToBitmap(this in HBITMAP hbmp) => Image.FromHbitmap((IntPtr)hbmp);
// TODO: Fix code below to process different bpp bitmaps w/o flipping
//{
// const System.Drawing.Imaging.PixelFormat fmt = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
// // If hbmp is NULL handle, return null
// if (hbmp.IsNull) return null;
/// <summary>Creates a managed <see cref="Bitmap"/> from a HICON instance.</summary>
/// <returns>A managed bitmap instance.</returns>
public static Bitmap ToBitmap(this in HICON hIcon) => hIcon.IsNull ? null : (Bitmap)Bitmap.FromHicon((IntPtr)hIcon).Clone();
// // Get detail and bail if not 32bit, empty or an old style BMP
// var (bpp, width, height, scanBytes, bits, isdib) = GetInfo(hbmp);
// if (bpp != Image.GetPixelFormatSize(fmt) || height == 0 || !isdib)
// return Image.FromHbitmap((IntPtr)hbmp);
/// <summary>Creates a managed <see cref="Bitmap"/> from a SafeHICON instance.</summary>
/// <returns>A managed bitmap instance.</returns>
public static Bitmap ToBitmap(this SafeHICON hIcon) => ToBitmap((HICON)hIcon);
// // Create bitmap from detail and flip if upside-down
// var bmp = new Bitmap(width, height, scanBytes, fmt, bits);
// if (height < 0) bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
// return bmp;
// static (ushort bpp, int width, int height, int scanBytes, IntPtr bits, bool isdib) GetInfo(in HBITMAP hbmp)
// {
// var dibSz = Marshal.SizeOf(typeof(DIBSECTION));
// using var mem = GetObject(hbmp, dibSz);
// if (mem.Size == dibSz)
// {
// var dib = mem.ToStructure<DIBSECTION>();
// return (dib.dsBm.bmBitsPixel, dib.dsBmih.biWidth, dib.dsBmih.biHeight, dib.dsBm.bmWidthBytes, dib.dsBm.bmBits, true);
// }
// else
// {
// var bmp = mem.ToStructure<BITMAP>();
// return (bmp.bmBitsPixel, bmp.bmWidth, bmp.bmHeight, bmp.bmWidthBytes, bmp.bmBits, false);
// }
// }
//}
#if WPF && !NET20 && !NETSTANDARD2_0 && !NETCOREAPP2_0 && !NETCOREAPP2_1
/// <summary>Creates a <see cref="System.Windows.Media.Imaging.BitmapSource"/> from an <see cref="HBITMAP"/> preserving transparency, if possible.</summary>
/// <param name="hbmp">The HBITMAP value.</param>
/// <returns>The BitmapSource instance. If <paramref name="hbmp"/> is a <c>NULL</c> handle, <see langword="null"/> is returned.</returns>
public static System.Windows.Media.Imaging.BitmapSource ToBitmapSource(this in HBITMAP hbmp)
{
// If hbmp is NULL handle, return null
if (hbmp.IsNull) return null;
try
{
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap((IntPtr)hbmp, IntPtr.Zero,
System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
catch (System.ComponentModel.Win32Exception)
{
return null;
}
}
/// <summary>Creates a <see cref="System.Windows.Media.Imaging.BitmapSource"/> from an <see cref="SafeHBITMAP"/> preserving transparency, if possible.</summary>
/// <param name="hbmp">The SafeHBITMAP value.</param>
/// <returns>The BitmapSource instance. If <paramref name="hbmp"/> is a <c>NULL</c> handle, <see langword="null"/> is returned.</returns>
public static System.Windows.Media.Imaging.BitmapSource ToBitmapSource(this SafeHBITMAP hbmp) => ((HBITMAP)hbmp).ToBitmapSource();
#endif
/// <summary>Creates a managed <see cref="System.Drawing.Brush"/> from this HBRUSH instance.</summary>
/// <summary>Creates a managed <see cref="Brush"/> from this HBRUSH instance.</summary>
/// <param name="hbr">The HBRUSH value.</param>
/// <returns>A managed brush instance.</returns>
public static Brush ToBrush(this in HBRUSH hbr) => hbr.IsNull ? null : new NativeBrush(hbr);
/// <summary>Creates a managed <see cref="System.Drawing.Brush"/> from this HBRUSH instance.</summary>
/// <summary>Creates a managed <see cref="Brush"/> from this HBRUSH instance.</summary>
/// <param name="hbr">The HBRUSH value.</param>
/// <returns>A managed brush instance.</returns>
public static Brush ToBrush(this SafeHBRUSH hbr) => ((HBRUSH)hbr).ToBrush();
@ -159,30 +76,38 @@ namespace Vanara.PInvoke
/// <returns>The Font instance.</returns>
public static Font ToFont(this SafeHFONT hf) => ((HFONT)hf).ToFont();
/// <summary>Creates a managed <see cref="Icon"/> from an HICON instance.</summary>
/// <returns>A managed icon instance.</returns>
public static Icon ToIcon(this in HICON hIcon) => hIcon.IsNull ? null : (Icon)Icon.FromHandle((IntPtr)hIcon).Clone();
/// <summary>Creates a managed <see cref="Icon"/> from a SafeHICON instance.</summary>
/// <returns>A managed icon instance.</returns>
public static Icon ToIcon(this SafeHICON hIcon) => ToIcon((HICON)hIcon);
/// <summary>Creates a <see cref="Pen"/> from an <see cref="HPEN"/>.</summary>
/// <param name="hpen">The HPEN value.</param>
/// <returns>The Pen instance.</returns>
public static Pen ToPen(this in HPEN hpen)
{
using var ptr = GetObject(hpen);
var lpen = ptr.ToStructure<EXTLOGPEN>();
using InteropServices.ISafeMemoryHandle ptr = GetObject(hpen);
EXTLOGPEN lpen = ptr.ToStructure<EXTLOGPEN>();
Pen pen = null;
switch (lpen.elpBrushStyle)
{
case BrushStyle.BS_DIBPATTERN:
case BrushStyle.BS_DIBPATTERNPT:
var lw = (DIBColorMode)(uint)lpen.elpColor;
var hb = CreateDIBPatternBrushPt(lpen.elpHatch, lw);
DIBColorMode lw = (DIBColorMode)(uint)lpen.elpColor;
SafeHBRUSH hb = CreateDIBPatternBrushPt(lpen.elpHatch, lw);
pen = new Pen(((HBRUSH)hb).ToBrush());
break;
case BrushStyle.BS_HATCHED:
var hbr = new HatchBrush((System.Drawing.Drawing2D.HatchStyle)lpen.elpHatch.ToInt32(), lpen.elpColor);
HatchBrush hbr = new HatchBrush((System.Drawing.Drawing2D.HatchStyle)lpen.elpHatch.ToInt32(), lpen.elpColor);
pen = new Pen(hbr);
break;
case BrushStyle.BS_PATTERN:
var pbr = new TextureBrush(Image.FromHbitmap(lpen.elpHatch));
TextureBrush pbr = new TextureBrush(Image.FromHbitmap(lpen.elpHatch));
pen = new Pen(pbr);
break;
@ -192,7 +117,7 @@ namespace Vanara.PInvoke
pen = new Pen(lpen.elpColor) { DashStyle = (DashStyle)lpen.Style };
if (pen.DashStyle == DashStyle.Custom && lpen.elpNumEntries > 0)
{
var styleArray = lpen.elpStyleEntry.ToArray<uint>((int)lpen.elpNumEntries);
uint[] styleArray = lpen.elpStyleEntry.ToArray<uint>((int)lpen.elpNumEntries);
pen.DashPattern = Array.ConvertAll(styleArray, i => (float)i);
}
break;
@ -225,12 +150,61 @@ namespace Vanara.PInvoke
/// <returns>The Region instance.</returns>
public static Region ToRegion(this SafeHRGN hrgn) => ((HRGN)hrgn).ToRegion();
// TODO: Fix code below to process different bpp bitmaps w/o flipping
//{
// const Imaging.PixelFormat fmt = Imaging.PixelFormat.Format32bppArgb;
// // If hbmp is NULL handle, return null if (hbmp.IsNull) return null;
// // Get detail and bail if not 32bit, empty or an old style BMP var (bpp, width, height, scanBytes, bits, isdib) = GetInfo(hbmp);
// if (bpp != Image.GetPixelFormatSize(fmt) || height == 0 || !isdib) return Image.FromHbitmap((IntPtr)hbmp);
// // Create bitmap from detail and flip if upside-down var bmp = new Bitmap(width, height, scanBytes, fmt, bits); if (height < 0)
// bmp.RotateFlip(RotateFlipType.Rotate180FlipNone); return bmp;
// static (ushort bpp, int width, int height, int scanBytes, IntPtr bits, bool isdib) GetInfo(in HBITMAP hbmp) { var dibSz =
// Marshal.SizeOf(typeof(DIBSECTION)); using var mem = GetObject(hbmp, dibSz); if (mem.Size == dibSz) { var dib =
// mem.ToStructure<DIBSECTION>(); return (dib.dsBm.bmBitsPixel, dib.dsBmih.biWidth, dib.dsBmih.biHeight, dib.dsBm.bmWidthBytes,
// dib.dsBm.bmBits, true); } else { var bmp = mem.ToStructure<BITMAP>(); return (bmp.bmBitsPixel, bmp.bmWidth, bmp.bmHeight,
// bmp.bmWidthBytes, bmp.bmBits, false); } }
//}
#if WPF && !NET20 && !NETSTANDARD2_0 && !NETCOREAPP2_0 && !NETCOREAPP2_1
/// <summary>
/// Creates a <see cref="System.Windows.Media.Imaging.BitmapSource"/> from an <see cref="HBITMAP"/> preserving transparency, if possible.
/// </summary>
/// <param name="hbmp">The HBITMAP value.</param>
/// <returns>The BitmapSource instance. If <paramref name="hbmp"/> is a <c>NULL</c> handle, <see langword="null"/> is returned.</returns>
public static System.Windows.Media.Imaging.BitmapSource ToBitmapSource(this in HBITMAP hbmp)
{
// If hbmp is NULL handle, return null
if (hbmp.IsNull) return null;
try
{
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap((IntPtr)hbmp, IntPtr.Zero,
System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
catch (System.ComponentModel.Win32Exception)
{
return null;
}
}
/// <summary>
/// Creates a <see cref="System.Windows.Media.Imaging.BitmapSource"/> from an <see cref="SafeHBITMAP"/> preserving transparency, if possible.
/// </summary>
/// <param name="hbmp">The SafeHBITMAP value.</param>
/// <returns>The BitmapSource instance. If <paramref name="hbmp"/> is a <c>NULL</c> handle, <see langword="null"/> is returned.</returns>
public static System.Windows.Media.Imaging.BitmapSource ToBitmapSource(this SafeHBITMAP hbmp) => ((HBITMAP)hbmp).ToBitmapSource();
#endif
private class NativeBrush : Brush
{
public NativeBrush(HBRUSH hBrush)
{
var lb = GetObject<LOGBRUSH>(hBrush);
using var b2 = CreateBrushIndirect(lb);
LOGBRUSH lb = GetObject<LOGBRUSH>(hBrush);
using SafeHBRUSH b2 = CreateBrushIndirect(lb);
SetNativeBrush(b2.DangerousGetHandle());
b2.SetHandleAsInvalid();
}
@ -238,4 +212,35 @@ namespace Vanara.PInvoke
public override object Clone() => this;
}
}
/// <summary>A self-releasing pattern for IDeviceContext.GetHdc and ReleaseHdc.</summary>
/// <seealso cref="System.IDisposable"/>
public class SafeTempHDC : IDisposable, IGraphicsObjectHandle
{
private readonly IDeviceContext dc;
private readonly IntPtr hdc;
/// <summary>Initializes a new instance of the <see cref="SafeTempHDC"/> class with an <see cref="IDeviceContext"/>.</summary>
/// <param name="dc">The <see cref="IDeviceContext"/> instance.</param>
public SafeTempHDC(IDeviceContext dc)
{
this.dc = dc;
hdc = dc?.GetHdc() ?? default;
}
/// <summary>Gets a value indicating whether this instance has a NULL handle.</summary>
/// <value><see langword="true"/> if this has a NULL handle; otherwise, <see langword="false"/>.</value>
public bool IsNull => hdc == default;
/// <summary>Performs an implicit conversion from <see cref="SafeTempHDC"/> to <see cref="HDC"/>.</summary>
/// <param name="o">The <see cref="SafeTempHDC"/> instance.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator HDC(SafeTempHDC o) => o.hdc;
/// <inheritdoc/>
public IntPtr DangerousGetHandle() => hdc;
/// <summary>Releases claimed HDC.</summary>
public void Dispose() => dc?.ReleaseHdc();
}
}

View File

@ -7,6 +7,7 @@ using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.PInvoke;
namespace Vanara.Extensions
{
@ -71,26 +72,6 @@ namespace Vanara.Extensions
gp.CloseFigure();
}
/// <summary>A method to darken a color by a percentage of the difference between the color and Black.</summary>
/// <param name="colorIn">The original color.</param>
/// <param name="percent">The percentage by which to darken the original color.</param>
/// <returns>
/// The return color's Alpha value will be unchanged, but the RGB content will have been increased by the specified percentage. If
/// percent is 100 then the returned Color will be Black with original Alpha.
/// </returns>
public static Color Darken(this Color colorIn, float percent)
{
if (percent < 0 || percent > 1.0)
throw new ArgumentOutOfRangeException(nameof(percent));
int a = colorIn.A;
var r = colorIn.R - (int)(colorIn.R * percent);
var g = colorIn.G - (int)(colorIn.G * percent);
var b = colorIn.B - (int)(colorIn.B * percent);
return Color.FromArgb(a, r, g, b);
}
/// <summary>Draws image with specified parameters.</summary>
/// <param name="graphics">Graphics on which to draw image</param>
/// <param name="image">Image to be drawn</param>
@ -219,26 +200,6 @@ namespace Vanara.Extensions
static double CalcOrigColor(byte w, byte b) => 255.0 * b / (255.0 - w + b);
}
/// <summary>A method to lighten a color by a percentage of the difference between the color and Black.</summary>
/// <param name="colorIn">The original color.</param>
/// <param name="percent">The percentage by which to lighten the original color.</param>
/// <returns>
/// The return color's Alpha value will be unchanged, but the RGB content will have been decreased by the specified percentage. If
/// percent is 100 then the returned Color will be White with original Alpha.
/// </returns>
public static Color Lighten(this Color colorIn, float percent)
{
if (percent < 0 || percent > 1.0)
throw new ArgumentOutOfRangeException(nameof(percent));
int a = colorIn.A;
var r = colorIn.R + (int)((255f - colorIn.R) * percent);
var g = colorIn.G + (int)((255f - colorIn.G) * percent);
var b = colorIn.B + (int)((255f - colorIn.B) * percent);
return Color.FromArgb(a, r, g, b);
}
/// <summary>Resize the image to the specified width and height.</summary>
/// <param name="image">The image to resize.</param>
/// <param name="width">The width to resize to.</param>
@ -279,7 +240,7 @@ namespace Vanara.Extensions
if (bitmap == null) throw new ArgumentNullException(nameof(bitmap));
if (Image.GetPixelFormatSize(bitmap.PixelFormat) != 32) throw new ArgumentException(@"Bitmap pixels must be 32bpp.", nameof(bitmap));
bmp = bitmap;
bd = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadWrite, bmp.PixelFormat);
bd = bmp.LockBits(new Rectangle(POINT.Empty, bmp.Size), ImageLockMode.ReadWrite, bmp.PixelFormat);
}
/// <summary>Finalizes an instance of the <see cref="SmartBitmapLock"/> class.</summary>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Extension methods and conversions from Vanara P/Invoke types and methods to Windows Forms types and methods.</Description>
<AssemblyTitle>$(AssemblyName)</AssemblyTitle>
<TargetFrameworks>net20;net35;net40;net45;net5.0-windows;netstandard2.0;netcoreapp2.0;netcoreapp2.1;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<UseWindowsForms>true</UseWindowsForms>
<AssemblyName>Vanara.Windows.Extensions</AssemblyName>
<PackageId>$(AssemblyName)</PackageId>
<PackageTags>pinvoke;vanara;net-extensions;interop;extensions;winforms;windows forms</PackageTags>
<PackageReleaseNotes />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PInvoke\Gdi32\Vanara.PInvoke.Gdi32.csproj" />
<ProjectReference Include="..\PInvoke\User32\Vanara.PInvoke.User32.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="5.0.3" Condition=" $(TargetFramework.StartsWith('netstandard')) Or $(TargetFramework.StartsWith('netcore')) " />
</ItemGroup>
</Project>

View File

@ -14,6 +14,7 @@ using Vanara.Windows.Shell;
using static Vanara.PInvoke.Ole32;
using static Vanara.PInvoke.Shell32;
using static Vanara.PInvoke.User32;
using DragEventArgs = System.Windows.Forms.DragEventArgs;
using IMessageFilter = System.Windows.Forms.IMessageFilter;
namespace Vanara.Windows.Forms

View File

@ -109,7 +109,7 @@ namespace Vanara.Windows.Forms
if (!CompositionSupported)
return;
DwmpGetColorizationParameters(out var p).ThrowIfFailed();
p.clrColor = value;
p.clrColor = (COLORREF)value;
DwmpSetColorizationParameters(p, 1).ThrowIfFailed();
Microsoft.Win32.Registry.CurrentUser.SetValue(@"Software\Microsoft\Windows\DWM\ColorizationColor", value.ToArgb(), Microsoft.Win32.RegistryValueKind.DWord);
}
@ -213,7 +213,10 @@ namespace Vanara.Windows.Forms
throw new ArgumentNullException(nameof(window));
var bb = new DWM_BLURBEHIND(enabled);
if (graphics != null && region != null)
bb.SetRegion(graphics, region);
{
bb.hRgnBlur = region.GetHrgn(graphics);
bb.dwFlags |= DWM_BLURBEHIND_Mask.DWM_BB_BLURREGION;
}
if (transitionOnMaximized)
bb.TransitionOnMaximized = true;
DwmEnableBlurBehindWindow(window.Handle, bb);

View File

@ -41,7 +41,7 @@ namespace Vanara.Drawing
/// <param name="data">User-defined data to pass to the <paramref name="paintAction"/> callback.</param>
public static void Paint<TState, TParam>(Graphics graphics, Rectangle bounds, PaintAction<TState, TParam> paintAction, TState currentState, TParam data)
{
using (var g = new SafeHDC(graphics))
using (var g = new SafeTempHDC(graphics))
using (var bp = new BufferedPainter(g, bounds))
paintAction(bp.Graphics, bounds, currentState, data);
}
@ -90,7 +90,7 @@ namespace Vanara.Drawing
else
paintAnimationInstances.Add(ctrl.Handle, new Tuple<object, object>(currentState, newState));
using (var hdc = new SafeHDC(graphics))
using (var hdc = new SafeTempHDC(graphics))
{
if (hdc.IsNull) return;
// see if this paint was generated by a soft-fade animation

View File

@ -260,8 +260,8 @@ namespace Vanara.Extensions
/// </returns>
public static int MeasureText(this IDeviceContext dc, System.Text.StringBuilder text, Font font, Size proposedSize, TextFormatFlags flags)
{
using var hdc = new SafeHDC(dc);
using var ctx = hdc.SelectObject((HFONT)font.ToHfont());
using var hdc = new SafeTempHDC(dc);
using var ctx = new GdiObjectContext(hdc, (HFONT)font.ToHfont());
return Win32Error.ThrowLastErrorIf(DrawTextEx(hdc, text, text.Length, new RECT(0, 0, proposedSize.Width, proposedSize.Height), (DrawTextFlags)(int)flags | DrawTextFlags.DT_CALCRECT), h => h == 0);
}
}

View File

@ -130,7 +130,7 @@ namespace Vanara.Extensions
if (iconSize <= IconSize.Small)
return ImageList_GetIcon(hSystemImageList, shfi.iIcon, IMAGELISTDRAWFLAGS.ILD_TRANSPARENT).ToIcon();
SHGetImageList((SHIL)iconSize, typeof(IImageList).GUID, out var il).ThrowIfFailed();
return il.GetIcon(shfi.iIcon, IMAGELISTDRAWFLAGS.ILD_TRANSPARENT).ToIcon();
return ((IImageList)il).GetIcon(shfi.iIcon, IMAGELISTDRAWFLAGS.ILD_TRANSPARENT).ToIcon();
}
/// <summary>Gets the Shell icon for the given file name or extension.</summary>

View File

@ -48,7 +48,7 @@ namespace Vanara.Extensions
throw new ArgumentOutOfRangeException(nameof(index));
if (overlayImageIndex < 0 || overlayImageIndex > imageList.GetOverlayCount())
throw new ArgumentOutOfRangeException(nameof(overlayImageIndex));
using (var hg = new SafeHDC(g))
using (var hg = new SafeTempHDC(g))
{
var p = new IMAGELISTDRAWPARAMS(hg, bounds, index, bgColor, style | (IMAGELISTDRAWFLAGS)INDEXTOOVERLAYMASK(overlayImageIndex)) { rgbFg = fgColor };
imageList.GetIImageList().Draw(p);

View File

@ -17,7 +17,7 @@ namespace Vanara.Extensions
/// <param name="pt">The pt.</param>
/// <param name="newWin">The new win.</param>
/// <returns></returns>
public static Point MapPoint(this IWin32Window ctrl, Point pt, IWin32Window newWin = null)
public static POINT MapPoint(this IWin32Window ctrl, POINT pt, IWin32Window newWin = null)
{
MapWindowPoints(GetHandle(ctrl), GetHandle(newWin), ref pt, 1);
return pt;
@ -31,11 +31,11 @@ namespace Vanara.Extensions
/// <param name="points">The points.</param>
/// <param name="newWin">The new win.</param>
/// <exception cref="System.ArgumentNullException">points</exception>
public static void MapPoints(this IWin32Window ctrl, Point[] points, IWin32Window newWin = null)
public static void MapPoints(this IWin32Window ctrl, POINT[] points, IWin32Window newWin = null)
{
if (points == null) throw new ArgumentNullException(nameof(points));
MapWindowPoints(GetHandle(ctrl), GetHandle(newWin), points, points.Length);
/*Point[] pts = new Point[points.Length];
/*POINT[] pts = new POINT[points.Length];
points.CopyTo(pts, 0);
for (int i = 0; i < pts.Length; i++)
MapWindowPoints(GetHandleRef(ctrl), GetHandleRef(newWin), ref pts[i], 1);
@ -46,7 +46,7 @@ namespace Vanara.Extensions
/// <param name="ctrl">The control.</param>
/// <param name="pt">The pt.</param>
/// <returns></returns>
public static Point MapPointToClient(this IWin32Window ctrl, Point pt) => MapPoint(null, pt, ctrl);
public static POINT MapPointToClient(this IWin32Window ctrl, POINT pt) => MapPoint(null, pt, ctrl);
/// <summary>
/// The MapPoint method converts (maps) a rectangle from a coordinate space relative to one window to a coordinate space relative to

View File

@ -18,7 +18,7 @@ namespace Vanara.Extensions
/// <returns>The margins defined for the property.</returns>
public static Padding GetMargins2(this VisualStyleRenderer rnd, IDeviceContext dc = null, MarginProperty prop = MarginProperty.ContentMargins)
{
using (var hdc = new SafeHDC(dc))
using (var hdc = new SafeTempHDC(dc))
{
GetThemeMargins(rnd.GetSafeHandle(), hdc, rnd.Part, rnd.State, (int)prop, null, out MARGINS m);
return new Padding(m.cxLeftWidth, m.cyTopHeight, m.cxRightWidth, m.cyBottomHeight);

View File

@ -155,7 +155,7 @@ namespace Vanara.Extensions
{
var rc = new RECT(bounds);
var ht = new SafeHTHEME(rnd.Handle, false);
using (var hdc = new SafeHDC(dc))
using (var hdc = new SafeTempHDC(dc))
DrawThemeTextEx(ht, hdc, rnd.Part, rnd.State, text, text.Length, FromTFF(flags), ref rc, options);
bounds = rc;
}
@ -197,7 +197,7 @@ namespace Vanara.Extensions
var info = new BITMAPINFO(bounds.Width, -bounds.Height);
using (memoryHdc.SelectObject(CreateDIBSection(HDC.NULL, info, DIBColorMode.DIB_RGB_COLORS, out var ppv)))
{
using (var memoryGraphics = (Graphics)memoryHdc)
using (var memoryGraphics = Graphics.FromHdc(memoryHdc.DangerousGetHandle()))
{
// Setup graphics
memoryGraphics.CompositingMode = CompositingMode.SourceOver;
@ -217,7 +217,7 @@ namespace Vanara.Extensions
// Copy DIB to Bitmap
var bmp = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
using (var primaryHdc = new SafeHDC(Graphics.FromImage(bmp)))
using (var primaryHdc = new SafeTempHDC(Graphics.FromImage(bmp)))
BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, RasterOperationMode.SRCCOPY);
return bmp;
}
@ -233,7 +233,7 @@ namespace Vanara.Extensions
/// </returns>
public static Font GetFont2(this VisualStyleRenderer rnd, IDeviceContext dc = null, Font defaultValue = null)
{
using (var hdc = new SafeHDC(dc))
using (var hdc = new SafeTempHDC(dc))
{
return 0 != GetThemeFont(new SafeHTHEME(rnd.Handle, false), hdc, rnd.Part, rnd.State, 210, out var f)
? defaultValue : Font.FromLogFont(f);

Some files were not shown because too many files have changed in this diff Show More