1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-29 09:10:09 +00:00
msfs-popout-panel-manager/Provider/PInvoke.cs

165 lines
6.8 KiB
C#
Raw Normal View History

2021-09-30 02:17:20 +00:00
using System;
2021-12-14 05:40:07 +00:00
using System.Drawing;
2021-09-30 02:17:20 +00:00
using System.Runtime.InteropServices;
using System.Text;
2022-01-27 13:40:04 +00:00
namespace MSFSPopoutPanelManager.Provider
2021-09-30 02:17:20 +00:00
{
2022-01-18 14:58:11 +00:00
public static class PInvokeConstant
{
public const int SW_SHOWNORMAL = 1;
public const int SW_SHOWMINIMIZED = 2;
public const int SW_SHOWMAXIMIZED = 3;
2022-01-27 13:40:04 +00:00
public const int SW_SHOW = 5;
public const int SW_SHOWDEFAULT = 10;
2022-01-18 14:58:11 +00:00
public const int SW_NORMAL = 1;
public const int SW_MINIMIZE = 6;
public const int SW_RESTORE = 9;
2022-06-13 03:49:56 +00:00
public const uint EVENT_SYSTEM_CAPTURESTART = 0x0008;
public const uint EVENT_SYSTEM_CAPTUREEND = 0x0009;
public const uint EVENT_SYSTEM_MOVESIZESTART = 0x000A;
2022-01-18 14:58:11 +00:00
public const uint EVENT_SYSTEM_MOVESIZEEND = 0x000B;
public const uint EVENT_OBJECT_LOCATIONCHANGE = 0x800B;
public const int SWP_NOMOVE = 0x0002;
public const int SWP_NOSIZE = 0x0001;
2022-04-18 03:38:33 +00:00
public const int SWP_FRAMECHANGED = 0x0020;
public const int SWP_NOREDRAW = 0x0008;
public const int SWP_ASYNCWINDOWPOS = 0x4000;
2022-01-18 14:58:11 +00:00
public const int SWP_ALWAYS_ON_TOP = SWP_NOMOVE | SWP_NOSIZE;
public const int GWL_STYLE = -16;
2022-04-18 03:38:33 +00:00
public const int GWL_EXSTYLE = -20;
public const uint WS_SIZEBOX = 0x00040000;
public const uint WS_BORDER = 0x00800000;
public const uint WS_DLGFRAME = 0x00400000;
public const uint WS_CAPTION = WS_BORDER | WS_DLGFRAME;
public const uint WS_POPUP = 0x80000000;
public const uint WS_EX_DLGMODALFRAME = 0x00000001;
public const uint WS_THICKFRAME = 0x00040000;
2022-06-30 23:53:08 +00:00
public const uint WS_MAXIMIZEBOX = 0x10000;
public const uint WS_MINIMIZEBOX = 0x20000;
2022-01-18 14:58:11 +00:00
public const int HWND_TOPMOST = -1;
public const int HWND_NOTOPMOST = -2;
public const uint WM_CLOSE = 0x0010;
public const int WINEVENT_OUTOFCONTEXT = 0;
}
2022-01-27 13:40:04 +00:00
2021-09-30 02:17:20 +00:00
public class PInvoke
{
[DllImport("user32", SetLastError = true)]
2022-02-07 03:05:05 +00:00
public static extern int EnumWindows(CallBack callback, int lParam);
2021-09-30 02:17:20 +00:00
[DllImport("user32", SetLastError = true)]
2022-02-07 03:05:05 +00:00
public static extern bool EnumChildWindows(IntPtr window, CallBack callback, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
2022-06-30 23:53:08 +00:00
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
public static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
2022-01-27 13:40:04 +00:00
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
2021-12-14 05:40:07 +00:00
private static extern int GetClassName(IntPtr hWnd, StringBuilder strPtrClassName, Int32 nMaxCount);
public static string GetClassName(IntPtr hwnd)
{
StringBuilder sb = new StringBuilder(255);
GetClassName(hwnd, sb, sb.Capacity);
return sb.ToString();
}
2021-09-30 02:17:20 +00:00
[DllImport("user32.dll", SetLastError = true)]
2021-12-14 05:40:07 +00:00
public static extern bool GetClientRect(IntPtr hWnd, out Rectangle lpRect);
2021-09-30 02:17:20 +00:00
[DllImport("user32.dll", SetLastError = true)]
2021-09-30 02:17:20 +00:00
[return: MarshalAs(UnmanagedType.Bool)]
2021-12-14 05:40:07 +00:00
public static extern bool GetCursorPos(out Point lpPoint);
2021-09-30 02:17:20 +00:00
[DllImport("user32.dll", SetLastError = true)]
2021-09-30 02:17:20 +00:00
public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
2022-01-18 14:58:11 +00:00
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
[DllImport("user32.dll", SetLastError = true)]
2021-12-14 05:40:07 +00:00
public static extern int GetWindowRect(IntPtr hwnd, out Rectangle lpRect);
2021-09-30 02:17:20 +00:00
[DllImport("user32.dll", CharSet = CharSet.Auto)]
2021-12-14 05:40:07 +00:00
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);
2021-09-30 02:17:20 +00:00
2021-12-14 05:40:07 +00:00
public static string GetWindowText(IntPtr hwnd)
{
StringBuilder sb = new StringBuilder(255);
GetWindowText(hwnd, sb, sb.Capacity);
return sb.ToString();
}
2021-09-30 02:17:20 +00:00
[DllImport("user32.dll", SetLastError = true)]
2022-02-07 03:05:05 +00:00
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
2021-09-30 02:17:20 +00:00
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
[DllImport("user32.dll", SetLastError = true)]
2021-09-30 02:17:20 +00:00
public static extern void mouse_event(uint dwFlags, int dx, int dy, uint cButtons, uint dwExtraInfo);
[DllImport("user32.dll", SetLastError = true)]
2021-09-30 02:17:20 +00:00
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
[DllImport("User32.dll", SetLastError = true)]
2021-09-30 02:17:20 +00:00
public static extern bool SetCursorPos(int X, int Y);
2021-12-14 05:40:07 +00:00
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetFocus(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
2021-09-30 02:17:20 +00:00
public static extern bool SetForegroundWindow(IntPtr hWnd);
2021-12-14 05:40:07 +00:00
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
2021-09-30 02:17:20 +00:00
[DllImport("user32.dll", SetLastError = true)]
2022-01-27 13:40:04 +00:00
public static extern bool ShowWindowAsync(HandleRef hWnd, int nCmdShow);
[DllImport("USER32.dll", SetLastError = true)]
2021-09-30 02:17:20 +00:00
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
2022-01-27 13:40:04 +00:00
public static extern IntPtr SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint wFlags);
2021-09-30 02:17:20 +00:00
[DllImport("user32.dll", SetLastError = true)]
2021-09-30 02:17:20 +00:00
public static extern bool SetWindowText(System.IntPtr hwnd, System.String lpString);
2021-12-14 05:40:07 +00:00
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventProc lpfnWinEventProc, int idProcess, int idThread, uint dwflags);
2022-01-18 14:58:11 +00:00
[DllImport("user32.dll", SetLastError = true)]
2022-01-18 14:58:11 +00:00
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll", SetLastError = true)]
2021-12-14 05:40:07 +00:00
public static extern int UnhookWinEvent(IntPtr hWinEventHook);
public delegate bool CallBack(IntPtr hwnd, int lParam);
2021-09-30 02:17:20 +00:00
2021-12-14 05:40:07 +00:00
public delegate void WinEventProc(IntPtr hWinEventHook, uint iEvent, IntPtr hWnd, int idObject, int idChild, int dwEventThread, int dwmsEventTime);
2021-09-30 02:17:20 +00:00
}
2022-01-18 14:58:11 +00:00
[StructLayout(LayoutKind.Sequential)]
public struct WINDOWPLACEMENT
{
public int length;
public int flags;
public int showCmd;
public Point ptMinPosition;
public Point ptMaxPosition;
public Rectangle rcNormalPosition;
public Rectangle rcDevice;
}
2021-09-30 02:17:20 +00:00
}