示例#1
0
        public static string GetWindowText(IntPtr hWnd)
        {
            // Allocate correct string length first
            int           length = WindowsInterop.GetWindowTextLength(hWnd);
            StringBuilder sb     = new StringBuilder(length + 1);

            WindowsInterop.GetWindowText(hWnd, sb, sb.Capacity);
            return(sb.ToString());
        }
示例#2
0
        private static List <IntPtr> GetRootWindowsOfProcess(int pid)
        {
            List <IntPtr> rootWindows       = GetChildWindows(IntPtr.Zero);
            List <IntPtr> dsProcRootWindows = new List <IntPtr>();

            foreach (IntPtr hWnd in rootWindows)
            {
                WindowsInterop.GetWindowThreadProcessId(hWnd, out uint lpdwProcessId);
                if (lpdwProcessId == pid)
                {
                    dsProcRootWindows.Add(hWnd);
                }
            }
            return(dsProcRootWindows);
        }
示例#3
0
        public static RECT GetClientRect()
        {
            RECT clientRect = new RECT();

            WindowsInterop.GetClientRect(Handle, ref clientRect);

            POINT topLeft = new POINT();

            ClientToScreen(Handle, ref topLeft);

            clientRect.Left    = topLeft.X;
            clientRect.Top     = topLeft.Y;
            clientRect.Right  += topLeft.X;
            clientRect.Bottom += topLeft.Y;

            return(clientRect);
        }
示例#4
0
        private static List <IntPtr> GetChildWindows(IntPtr parent)
        {
            List <IntPtr> result     = new List <IntPtr>();
            GCHandle      listHandle = GCHandle.Alloc(result);

            try
            {
                WindowsInterop.Win32Callback childProc = new WindowsInterop.Win32Callback(EnumWindow);
                WindowsInterop.EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));
            }
            finally
            {
                if (listHandle.IsAllocated)
                {
                    listHandle.Free();
                }
            }
            return(result);
        }