-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve PInvoke WinApi and add DPI Support
- Loading branch information
Showing
93 changed files
with
4,691 additions
and
3,010 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
SkinFramWorkCore/Interop/Dwmapi/Inetrop.DwmExtendFrameIntoClientArea.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
internal static partial class Interop | ||
{ | ||
internal static partial class Dwmapi | ||
{ | ||
[DllImport(Libraries.Dwmapi, CharSet = CharSet.Auto, ExactSpelling = false)] | ||
public static extern HRESULT DwmExtendFrameIntoClientArea(IntPtr hWnd, ref UxTheme.MARGINS pMarInset); | ||
public static HRESULT DwmExtendFrameIntoClientArea(IHandle hWnd, ref UxTheme.MARGINS pMarInset) | ||
{ | ||
var result = DwmExtendFrameIntoClientArea(hWnd.Handle, ref pMarInset); | ||
GC.KeepAlive(hWnd); | ||
return result; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
SkinFramWorkCore/Interop/Gdi32/Interop.CreateRoundRectRgn.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
internal static partial class Interop | ||
{ | ||
internal static partial class Gdi32 | ||
{ | ||
[DllImport(Libraries.Gdi32)] | ||
public static extern HRGN CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
SkinFramWorkCore/Interop/Gdi32/Interop.CreateSolidBrush.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Gdi32 | ||
{ | ||
[DllImport(Libraries.Gdi32, ExactSpelling = true, SetLastError = true)] | ||
public static extern HBRUSH CreateSolidBrush(int crColor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
using System; | ||
internal static partial class Interop | ||
{ | ||
internal static partial class Gdi32 | ||
{ | ||
[DllImport(Libraries.Gdi32, ExactSpelling = true)] | ||
public static extern BOOL DeleteObject(IntPtr hObject); | ||
|
||
public static BOOL DeleteObject(HGDIOBJ hObject) => DeleteObject(hObject.Handle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
internal static partial class Interop | ||
{ | ||
internal static partial class Gdi32 | ||
{ | ||
[DllImport(Libraries.Gdi32)] | ||
public static extern int ExcludeClipRect(HDC hdc, int left, int top, int right, int bottom); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Gdi32 | ||
{ | ||
// This does set last error but *only* in one error case that doesn't add any real value. | ||
[DllImport(Libraries.Gdi32, ExactSpelling = true)] | ||
public static extern OBJ GetObjectType(HGDIOBJ h); | ||
|
||
public static OBJ GetObjectType(HandleRef h) | ||
{ | ||
OBJ result = GetObjectType((HGDIOBJ)h.Handle); | ||
GC.KeepAlive(h.Wrapper); | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
using System; | ||
internal static partial class Interop | ||
{ | ||
internal static partial class Gdi32 | ||
{ | ||
[DllImport(Libraries.Gdi32, ExactSpelling = true)] | ||
public static extern uint GetRegionData(IntPtr hRgn, uint nCount, IntPtr lpRgnData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
using System; | ||
internal static partial class Interop | ||
{ | ||
internal static partial class Gdi32 | ||
{ | ||
public readonly struct HBRUSH | ||
{ | ||
public IntPtr Handle { get; } | ||
|
||
public HBRUSH(IntPtr handle) => Handle = handle; | ||
|
||
public bool IsNull => Handle == IntPtr.Zero; | ||
|
||
public static explicit operator IntPtr(HBRUSH hbrush) => hbrush.Handle; | ||
public static explicit operator HBRUSH(IntPtr hbrush) => new HBRUSH(hbrush); | ||
public static implicit operator HGDIOBJ(HBRUSH hbrush) => new HGDIOBJ(hbrush.Handle); | ||
public static explicit operator HBRUSH(HGDIOBJ hbrush) => new HBRUSH(hbrush.Handle); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Gdi32 | ||
{ | ||
public readonly struct HDC | ||
{ | ||
public IntPtr Handle { get; } | ||
|
||
public HDC(IntPtr handle) => Handle = handle; | ||
|
||
public bool IsNull => Handle == IntPtr.Zero; | ||
|
||
public static explicit operator IntPtr(HDC hdc) => hdc.Handle; | ||
public static explicit operator HDC(IntPtr hdc) => new HDC(hdc); | ||
public static implicit operator HGDIOBJ(HDC hdc) => new HGDIOBJ(hdc.Handle); | ||
|
||
public static bool operator ==(HDC value1, HDC value2) => value1.Handle == value2.Handle; | ||
public static bool operator !=(HDC value1, HDC value2) => value1.Handle != value2.Handle; | ||
public override bool Equals(object? obj) => obj is HDC hdc && hdc.Handle == Handle; | ||
public override int GetHashCode() => Handle.GetHashCode(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Gdi32 | ||
{ | ||
public struct HGDIOBJ | ||
{ | ||
public IntPtr Handle { get; } | ||
|
||
public HGDIOBJ(IntPtr handle) => Handle = handle; | ||
|
||
public bool IsNull => Handle == IntPtr.Zero; | ||
|
||
public static explicit operator IntPtr(HGDIOBJ hgdiobj) => hgdiobj.Handle; | ||
public static explicit operator HGDIOBJ(IntPtr hgdiobj) => new HGDIOBJ(hgdiobj); | ||
|
||
public static bool operator ==(HGDIOBJ value1, HGDIOBJ value2) => value1.Handle == value2.Handle; | ||
public static bool operator !=(HGDIOBJ value1, HGDIOBJ value2) => value1.Handle != value2.Handle; | ||
public override bool Equals(object? obj) => obj is HGDIOBJ hgdiobj && hgdiobj.Handle == Handle; | ||
public override int GetHashCode() => Handle.GetHashCode(); | ||
|
||
public OBJ ObjectType => GetObjectType(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Buffers; | ||
using System; | ||
internal static partial class Interop | ||
{ | ||
internal static partial class Gdi32 | ||
{ | ||
public readonly struct HRGN | ||
{ | ||
public IntPtr Handle { get; } | ||
|
||
public HRGN(IntPtr handle) => Handle = handle; | ||
|
||
public bool IsNull => Handle == IntPtr.Zero; | ||
|
||
public static implicit operator HGDIOBJ(HRGN hrgn) => new HGDIOBJ(hrgn.Handle); | ||
public static explicit operator IntPtr(HRGN hrgn) => hrgn.Handle; | ||
public static explicit operator HRGN(IntPtr hrgn) => new HRGN(hrgn); | ||
|
||
public unsafe RECT[] GetRegionRects() | ||
{ | ||
uint regionDataSize = GetRegionData(Handle, 0, IntPtr.Zero); | ||
if (regionDataSize == 0) | ||
{ | ||
return Array.Empty<RECT>(); | ||
} | ||
|
||
byte[] buffer = ArrayPool<byte>.Shared.Rent((int)regionDataSize); | ||
|
||
fixed (byte* b = buffer) | ||
{ | ||
if (GetRegionData(Handle, regionDataSize, (IntPtr)b) != regionDataSize) | ||
{ | ||
return Array.Empty<RECT>(); | ||
} | ||
|
||
RECT[] result = RGNDATAHEADER.GetRegionRects((RGNDATAHEADER*)b); | ||
ArrayPool<byte>.Shared.Return(buffer); | ||
return result; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.