示例#1
0
        public static bool IsPid(uint pid)
        {
            IntPtr hWnd      = IntPtr.Zero;
            IntPtr lngProcId = IntPtr.Zero;;

            hWnd = User32API.GetDesktopWindow();
            hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_CHILD);
            while (hWnd != IntPtr.Zero)
            {
                //Console.WriteLine(str);
                User32API.GetWindowThreadProcessId(hWnd, ref lngProcId);
                if ((uint)lngProcId == pid)
                {
                    //if (IsWD)
                    //{
                    //    if (!User32API.IsWindowVisible(hWnd))
                    //    {
                    //        hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_HWNDNEXT);
                    //        continue;
                    //    }
                    //}
                    return(true);
                }
                hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_HWNDNEXT);
            }
            return(false);
        }
示例#2
0
        //user32.dll
        public static IntPtr GetWindow(uint pid, string strTitle)
        {
            IntPtr hWnd      = IntPtr.Zero;
            IntPtr lngProcId = IntPtr.Zero;;

            hWnd = User32API.GetDesktopWindow();
            hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_CHILD);
            string str = string.Empty;

            while (hWnd != IntPtr.Zero)
            {
                str = User32API.GetWindowText(hWnd);

                if (str.IndexOf(strTitle) != -1)
                {
                    //Console.WriteLine(str);
                    User32API.GetWindowThreadProcessId(hWnd, ref lngProcId);
                    if ((uint)lngProcId == pid)
                    {
                        return(hWnd);
                    }
                }
                hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_HWNDNEXT);
            }

            //MainWindowHandle

            return(IntPtr.Zero);
        }
示例#3
0
        //user32.dll
        public static IntPtr GetWindow(uint pid, bool IsWD)
        {
            IntPtr hWnd      = IntPtr.Zero;
            IntPtr lngProcId = IntPtr.Zero;;

            hWnd = User32API.GetDesktopWindow();
            hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_CHILD);
            while (hWnd != IntPtr.Zero)
            {
                //Console.WriteLine(str);
                User32API.GetWindowThreadProcessId(hWnd, ref lngProcId);
                if ((uint)lngProcId == pid)
                {
                    if (IsWD)
                    {
                        if (!User32API.IsWindowVisible(hWnd))
                        {
                            hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_HWNDNEXT);
                            continue;
                        }
                    }
                    return(hWnd);
                }
                hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_HWNDNEXT);
            }
            return(IntPtr.Zero);
        }