Repository navigation
Expand file tree
/
Copy pathNativeMethods.cs
More file actions
64 lines (50 loc) · 2.16 KB
/
Copy pathNativeMethods.cs
File metadata and controls
64 lines (50 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Runtime.InteropServices;
namespace Roundify;
internal static class NativeMethods
{
private const string User32 = "user32.dll";
public const int GWL_EXSTYLE = -20;
public const int WM_NCHITTEST = 0x0084;
public const int HTTRANSPARENT = -1;
public const long WS_EX_TRANSPARENT = 0x00000020L;
public const long WS_EX_TOOLWINDOW = 0x00000080L;
public const long WS_EX_NOACTIVATE = 0x08000000L;
public static readonly IntPtr HWND_TOP = IntPtr.Zero;
public static readonly IntPtr HWND_TOPMOST = new(-1);
public const uint SWP_NOSIZE = 0x0001;
public const uint SWP_NOMOVE = 0x0002;
public const uint SWP_NOACTIVATE = 0x0010;
public const uint SWP_SHOWWINDOW = 0x0040;
[DllImport(User32, EntryPoint = "GetWindowLongPtrW", SetLastError = true)]
private static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
[DllImport(User32, EntryPoint = "GetWindowLongW", SetLastError = true)]
private static extern int GetWindowLong32(IntPtr hWnd, int nIndex);
[DllImport(User32, EntryPoint = "SetWindowLongPtrW", SetLastError = true)]
private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport(User32, EntryPoint = "SetWindowLongW", SetLastError = true)]
private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport(User32, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(
IntPtr hWnd,
IntPtr hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
uint uFlags);
[DllImport(User32)]
public static extern uint GetDpiForWindow(IntPtr hWnd);
public static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex)
{
return IntPtr.Size == 8
? GetWindowLongPtr64(hWnd, nIndex)
: new IntPtr(GetWindowLong32(hWnd, nIndex));
}
public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr value)
{
return IntPtr.Size == 8
? SetWindowLongPtr64(hWnd, nIndex, value)
: new IntPtr(SetWindowLong32(hWnd, nIndex, value.ToInt32()));
}
}