Win32NativeInterop.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "RegisterClassExW")]
  66. public static partial ushort RegisterClassEx(ref WNDCLASSEX param);
  67. [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "UnregisterClassW")]
  68. public static partial short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, IntPtr instance);
  69. [LibraryImport("user32.dll", EntryPoint = "DefWindowProcW")]
  70. public static partial IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam);
  71. [LibraryImport("kernel32.dll", EntryPoint = "GetModuleHandleA")]
  72. public static partial IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPStr)] string lpModuleName);
  73. [LibraryImport("user32.dll", SetLastError = true)]
  74. [return: MarshalAs(UnmanagedType.Bool)]
  75. public static partial bool DestroyWindow(IntPtr hwnd);
  76. [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "LoadCursorA")]
  77. public static partial IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName);
  78. [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "CreateWindowExW")]
  79. public static partial IntPtr CreateWindowEx(
  80. uint dwExStyle,
  81. [MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
  82. [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName,
  83. WindowStyles dwStyle,
  84. int x,
  85. int y,
  86. int nWidth,
  87. int nHeight,
  88. IntPtr hWndParent,
  89. IntPtr hMenu,
  90. IntPtr hInstance,
  91. IntPtr lpParam);
  92. }
  93. }