Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // EnumWindows
- [DllImport("user32.dll")]
- private static extern bool EnumWindows(CallBackPtr enumProc, int lParam);
- // EnumChildWindows
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool EnumChildWindows(IntPtr hwnd, CallBackPtr enumProc, IntPtr lParam);
- // GetWindowLong
- [DllImport("user32.dll", SetLastError = true)]
- private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
- // SetWindowLong
- [DllImport("user32.dll")]
- static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
- // GetWindowText
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
- // IsWindowVisible
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool IsWindowVisible(IntPtr hWnd);
- // IsWindow
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool IsWindow(IntPtr hWnd);
- // GetAncestor
- [DllImport("user32.dll", ExactSpelling = true)]
- static extern IntPtr GetAncestor(IntPtr hwnd, GetAncestorFlags flags);
- enum GetAncestorFlags
- {
- GA_PARENT = 1, // Retrieves the parent window. This does not include the owner, as it does with the GetParent function.
- GA_ROOT = 2, // Retrieves the root window by walking the chain of parent windows.
- GA_ROOTOWNER = 3 // Retrieves the owned root window by walking the chain of parent and owner windows returned by GetParent.
- }
- // GetLastActivePopup
- [DllImport("user32.dll")]
- static extern IntPtr GetLastActivePopup(IntPtr hWnd);
- // GetTitleBarInfo
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool GetTitleBarInfo(IntPtr hwnd, ref TITLEBARINFO pti);
- [StructLayout(LayoutKind.Sequential)]
- struct TITLEBARINFO
- {
- public const int CCHILDREN_TITLEBAR = 5;
- public uint cbSize;
- public RECT rcTitleBar;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = CCHILDREN_TITLEBAR + 1)]
- public uint[] rgstate;
- }
- // DwmGetWindowAttribute
- [DllImport("dwmapi.dll")]
- static extern int DwmGetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, out bool pvAttribute, int cbAttribute);
- [DllImport("dwmapi.dll")]
- static extern int DwmGetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, out RECT pvAttribute, int cbAttribute);
- enum DWMWINDOWATTRIBUTE : uint
- {
- NCRenderingEnabled = 1,
- NCRenderingPolicy,
- TransitionsForceDisabled,
- AllowNCPaint,
- CaptionButtonBounds,
- NonClientRtlLayout,
- ForceIconicRepresentation,
- Flip3DPolicy,
- ExtendedFrameBounds,
- HasIconicBitmap,
- DisallowPeek,
- ExcludedFromPeek,
- Cloak,
- Cloaked,
- FreezeRepresentation
- }
- // GetWindowTextLength
- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- static extern int GetWindowTextLength(IntPtr hWnd);
- // GetWindowThreadProcessID
- [DllImport("user32.dll", SetLastError = true)]
- static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
- [DllImport("user32.dll")]
- // When you don't want the ProcessId, use this overload and pass IntPtr.Zero for the second parameter
- static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
- // GetWindowRect
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool GetWindowRect(HandleRef hWnd, out RECT lpRect);
- [StructLayout(LayoutKind.Sequential)]
- public struct RECT
- {
- public int Left; // x position of upper-left corner
- public int Top; // y position of upper-left corner
- public int Right; // x position of lower-right corner
- public int Bottom; // y position of lower-right corner
- }
- // IsIconic
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool IsIconic(IntPtr hWnd);
- // OpenProcess
- [DllImport("kernel32.dll", SetLastError = true)]
- public static extern IntPtr OpenProcess(
- ProcessAccessFlags processAccess,
- bool bInheritHandle,
- int processId
- );
- public static IntPtr OpenProcess(System.Diagnostics.Process proc, ProcessAccessFlags flags)
- {
- return OpenProcess(flags, false, proc.Id);
- }
- [Flags]
- public enum ProcessAccessFlags : uint
- {
- All = 0x001F0FFF,
- Terminate = 0x00000001,
- CreateThread = 0x00000002,
- VirtualMemoryOperation = 0x00000008,
- VirtualMemoryRead = 0x00000010,
- VirtualMemoryWrite = 0x00000020,
- DuplicateHandle = 0x00000040,
- CreateProcess = 0x000000080,
- SetQuota = 0x00000100,
- SetInformation = 0x00000200,
- QueryInformation = 0x00000400,
- QueryLimitedInformation = 0x00001000,
- Synchronize = 0x00100000
- }
- // CloseHandle
- [DllImport("kernel32.dll", SetLastError = true)]
- static extern bool CloseHandle(IntPtr hHandle);
- // GetModuleFilenameEx
- [DllImport("psapi.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
- static extern uint GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, [Out] System.Text.StringBuilder lpBaseName, uint nSize);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement