示例#1
0
        public static IntPtr GetProcessWnd(uint pid)
        {
            var ptrWnd = IntPtr.Zero;

            var ret = Win32Funcs.EnumWindowsWrapper((hWnd, lParam) =>
            {
                if (IntPtr.Zero.Equals(Win32Funcs.GetParentWrapper(hWnd)))
                {
                    int id;
                    Win32Funcs.GetWindowThreadProcessIdWrapper(hWnd, out id);
                    if (new IntPtr(id).Equals(lParam))
                    {
                        ptrWnd = hWnd;
                        Win32Funcs.SetLastErrorWrapper(0);
                        return(false);
                    }
                }

                return(true);
            }, new IntPtr(pid));

            return((!ret && Marshal.GetLastWin32Error() == 0) ? ptrWnd : IntPtr.Zero);
        }