Skip to content

Commit c4bddaf

Browse files
committed
Improve PInvoke WinApi and add DPI Support
1 parent f6a955a commit c4bddaf

File tree

93 files changed

+4691
-3010
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+4691
-3010
lines changed

SkinFramWorkCore.sln

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.32929.386
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33103.184
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkinFramWorkCore", "SkinFramWorkCore\SkinFramWorkCore.csproj", "{2D1532E1-CB47-467C-AB40-3C910A0100AE}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkinFramWorkCore", "SkinFramWorkCore\SkinFramWorkCore.csproj", "{2D1532E1-CB47-467C-AB40-3C910A0100AE}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{28D26C77-C889-4603-9F5C-8234A8C0690E}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp1", "TestApp1\TestApp1.csproj", "{12A05D1D-6EFC-49D0-9C58-28DBE9EE743B}"
9+
ProjectSection(ProjectDependencies) = postProject
10+
{2D1532E1-CB47-467C-AB40-3C910A0100AE} = {2D1532E1-CB47-467C-AB40-3C910A0100AE}
11+
EndProjectSection
912
EndProject
1013
Global
1114
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -17,10 +20,10 @@ Global
1720
{2D1532E1-CB47-467C-AB40-3C910A0100AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
1821
{2D1532E1-CB47-467C-AB40-3C910A0100AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
1922
{2D1532E1-CB47-467C-AB40-3C910A0100AE}.Release|Any CPU.Build.0 = Release|Any CPU
20-
{28D26C77-C889-4603-9F5C-8234A8C0690E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21-
{28D26C77-C889-4603-9F5C-8234A8C0690E}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{28D26C77-C889-4603-9F5C-8234A8C0690E}.Release|Any CPU.ActiveCfg = Release|Any CPU
23-
{28D26C77-C889-4603-9F5C-8234A8C0690E}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{12A05D1D-6EFC-49D0-9C58-28DBE9EE743B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{12A05D1D-6EFC-49D0-9C58-28DBE9EE743B}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{12A05D1D-6EFC-49D0-9C58-28DBE9EE743B}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{12A05D1D-6EFC-49D0-9C58-28DBE9EE743B}.Release|Any CPU.Build.0 = Release|Any CPU
2427
EndGlobalSection
2528
GlobalSection(SolutionProperties) = preSolution
2629
HideSolutionNode = FALSE

SkinFramWorkCore/CaptionButton.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

SkinFramWorkCore/CaptionButtons.cs

Lines changed: 0 additions & 68 deletions
This file was deleted.

SkinFramWorkCore/DebugConsole.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Runtime.InteropServices;
66
namespace SkinFramWorkCore
77
{
8-
public class DebugConsole
8+
internal class DebugConsole
99
{
1010
#region Methods
1111
/// <summary>

SkinFramWorkCore/DwmButtonState.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
internal static partial class Interop
8+
{
9+
internal static partial class Dwmapi
10+
{
11+
[DllImport(Libraries.Dwmapi, CharSet = CharSet.Auto, ExactSpelling = false)]
12+
public static extern HRESULT DwmExtendFrameIntoClientArea(IntPtr hWnd, ref UxTheme.MARGINS pMarInset);
13+
public static HRESULT DwmExtendFrameIntoClientArea(IHandle hWnd, ref UxTheme.MARGINS pMarInset)
14+
{
15+
var result = DwmExtendFrameIntoClientArea(hWnd.Handle, ref pMarInset);
16+
GC.KeepAlive(hWnd);
17+
return result;
18+
}
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.InteropServices;
6+
internal static partial class Interop
7+
{
8+
internal static partial class Gdi32
9+
{
10+
[DllImport(Libraries.Gdi32)]
11+
public static extern HRGN CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse);
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.InteropServices;
6+
7+
internal static partial class Interop
8+
{
9+
internal static partial class Gdi32
10+
{
11+
[DllImport(Libraries.Gdi32, ExactSpelling = true, SetLastError = true)]
12+
public static extern HBRUSH CreateSolidBrush(int crColor);
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.InteropServices;
6+
using System;
7+
internal static partial class Interop
8+
{
9+
internal static partial class Gdi32
10+
{
11+
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
12+
public static extern BOOL DeleteObject(IntPtr hObject);
13+
14+
public static BOOL DeleteObject(HGDIOBJ hObject) => DeleteObject(hObject.Handle);
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.InteropServices;
6+
internal static partial class Interop
7+
{
8+
internal static partial class Gdi32
9+
{
10+
[DllImport(Libraries.Gdi32)]
11+
public static extern int ExcludeClipRect(HDC hdc, int left, int top, int right, int bottom);
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
internal static partial class Interop
9+
{
10+
internal static partial class Gdi32
11+
{
12+
// This does set last error but *only* in one error case that doesn't add any real value.
13+
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
14+
public static extern OBJ GetObjectType(HGDIOBJ h);
15+
16+
public static OBJ GetObjectType(HandleRef h)
17+
{
18+
OBJ result = GetObjectType((HGDIOBJ)h.Handle);
19+
GC.KeepAlive(h.Wrapper);
20+
return result;
21+
}
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.InteropServices;
6+
using System;
7+
internal static partial class Interop
8+
{
9+
internal static partial class Gdi32
10+
{
11+
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
12+
public static extern uint GetRegionData(IntPtr hRgn, uint nCount, IntPtr lpRgnData);
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
using System;
5+
internal static partial class Interop
6+
{
7+
internal static partial class Gdi32
8+
{
9+
public readonly struct HBRUSH
10+
{
11+
public IntPtr Handle { get; }
12+
13+
public HBRUSH(IntPtr handle) => Handle = handle;
14+
15+
public bool IsNull => Handle == IntPtr.Zero;
16+
17+
public static explicit operator IntPtr(HBRUSH hbrush) => hbrush.Handle;
18+
public static explicit operator HBRUSH(IntPtr hbrush) => new HBRUSH(hbrush);
19+
public static implicit operator HGDIOBJ(HBRUSH hbrush) => new HGDIOBJ(hbrush.Handle);
20+
public static explicit operator HBRUSH(HGDIOBJ hbrush) => new HBRUSH(hbrush.Handle);
21+
}
22+
}
23+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
internal static partial class Interop
8+
{
9+
internal static partial class Gdi32
10+
{
11+
public readonly struct HDC
12+
{
13+
public IntPtr Handle { get; }
14+
15+
public HDC(IntPtr handle) => Handle = handle;
16+
17+
public bool IsNull => Handle == IntPtr.Zero;
18+
19+
public static explicit operator IntPtr(HDC hdc) => hdc.Handle;
20+
public static explicit operator HDC(IntPtr hdc) => new HDC(hdc);
21+
public static implicit operator HGDIOBJ(HDC hdc) => new HGDIOBJ(hdc.Handle);
22+
23+
public static bool operator ==(HDC value1, HDC value2) => value1.Handle == value2.Handle;
24+
public static bool operator !=(HDC value1, HDC value2) => value1.Handle != value2.Handle;
25+
public override bool Equals(object? obj) => obj is HDC hdc && hdc.Handle == Handle;
26+
public override int GetHashCode() => Handle.GetHashCode();
27+
}
28+
}
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
internal static partial class Interop
8+
{
9+
internal static partial class Gdi32
10+
{
11+
public struct HGDIOBJ
12+
{
13+
public IntPtr Handle { get; }
14+
15+
public HGDIOBJ(IntPtr handle) => Handle = handle;
16+
17+
public bool IsNull => Handle == IntPtr.Zero;
18+
19+
public static explicit operator IntPtr(HGDIOBJ hgdiobj) => hgdiobj.Handle;
20+
public static explicit operator HGDIOBJ(IntPtr hgdiobj) => new HGDIOBJ(hgdiobj);
21+
22+
public static bool operator ==(HGDIOBJ value1, HGDIOBJ value2) => value1.Handle == value2.Handle;
23+
public static bool operator !=(HGDIOBJ value1, HGDIOBJ value2) => value1.Handle != value2.Handle;
24+
public override bool Equals(object? obj) => obj is HGDIOBJ hgdiobj && hgdiobj.Handle == Handle;
25+
public override int GetHashCode() => Handle.GetHashCode();
26+
27+
public OBJ ObjectType => GetObjectType(this);
28+
}
29+
}
30+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Buffers;
6+
using System;
7+
internal static partial class Interop
8+
{
9+
internal static partial class Gdi32
10+
{
11+
public readonly struct HRGN
12+
{
13+
public IntPtr Handle { get; }
14+
15+
public HRGN(IntPtr handle) => Handle = handle;
16+
17+
public bool IsNull => Handle == IntPtr.Zero;
18+
19+
public static implicit operator HGDIOBJ(HRGN hrgn) => new HGDIOBJ(hrgn.Handle);
20+
public static explicit operator IntPtr(HRGN hrgn) => hrgn.Handle;
21+
public static explicit operator HRGN(IntPtr hrgn) => new HRGN(hrgn);
22+
23+
public unsafe RECT[] GetRegionRects()
24+
{
25+
uint regionDataSize = GetRegionData(Handle, 0, IntPtr.Zero);
26+
if (regionDataSize == 0)
27+
{
28+
return Array.Empty<RECT>();
29+
}
30+
31+
byte[] buffer = ArrayPool<byte>.Shared.Rent((int)regionDataSize);
32+
33+
fixed (byte* b = buffer)
34+
{
35+
if (GetRegionData(Handle, regionDataSize, (IntPtr)b) != regionDataSize)
36+
{
37+
return Array.Empty<RECT>();
38+
}
39+
40+
RECT[] result = RGNDATAHEADER.GetRegionRects((RGNDATAHEADER*)b);
41+
ArrayPool<byte>.Shared.Return(buffer);
42+
return result;
43+
}
44+
}
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)