Пример #1
0
        private IntPtr FindMessageBox()
        {
            IntPtr foundWindowHandle = IntPtr.Zero;

            if (handle != new IntPtr(0))
            {
                return(handle);
            }

            IntPtr desktop = Win32.GetDesktopWindow();

            Win32.EnumChildWindows(
                desktop,
                delegate(IntPtr hwnd, IntPtr lParam)
            {
                if (WindowHandle.IsDialog(hwnd))
                {
                    if (name == null || WindowHandle.GetCaption(hwnd) == name)
                    {
                        foundWindowHandle = hwnd;
                    }
                }
                return(1);
            },
                IntPtr.Zero);

            if (foundWindowHandle == IntPtr.Zero)
            {
                throw new ControlNotVisibleException("Message Box not visible");
            }
            return(foundWindowHandle);
        }
Пример #2
0
        /// <summary>
        /// Finds the OpenFileDialog.
        /// </summary>
        protected static IntPtr FindFileDialog()
        {
            IntPtr desktop = Win32.GetDesktopWindow();
            IntPtr res     = IntPtr.Zero;

            Win32.EnumChildWindows(desktop,
                                   delegate(IntPtr hwnd, IntPtr lParam)
            {
                if (WindowHandle.IsDialog(hwnd))
                {
                    string name = WindowHandle.GetCaption(hwnd);
                    if (name == FileDialogTester.InitialFileDialogName
                        // Vista 64 hack
                        || name == "Save as" || name == "Enregistrer sous" || name == "Speichern unter")
                    {
                        res = hwnd;
                    }
                }
                return(1);
            },
                                   IntPtr.Zero);
            if (res == IntPtr.Zero)
            {
                throw new ControlNotVisibleException("Open File Dialog is not visible");
            }
            return(res);
        }
Пример #3
0
 /// <summary>
 /// Finds all of the forms with a specified name and returns them in a FormCollection.
 /// </summary>
 /// <param name="formName">The name of the form to search for.</param>
 /// <returns>the FormCollection of all found forms.</returns>
 public List <Form> FindAll(string formName)
 {
     lock (this)
     {
         forms = new List <Form>();
         name  = formName;
         IntPtr desktop = Win32.GetDesktopWindow();
         Win32.EnumChildWindows(desktop, FindMatchingForms, IntPtr.Zero);
         return(forms);
     }
 }
Пример #4
0
        bool SetFileNameCB(string file)
        {
            if (!Win32.IsWindowVisible(hWnd))
            {
                return(false);
            }
            IntPtr fnh = Win32.GetDlgItem(hWnd, FileNameCheckBox);

            if (fnh == IntPtr.Zero)
            {
                // On Vista 64, it seems the combo box does not have an id. However, it contains a control with id 1001.
                Win32.EnumChildWindows(hWnd,
                                       delegate(IntPtr wnd, IntPtr lparam)
                {
                    if (Win32.GetDlgItem(wnd, 1001) == IntPtr.Zero)
                    {
                        return(1);
                    }
                    fnh = wnd;
                    return(0);
                }, IntPtr.Zero);

                if (fnh == IntPtr.Zero)
                {
                    throw new System.Exception("XunitForms fatal error: cannot find filename box");
                }

                Util.GetMessageHook.Record(delegate()
                {
                    Win32.SetWindowText(fnh, file);
                    StringBuilder sb = new StringBuilder(file.Length + 1);
                    Win32.GetWindowText(fnh, sb, file.Length + 1);
                    if (sb.ToString().ToLowerInvariant() != file.ToString().ToLowerInvariant())
                    {
                        return(false);
                    }

                    IntPtr open_btn = Win32.GetDlgItem(hWnd, OpenButton);
                    Win32.PostMessage(open_btn, Win32.BM_CLICK, (IntPtr)0, IntPtr.Zero);

                    return(true);
                });
            }
            else
            {
                Win32.SetDlgItemText(hWnd, FileNameCheckBox, file);

                StringBuilder sb = new StringBuilder(file.Length + 1);
                Win32.GetDlgItemText(hWnd, FileNameCheckBox, sb, file.Length + 1);

                if (sb.ToString().ToLowerInvariant() != file.ToString().ToLowerInvariant())
                {
                    return(false);
                }

                IntPtr open_btn = Win32.GetDlgItem(hWnd, OpenButton);
                Win32.PostMessage(open_btn, Win32.BM_CLICK, (IntPtr)0, IntPtr.Zero);
                return(true);
            }

            return(true);
        }