|
| 1 | +using System; |
| 2 | +using System.Runtime.InteropServices; |
| 3 | + |
| 4 | +namespace TaskbarHook |
| 5 | +{ |
| 6 | + internal static class User32 |
| 7 | + { |
| 8 | + #region DLLImports |
| 9 | + [DllImport("user32.dll", SetLastError = true)] |
| 10 | + private static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd); |
| 11 | + |
| 12 | + [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)] |
| 13 | + private static extern IntPtr GetParent(IntPtr hWnd); |
| 14 | + |
| 15 | + [DllImport("user32.dll", CharSet = CharSet.Unicode)] |
| 16 | + private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle); |
| 17 | + |
| 18 | + [DllImport("user32.dll", SetLastError = true)] |
| 19 | + private static extern bool GetWindowRect(IntPtr hwnd, out Rectangle lpRect); |
| 20 | + |
| 21 | + [DllImport("user32.dll", SetLastError = true)] |
| 22 | + private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); |
| 23 | + |
| 24 | + [DllImport("user32.dll", EntryPoint = "SetWindowPos")] |
| 25 | + private static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags); |
| 26 | + |
| 27 | + [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)] |
| 28 | + private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); |
| 29 | + #endregion |
| 30 | + |
| 31 | + internal static bool SetWindowPosition(IntPtr handle, int x, int y) => SetWindowPos(handle, 0, x, y, 0, 0, 0x0001) != IntPtr.Zero; |
| 32 | + |
| 33 | + internal static IntPtr SetWindowParent(IntPtr parent, IntPtr child) => SetParent(child, parent); |
| 34 | + |
| 35 | + internal static bool HideWindow(IntPtr handle) => SetVisibilityState(handle, 0); |
| 36 | + |
| 37 | + internal static bool ShowWindow(IntPtr handle) => SetVisibilityState(handle, 5); |
| 38 | + |
| 39 | + internal static bool SetVisibilityState(IntPtr handle, int state) => ShowWindow(handle, state); |
| 40 | + |
| 41 | + internal static IntPtr GetWindowParent(IntPtr handle) => GetParent(handle); |
| 42 | + |
| 43 | + internal static IntPtr GetWindow(string className) => GetWindow(IntPtr.Zero, className); |
| 44 | + |
| 45 | + internal static IntPtr GetWindow(IntPtr parentHandle, string className) => FindWindowEx(parentHandle, IntPtr.Zero, className, string.Empty); |
| 46 | + |
| 47 | + internal static IntPtr GetFirstWindowChild(IntPtr parentHandle) => GetWindow(parentHandle, 5); |
| 48 | + |
| 49 | + internal static Rectangle GetWindowRectangle(IntPtr handle) |
| 50 | + { |
| 51 | + Rectangle rectangle = new Rectangle(); |
| 52 | + GetWindowRect(handle, out rectangle); |
| 53 | + return rectangle; |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments