Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.09 KB | None | 0 0
  1. // EnumWindows
  2.         [DllImport("user32.dll")]
  3.         private static extern bool EnumWindows(CallBackPtr enumProc, int lParam);
  4.  
  5.         // EnumChildWindows
  6.         [DllImport("user32.dll")]
  7.         [return: MarshalAs(UnmanagedType.Bool)]
  8.         public static extern bool EnumChildWindows(IntPtr hwnd, CallBackPtr enumProc, IntPtr lParam);
  9.  
  10.         // GetWindowLong
  11.         [DllImport("user32.dll", SetLastError = true)]
  12.         private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
  13.  
  14.         // SetWindowLong
  15.         [DllImport("user32.dll")]
  16.         static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
  17.  
  18.         // GetWindowText
  19.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  20.         public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
  21.  
  22.         // IsWindowVisible
  23.         [DllImport("user32.dll")]
  24.         [return: MarshalAs(UnmanagedType.Bool)]
  25.         static extern bool IsWindowVisible(IntPtr hWnd);
  26.  
  27.         // IsWindow
  28.         [DllImport("user32.dll")]
  29.         [return: MarshalAs(UnmanagedType.Bool)]
  30.         static extern bool IsWindow(IntPtr hWnd);
  31.  
  32.         // GetAncestor
  33.         [DllImport("user32.dll", ExactSpelling = true)]
  34.         static extern IntPtr GetAncestor(IntPtr hwnd, GetAncestorFlags flags);
  35.         enum GetAncestorFlags
  36.         {
  37.             GA_PARENT = 1, // Retrieves the parent window. This does not include the owner, as it does with the GetParent function.
  38.             GA_ROOT = 2, // Retrieves the root window by walking the chain of parent windows.
  39.             GA_ROOTOWNER = 3 // Retrieves the owned root window by walking the chain of parent and owner windows returned by GetParent.
  40.         }
  41.  
  42.         // GetLastActivePopup
  43.         [DllImport("user32.dll")]
  44.         static extern IntPtr GetLastActivePopup(IntPtr hWnd);
  45.  
  46.         // GetTitleBarInfo
  47.         [DllImport("user32.dll")]
  48.         [return: MarshalAs(UnmanagedType.Bool)]
  49.         static extern bool GetTitleBarInfo(IntPtr hwnd, ref TITLEBARINFO pti);
  50.         [StructLayout(LayoutKind.Sequential)]
  51.         struct TITLEBARINFO
  52.         {
  53.             public const int CCHILDREN_TITLEBAR = 5;
  54.             public uint cbSize;
  55.             public RECT rcTitleBar;
  56.             [MarshalAs(UnmanagedType.ByValArray, SizeConst = CCHILDREN_TITLEBAR + 1)]
  57.             public uint[] rgstate;
  58.         }
  59.  
  60.         // DwmGetWindowAttribute
  61.         [DllImport("dwmapi.dll")]
  62.         static extern int DwmGetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, out bool pvAttribute, int cbAttribute);
  63.         [DllImport("dwmapi.dll")]
  64.         static extern int DwmGetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, out RECT pvAttribute, int cbAttribute);
  65.             enum DWMWINDOWATTRIBUTE : uint
  66.             {
  67.                 NCRenderingEnabled = 1,
  68.                 NCRenderingPolicy,
  69.                 TransitionsForceDisabled,
  70.                 AllowNCPaint,
  71.                 CaptionButtonBounds,
  72.                 NonClientRtlLayout,
  73.                 ForceIconicRepresentation,
  74.                 Flip3DPolicy,
  75.                 ExtendedFrameBounds,
  76.                 HasIconicBitmap,
  77.                 DisallowPeek,
  78.                 ExcludedFromPeek,
  79.                 Cloak,
  80.                 Cloaked,
  81.                 FreezeRepresentation
  82.             }
  83.  
  84.         // GetWindowTextLength
  85.         [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  86.         static extern int GetWindowTextLength(IntPtr hWnd);
  87.  
  88.         // GetWindowThreadProcessID
  89.         [DllImport("user32.dll", SetLastError = true)]
  90.         static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
  91.  
  92.         [DllImport("user32.dll")]
  93.         // When you don't want the ProcessId, use this overload and pass IntPtr.Zero for the second parameter
  94.         static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
  95.  
  96.         // GetWindowRect
  97.         [DllImport("user32.dll")]
  98.         [return: MarshalAs(UnmanagedType.Bool)]
  99.         static extern bool GetWindowRect(HandleRef hWnd, out RECT lpRect);
  100.         [StructLayout(LayoutKind.Sequential)]
  101.         public struct RECT
  102.         {
  103.             public int Left;        // x position of upper-left corner
  104.             public int Top;         // y position of upper-left corner
  105.             public int Right;       // x position of lower-right corner
  106.             public int Bottom;      // y position of lower-right corner
  107.         }
  108.  
  109.         // IsIconic
  110.         [DllImport("user32.dll")]
  111.         [return: MarshalAs(UnmanagedType.Bool)]
  112.         static extern bool IsIconic(IntPtr hWnd);
  113.  
  114.         // OpenProcess
  115.         [DllImport("kernel32.dll", SetLastError = true)]
  116.         public static extern IntPtr OpenProcess(
  117.              ProcessAccessFlags processAccess,
  118.              bool bInheritHandle,
  119.              int processId
  120.         );
  121.         public static IntPtr OpenProcess(System.Diagnostics.Process proc, ProcessAccessFlags flags)
  122.         {
  123.             return OpenProcess(flags, false, proc.Id);
  124.         }
  125.         [Flags]
  126.         public enum ProcessAccessFlags : uint
  127.         {
  128.             All = 0x001F0FFF,
  129.             Terminate = 0x00000001,
  130.             CreateThread = 0x00000002,
  131.             VirtualMemoryOperation = 0x00000008,
  132.             VirtualMemoryRead = 0x00000010,
  133.             VirtualMemoryWrite = 0x00000020,
  134.             DuplicateHandle = 0x00000040,
  135.             CreateProcess = 0x000000080,
  136.             SetQuota = 0x00000100,
  137.             SetInformation = 0x00000200,
  138.             QueryInformation = 0x00000400,
  139.             QueryLimitedInformation = 0x00001000,
  140.             Synchronize = 0x00100000
  141.         }
  142.  
  143.         // CloseHandle
  144.         [DllImport("kernel32.dll", SetLastError = true)]
  145.         static extern bool CloseHandle(IntPtr hHandle);
  146.  
  147.         // GetModuleFilenameEx
  148.         [DllImport("psapi.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
  149.         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