Win32NativeInterop.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Runtime.Versioning;
  4. namespace Ryujinx.Ava.UI.Helpers
  5. {
  6. [SupportedOSPlatform("windows")]
  7. internal partial class Win32NativeInterop
  8. {
  9. [Flags]
  10. public enum ClassStyles : uint
  11. {
  12. CS_CLASSDC = 0x40,
  13. CS_OWNDC = 0x20,
  14. }
  15. [Flags]
  16. public enum WindowStyles : uint
  17. {
  18. WS_CHILD = 0x40000000
  19. }
  20. public enum Cursors : uint
  21. {
  22. IDC_ARROW = 32512
  23. }
  24. public enum WindowsMessages : uint
  25. {
  26. MOUSEMOVE = 0x0200,
  27. LBUTTONDOWN = 0x0201,
  28. LBUTTONUP = 0x0202,
  29. LBUTTONDBLCLK = 0x0203,
  30. RBUTTONDOWN = 0x0204,
  31. RBUTTONUP = 0x0205,
  32. RBUTTONDBLCLK = 0x0206,
  33. MBUTTONDOWN = 0x0207,
  34. MBUTTONUP = 0x0208,
  35. MBUTTONDBLCLK = 0x0209,
  36. MOUSEWHEEL = 0x020A,
  37. XBUTTONDOWN = 0x020B,
  38. XBUTTONUP = 0x020C,
  39. XBUTTONDBLCLK = 0x020D,
  40. MOUSEHWHEEL = 0x020E,
  41. MOUSELAST = 0x020E
  42. }
  43. [UnmanagedFunctionPointer(CallingConvention.Winapi)]
  44. internal delegate IntPtr WindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam);
  45. [StructLayout(LayoutKind.Sequential)]
  46. public struct WNDCLASSEX
  47. {
  48. public int cbSize;
  49. public ClassStyles style;
  50. public IntPtr lpfnWndProc; // not WndProc
  51. public int cbClsExtra;
  52. public int cbWndExtra;
  53. public IntPtr hInstance;
  54. public IntPtr hIcon;
  55. public IntPtr hCursor;
  56. public IntPtr hbrBackground;
  57. public IntPtr lpszMenuName;
  58. public IntPtr lpszClassName;
  59. public IntPtr hIconSm;
  60. public WNDCLASSEX()
  61. {
  62. cbSize = Marshal.SizeOf<WNDCLASSEX>();
  63. }
  64. }
  65. public static IntPtr CreateEmptyCursor()
  66. {
  67. return CreateCursor(IntPtr.Zero, 0, 0, 1, 1, new byte[] { 0xFF }, new byte[] { 0x00 });
  68. }
  69. public static IntPtr CreateArrowCursor()
  70. {
  71. return LoadCursor(IntPtr.Zero, (IntPtr)Cursors.IDC_ARROW);
  72. }
  73. [LibraryImport("user32.dll")]
  74. public static partial IntPtr SetCursor(IntPtr handle);
  75. [LibraryImport("user32.dll")]
  76. public static partial IntPtr CreateCursor(IntPtr hInst, int xHotSpot, int yHotSpot, int nWidth, int nHeight, byte[] pvANDPlane, byte[] pvXORPlane);
  77. [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "RegisterClassExW")]
  78. public static partial ushort RegisterClassEx(ref WNDCLASSEX param);
  79. [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "UnregisterClassW")]
  80. public static partial short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, IntPtr instance);
  81. [LibraryImport("user32.dll", EntryPoint = "DefWindowProcW")]
  82. public static partial IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam);
  83. [LibraryImport("kernel32.dll", EntryPoint = "GetModuleHandleA")]
  84. public static partial IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPStr)] string lpModuleName);
  85. [LibraryImport("user32.dll", SetLastError = true)]
  86. [return: MarshalAs(UnmanagedType.Bool)]
  87. public static partial bool DestroyWindow(IntPtr hwnd);
  88. [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "LoadCursorA")]
  89. public static partial IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName);
  90. [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "CreateWindowExW")]
  91. public static partial IntPtr CreateWindowEx(
  92. uint dwExStyle,
  93. [MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
  94. [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName,
  95. WindowStyles dwStyle,
  96. int x,
  97. int y,
  98. int nWidth,
  99. int nHeight,
  100. IntPtr hWndParent,
  101. IntPtr hMenu,
  102. IntPtr hInstance,
  103. IntPtr lpParam);
  104. }
  105. }