-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeWin32.cs
More file actions
81 lines (65 loc) · 2.1 KB
/
Copy pathNativeWin32.cs
File metadata and controls
81 lines (65 loc) · 2.1 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System.Runtime.InteropServices;
namespace Du;
internal partial class NativeWin32
{
internal const int WM_COPYDATA = 0x004A;
internal const int WM_WINDOWPOSCHANGING = 0x0046;
internal const int WM_HSCROLL = 0x114;
internal const int WM_VSCROLL = 0x115;
internal const int WM_SIZE = 0x05;
internal const int WM_NOTIFY = 0x4E;
internal const int SW_RESTORE = 9;
[DllImport("user32.dll", SetLastError = true)]
internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref WmCopyData lParam);
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool SetForegroundWindow(IntPtr hWnd);
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool IsIconic(IntPtr hWnd);
[LibraryImport("kernel32.dll", SetLastError = true)]
internal static partial IntPtr LocalAlloc(int flag, int size);
[LibraryImport("kernel32.dll", SetLastError = true)]
internal static partial IntPtr LocalFree(IntPtr p);
//
internal struct WmCopyData : IDisposable
{
public IntPtr DwData;
public int CbData;
public IntPtr LpData;
public void Dispose()
{
if (LpData == IntPtr.Zero)
return;
LocalFree(LpData);
LpData = IntPtr.Zero;
}
public void SetString(string value)
{
Dispose();
CbData = (value.Length + 1) * 2;
LpData = LocalAlloc(0x40, CbData);
Marshal.Copy(value.ToCharArray(), 0, LpData, value.Length);
DwData = (IntPtr)1;
}
public void Send(IntPtr handle)
{
_ = SendMessage(handle, WM_COPYDATA, IntPtr.Zero, ref this);
}
public static WmCopyData FromLParam(IntPtr lparam)
{
return Marshal.PtrToStructure<WmCopyData>(lparam);
}
public static string? Receive(IntPtr lparam)
{
var s = FromLParam(lparam);
var v = Marshal.PtrToStringUni(s.LpData);
return v;
}
}
}