WinApi.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. namespace IntegrationTestApp.Embedding;
  5. internal class WinApi
  6. {
  7. public const int GWL_WNDPROC = -4;
  8. public const uint TME_HOVER = 1;
  9. public const uint TME_LEAVE = 2;
  10. public const uint WM_CONTEXTMENU = 0x007B;
  11. public const uint WM_MOUSELEAVE = 0x02A3;
  12. public const uint WM_MOUSEHOVER = 0x02A1;
  13. public const uint WM_MOUSEMOVE = 0x0200;
  14. public delegate IntPtr WndProcDelegate(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
  15. [Flags]
  16. public enum WindowStyles : uint
  17. {
  18. WS_BORDER = 0x800000,
  19. WS_CAPTION = 0xc00000,
  20. WS_CHILD = 0x40000000,
  21. WS_CLIPCHILDREN = 0x2000000,
  22. WS_CLIPSIBLINGS = 0x4000000,
  23. WS_DISABLED = 0x8000000,
  24. WS_DLGFRAME = 0x400000,
  25. WS_GROUP = 0x20000,
  26. WS_HSCROLL = 0x100000,
  27. WS_MAXIMIZE = 0x1000000,
  28. WS_MAXIMIZEBOX = 0x10000,
  29. WS_MINIMIZE = 0x20000000,
  30. WS_MINIMIZEBOX = 0x20000,
  31. WS_OVERLAPPED = 0x0,
  32. WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
  33. WS_POPUP = 0x80000000u,
  34. WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU,
  35. WS_SYSMENU = 0x80000,
  36. WS_TABSTOP = 0x10000,
  37. WS_THICKFRAME = 0x40000,
  38. WS_VISIBLE = 0x10000000,
  39. WS_VSCROLL = 0x200000,
  40. WS_EX_DLGMODALFRAME = 0x00000001,
  41. WS_EX_NOPARENTNOTIFY = 0x00000004,
  42. WS_EX_NOREDIRECTIONBITMAP = 0x00200000,
  43. WS_EX_TOPMOST = 0x00000008,
  44. WS_EX_ACCEPTFILES = 0x00000010,
  45. WS_EX_TRANSPARENT = 0x00000020,
  46. WS_EX_MDICHILD = 0x00000040,
  47. WS_EX_TOOLWINDOW = 0x00000080,
  48. WS_EX_WINDOWEDGE = 0x00000100,
  49. WS_EX_CLIENTEDGE = 0x00000200,
  50. WS_EX_CONTEXTHELP = 0x00000400,
  51. WS_EX_RIGHT = 0x00001000,
  52. WS_EX_LEFT = 0x00000000,
  53. WS_EX_RTLREADING = 0x00002000,
  54. WS_EX_LTRREADING = 0x00000000,
  55. WS_EX_LEFTSCROLLBAR = 0x00004000,
  56. WS_EX_RIGHTSCROLLBAR = 0x00000000,
  57. WS_EX_CONTROLPARENT = 0x00010000,
  58. WS_EX_STATICEDGE = 0x00020000,
  59. WS_EX_APPWINDOW = 0x00040000,
  60. WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
  61. WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
  62. WS_EX_LAYERED = 0x00080000,
  63. WS_EX_NOINHERITLAYOUT = 0x00100000,
  64. WS_EX_LAYOUTRTL = 0x00400000,
  65. WS_EX_COMPOSITED = 0x02000000,
  66. WS_EX_NOACTIVATE = 0x08000000
  67. }
  68. [DllImport("user32.dll", SetLastError = true)]
  69. public static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  70. [DllImport("user32.dll", SetLastError = true)]
  71. public static extern bool DestroyWindow(IntPtr hwnd);
  72. [DllImport("kernel32.dll")]
  73. public static extern IntPtr GetModuleHandle(string? lpModuleName);
  74. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  75. public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
  76. [DllImport("user32.dll", SetLastError = true)]
  77. public static extern IntPtr CreateWindowEx(
  78. int dwExStyle,
  79. string lpClassName,
  80. string lpWindowName,
  81. uint dwStyle,
  82. int x,
  83. int y,
  84. int nWidth,
  85. int nHeight,
  86. IntPtr hWndParent,
  87. IntPtr hMenu,
  88. IntPtr hInstance,
  89. IntPtr lpParam);
  90. [DllImport("user32.dll", SetLastError = true)]
  91. public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
  92. [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  93. public static extern bool SetWindowText(IntPtr hwnd, String lpString);
  94. [DllImport("user32.dll")]
  95. public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);
  96. [StructLayout(LayoutKind.Sequential)]
  97. public struct TRACKMOUSEEVENT
  98. {
  99. public int cbSize;
  100. public uint dwFlags;
  101. public IntPtr hwndTrack;
  102. public uint dwHoverTime;
  103. }
  104. }