Win32NativeInterop.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Runtime.Versioning;
  4. namespace Ryujinx.Ava.Ui.Controls
  5. {
  6. [SupportedOSPlatform("windows")]
  7. internal 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, CharSet = CharSet.Unicode)]
  46. public struct WNDCLASSEX
  47. {
  48. public int cbSize;
  49. public ClassStyles style;
  50. [MarshalAs(UnmanagedType.FunctionPtr)]
  51. public WindowProc lpfnWndProc; // not WndProc
  52. public int cbClsExtra;
  53. public int cbWndExtra;
  54. public IntPtr hInstance;
  55. public IntPtr hIcon;
  56. public IntPtr hCursor;
  57. public IntPtr hbrBackground;
  58. [MarshalAs(UnmanagedType.LPWStr)]
  59. public string lpszMenuName;
  60. [MarshalAs(UnmanagedType.LPWStr)]
  61. public string lpszClassName;
  62. public IntPtr hIconSm;
  63. public static WNDCLASSEX Create()
  64. {
  65. return new WNDCLASSEX
  66. {
  67. cbSize = Marshal.SizeOf<WNDCLASSEX>()
  68. };
  69. }
  70. }
  71. [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
  72. public static extern ushort RegisterClassEx(ref WNDCLASSEX param);
  73. [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
  74. public static extern short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, IntPtr instance);
  75. [DllImport("user32.dll", CharSet = CharSet.Unicode)]
  76. public static extern IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam);
  77. [DllImport("kernel32.dll")]
  78. public static extern IntPtr GetModuleHandle(string lpModuleName);
  79. [DllImport("user32.dll", SetLastError = true)]
  80. [return: MarshalAs(UnmanagedType.Bool)]
  81. public static extern bool DestroyWindow(IntPtr hwnd);
  82. [DllImport("user32.dll", SetLastError = true)]
  83. public static extern IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName);
  84. [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
  85. public static extern IntPtr CreateWindowEx(
  86. uint dwExStyle,
  87. string lpClassName,
  88. string lpWindowName,
  89. WindowStyles dwStyle,
  90. int x,
  91. int y,
  92. int nWidth,
  93. int nHeight,
  94. IntPtr hWndParent,
  95. IntPtr hMenu,
  96. IntPtr hInstance,
  97. IntPtr lpParam);
  98. }
  99. }