예제 #1
0
        private void FocusFirstControl(bool forAddControl)
        {
            Control c;

            for (int i = 0; i < base.Count; ++i)
            {
                c = base[i] as System.Windows.Forms.Control;
                if (c != null && c.TabStop && !base[i].ReadOnly)
                //&& ((forAddControl && base[i].Insertable) || (!forAddControl && base[i].Editable)))
                {
                    IWindowControl wc = c as IWindowControl;
                    if (wc != null)
                    {
                        if (wc.Control.CanSelect)
                        {
                            wc.Control.Select();
                            return;
                        }
                    }
                    else
                    {
                        if (c.CanSelect)
                        {
                            c.Select();
                            return;
                        }
                    }
                }
            }
        }
예제 #2
0
        //----

        public MyCefBrowser(IWindowControl parentControl,
                            int x, int y, int w, int h, string initUrl, bool isOsr)
        {
            this.currentUrl = initUrl;
            //create cef browser view handler
            this.parentControl = parentControl;
            this.topForm       = (IWindowForm)parentControl.GetTopLevelControl();
            //ui process ***
            this.managedCallback = new MyCefCallback(this.MxCallBack);
            //for specific browser
            if (this.IsOsr = isOsr)
            {
                this.myCefBrowser = Cef3Binder.MyCefCreateMyWebBrowserOSR(managedCallback);
                Cef3Binder.MyCefSetupBrowserHwndOSR(myCefBrowser, parentControl.GetHandle(), x, y, w, h, initUrl, IntPtr.Zero);
            }
            else
            {
                this.myCefBrowser = Cef3Binder.MyCefCreateMyWebBrowser(managedCallback);
                Cef3Binder.MyCefSetupBrowserHwnd(myCefBrowser, parentControl.GetHandle(), x, y, w, h, initUrl, IntPtr.Zero);
            }

            Cef3Binder.MyCefEnableKeyIntercept(myCefBrowser, 1);
            //register mycef browser
            RegisterCefWbControl(this);
        }
        /// <summary>
        /// 缺省处理ControlValueNullException方式
        /// </summary>
        /// <param name="ex"></param>
        public void ShowError(object invalidControl, string msg)
        {
            if (invalidControl == null)
            {
                throw new ArgumentNullException("invalidControl");
            }

            IWindowControl windowControl = invalidControl as IWindowControl;

            if (windowControl != null)
            {
                //ClearError();

                if (m_firstInvalidControl == null)
                {
                    m_firstInvalidControl = windowControl.Control;
                    //if (ex.InvalidDataControl is Feng.Windows.Forms.DataControlWrapper)
                    //{
                    //    m_invalidControl = ex.InvalidDataControl as Control;
                    //}
                    m_firstInvalidControl.Focus();
                }

                ShowErrorIcon(windowControl.Control, msg);
            }
            else
            {
                ServiceProvider.GetService <IMessageBox>().ShowWarning(msg);
            }
        }
예제 #4
0
 public CefWebBrowserControl()
 {
     SetStyle(
         ControlStyles.ContainerControl
         | ControlStyles.ResizeRedraw
         | ControlStyles.FixedWidth
         | ControlStyles.FixedHeight
         | ControlStyles.StandardClick
         | ControlStyles.UserMouse
         | ControlStyles.SupportsTransparentBackColor
         | ControlStyles.StandardDoubleClick
         | ControlStyles.OptimizedDoubleBuffer
         | ControlStyles.CacheText
         | ControlStyles.EnableNotifyMessage
         | ControlStyles.DoubleBuffer
         | ControlStyles.OptimizedDoubleBuffer
         | ControlStyles.UseTextForAccessibility
         | ControlStyles.Opaque,
         false);
     SetStyle(
         ControlStyles.UserPaint
         | ControlStyles.AllPaintingInWmPaint
         | ControlStyles.Selectable,
         true);
     thisWindowControl = MyWindowControl.TryGetWindowControlOrRegisterIfNotExists(this);
 }
예제 #5
0
        public MyCefBrowser(IWindowControl parentControl,
                            int x, int y, int w, int h, string initUrl, bool isOsr)
        {
            //global handler
            this.managedCallback = new MyCefCallback(this.HandleNativeReq);

            //cef-specific collection of cef-handler
            myBwHandler = new MyCefBwHandler(this);
            //---------------------------------------------------------------
            this.currentUrl = initUrl;
            //create cef browser view handler
            this.parentControl = parentControl;
            this.topForm       = parentControl.GetTopLevelControl() as IWindowForm;


            //for specific browser
            if (this.IsOsr = isOsr)
            {
                _myCefBw = new MyCefBw(Cef3Binder.MyCefCreateMyWebBrowserOSR(managedCallback));
                Cef3Binder.MyCefSetupBrowserHwndOSR(_myCefBw.ptr, parentControl.GetHandle(), x, y, w, h, initUrl, IntPtr.Zero);
            }
            else
            {
                _myCefBw = new MyCefBw(Cef3Binder.MyCefCreateMyWebBrowser(managedCallback));
                Cef3Binder.MyCefSetupBrowserHwnd(_myCefBw.ptr, parentControl.GetHandle(), x, y, w, h, initUrl, IntPtr.Zero);
            }


            Cef3Binder.MyCefBwCall(this._myCefBw.ptr, CefBwCallMsg.CefBw_MyCef_EnableKeyIntercept, 1);

            //register mycef browser
            RegisterCefWbControl(this);
        }
예제 #6
0
        static void Main(string[] args)
        {
            IntPtr windowHandle = NativeMethodsHelper.GetWindowByTitle("Test Form");

            /*
             * Test sub-controls of a window.
             */
            IWindowControlHandler        windowsControlHandler = new WindowControlHandler(null);
            IWindowControl               window = windowsControlHandler.GetWindowControl(windowHandle);
            IEnumerable <IWindowControl> childs = window.GetChildControls();

            object windowTitle = window.GetControlValue();

            Console.WriteLine($"Window title: { windowTitle }");

            Console.WriteLine($"Child controls values:");
            for (int i = 0; i < childs.Count(); ++i)
            {
                IWindowControl child             = childs.ElementAt(i);
                object         childControlValue = child.GetControlValue();
                Console.WriteLine($"{ i } - { childControlValue }");

                // Test button clicking.
                if (childControlValue.Equals("Test Button Text"))
                {
                    child.Click();
                }
            }

            for (int i = 0; i < childs.Count(); ++i)
            {
                IEnumerable <IWindowControl> childChilds = childs.ElementAt(i).GetChildControls();
                Console.WriteLine("");
            }
        }
예제 #7
0
        /// <summary>
        /// Finds any child window from specified that has a text value equals to specified.
        /// </summary>
        public static IWindowControl GetWindowControlByText(IWindowControl mainControl, string controlText)
        {
            object controlValue = mainControl.GetControlValue();
            string text         = controlValue.ToString();

            if (text.Equals(controlText))
            {
                return(mainControl);
            }

            IWindowControl foundControl         = null;
            IEnumerable <IWindowControl> childs = mainControl.GetChildControls();

            foreach (IWindowControl child in childs)
            {
                foundControl = GetWindowControlByText(child, controlText);

                if (foundControl != null)
                {
                    controlValue = foundControl.GetControlValue();
                    text         = controlValue.ToString();

                    if (text.Equals(controlText))
                    {
                        break;
                    }
                }
            }

            return(foundControl);
        }
예제 #8
0
    protected void ConfigureChildWindow(RCPChildWindow window, IWindowControl windowContent, bool isModal)
    {
        // Place the content within a transitioning content control for a transition when the window is opened
        var content = new TransitioningContentControl()
        {
            FocusVisualStyle  = null,
            IsTabStop         = false,
            Transition        = Data.UI_EnableAnimations ? TransitionType.Left : TransitionType.Normal,
            UseLayoutRounding = true,
            Content           = windowContent.UIContent,
            RestartTransitionOnContentChange = true
        };

        // For some reason the transition doesn't start automatically here, so we manually reload it on load (might be because the Loaded event fires twice, probably once before it gets shown)
        void Content_Loaded(object s, RoutedEventArgs e) => content.ReloadTransition();

        void Content_Unloaded(object s, RoutedEventArgs e)
        {
            // Make sure to unsubscribe to the events
            content.Unloaded -= Content_Unloaded;
            content.Loaded   -= Content_Loaded;
        }

        content.Loaded   += Content_Loaded;
        content.Unloaded += Content_Unloaded;

        // Set window properties
        window.Content     = content;
        window.IsModal     = isModal;
        window.CanMaximize = windowContent.IsResizable;
    }
예제 #9
0
    protected override Task ShowAsync(IWindowControl windowContent, bool isModal, string title)
    {
        // Show as a child window
        if (Data.UI_UseChildWindows && App.Current?.ChildWindowsParent is MetroWindow metroWindow)
        {
            // Create the child window
            var childWin = new RCPChildWindow();

            // Configure the window
            ConfigureChildWindow(childWin, windowContent, isModal);

            // Set the window instance
            windowContent.WindowInstance = new ChildWindowInstance(childWin);

            // Set the title
            if (title != null)
            {
                windowContent.WindowInstance.Title = title;
            }

            // Show the window
            return(metroWindow.ShowChildWindowAsync(childWin));
        }
        // or show as a normal window
        else
        {
            return(base.ShowAsync(windowContent, isModal, title));
        }
    }
예제 #10
0
        public static void DisposeAllChildWebBrowserControls(IWindowForm ownerForm)
        {
            //dispose all web browser (child) windows inside this window form
            List <MyCefBrowser> foundList;

            if (registerTopWindowForms.TryGetValue(ownerForm, out foundList))
            {
                //remove webbrowser controls
                for (int i = foundList.Count - 1; i >= 0; --i)
                {
                    MyCefBrowser   mycefBw = foundList[i];
                    IWindowControl wb      = mycefBw.ParentControl;
                    mycefBw.NotifyCloseBw();
                    //---------------------------------------
                    var parent = wb.GetParent();
                    parent.RemoveChild(wb);

                    //this Dispose() will terminate cef_life_time_handle ***
                    //after native side dispose the wb control
                    //it will raise event BrowserDisposed
                    wb.Dispose();

                    //---------------------------------------
                }
                registerTopWindowForms.Remove(ownerForm);
            }
        }
예제 #11
0
        /// <summary>
        /// 添加。
        /// 处理Enter KeyPress事件,
        /// </summary>
        /// <param name="item"></param>
        public override void Add(ISearchControl item)
        {
            base.Add(item);

            IWindowControl outerControl = item as IWindowControl;

            if (outerControl != null)
            {
                outerControl.Control.KeyPress += new System.Windows.Forms.KeyPressEventHandler(InputBox_KeyPress);
            }
            else
            {
                IWindowControlBetween lfcb = item as IWindowControlBetween;
                if (lfcb != null)
                {
                    System.Windows.Forms.Control control = lfcb.Control1 as System.Windows.Forms.Control;
                    if (control != null)
                    {
                        control.KeyPress += new System.Windows.Forms.KeyPressEventHandler(InputBox_KeyPress);
                    }
                    control = lfcb.Control2 as System.Windows.Forms.Control;
                    if (control != null)
                    {
                        control.KeyPress += new System.Windows.Forms.KeyPressEventHandler(InputBox_KeyPress);
                    }
                }
            }
        }
예제 #12
0
    protected Task ShowWindowAsync(IWindowControl windowContent, bool isModal, string title)
    {
        // Get the dispatcher
        Dispatcher dispatcher = GetDispatcher();

        // Run on UI thread
        return(dispatcher.Invoke(() => ShowAsync(windowContent, isModal, title)));
    }
예제 #13
0
        protected bool CanMakeMove()
        {
            IWindowControl mainControl        = this.LearningModule.Bot.ConnectionHandler.ConnectedProcesses.ElementAt(0).WindowHandle.ToWindowControl();
            IWindowControl playerCharGroupBox = NativeMethodsHelper.GetWindowControlByText(mainControl, TttSettings.CURRENT_PLAYER_TURN);
            IWindowControl charControl        = playerCharGroupBox.GetChildControls().FirstOrDefault();
            string         tttChar            = charControl.GetControlValue().ToString();

            return(this.TttChar.Equals(tttChar));
        }
예제 #14
0
        private string FindCurrentPlayerChar()
        {
            IWindowControl mainControl        = new WindowControl(this.WindowPtr, null);
            IWindowControl playerCharGroupBox = NativeMethodsHelper.GetWindowControlByText(mainControl, "Current Player Turn");
            IWindowControl charControl        = playerCharGroupBox.GetChildControls().FirstOrDefault();
            string         tttChar            = charControl.GetControlValue().ToString();

            return(tttChar);
        }
예제 #15
0
    public async Task ShowWindowAsync(IWindowControl windowContent, ShowWindowFlags flags = ShowWindowFlags.None, params string[] groupNames)
    {
        var openWindowInstance = new OpenWindowInstance(new WeakReference <IWindowControl>(windowContent), groupNames);

        try
        {
            // Remove instances which have been collected by the GC
            OpenWindows.RemoveWhere(x => !x.Window.TryGetTarget(out _));

            Type contentType = windowContent.UIContent.GetType();

            IWindowControl blockingWindow = OpenWindows.
                                            Select(x => x.Window.TryGetTarget(out IWindowControl w) ? new { Window = w, x.GroupNames } : null).
                                            FirstOrDefault(x =>
            {
                // Check for duplicate types
                if (!flags.HasFlag(ShowWindowFlags.DuplicateTypesAllowed) && x?.Window.UIContent.GetType() == contentType)
                {
                    return(true);
                }

                // Check for duplicate group names
                if (groupNames.Any() && x?.GroupNames.Any(groupNames.Contains) == true)
                {
                    return(true);
                }

                return(false);
            })?.Window;

            // If there is a window blocking this one from showing we return
            if (blockingWindow != null)
            {
                Logger.Info("The window is not being shown due to a window of the same type or ID being available", contentType);

                // Focus the blocking window
                if (!flags.HasFlag(ShowWindowFlags.DoNotFocusBlockingWindow))
                {
                    blockingWindow.WindowInstance?.Focus();
                }

                return;
            }

            OpenWindows.Add(openWindowInstance);

            // Show the window
            await ShowWindowAsync(windowContent, false, null);
        }
        finally
        {
            OpenWindows.Remove(openWindowInstance);

            windowContent.Dispose();
        }
    }
예제 #16
0
        private IEnumerable <IWindowControl> FindButtons()
        {
            IConnectedProcess            gameProcess       = this.GetGameProcess();
            IntPtr                       windowHandler     = gameProcess.WindowHandle;
            IWindowControl               mainWindowControl = windowHandler.ToWindowControl();
            IWindowControl               buttonsGroupBox   = NativeMethodsHelper.GetWindowControlByText(mainWindowControl, TttSettings.BUTTONS);
            IEnumerable <IWindowControl> buttons           = buttonsGroupBox.GetChildControls();

            return(buttons);
        }
예제 #17
0
 public void SetContent(IWindowControl windowControl)
 {
     if (!(windowControl is UIElement))
     {
         throw new ArgumentException("WindowControl has to be UIElement");
     }
     ClearContent();
     wpFillContent.Children.Add(windowControl as UIElement);
     this.ManagePropertyChangeNotificationSubscription(wpFillContent, PropertyChangeNotificationOperation.Subscribe);
 }
예제 #18
0
    protected void ConfigureWindow(Window window, IWindowControl windowContent)
    {
        // Set window properties
        window.Content       = windowContent.UIContent;
        window.ResizeMode    = windowContent.IsResizable ? ResizeMode.CanResize : ResizeMode.NoResize;
        window.SizeToContent = windowContent.IsResizable ? SizeToContent.Manual : SizeToContent.WidthAndHeight;

        if (!windowContent.IsResizable)
        {
            window.MinWidth  = 50;
            window.MinHeight = 50;
        }

        // Set startup location
        window.WindowStartupLocation = window.Owner == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner;
    }
예제 #19
0
        /// <summary>
        /// 处理异常
        /// </summary>
        /// <param name="ex"></param>
        public void ShowError(object invalidControl, string msg)
        {
            IWindowControl windowControl = invalidControl as IWindowControl;

            if (windowControl != null)
            {
                //ClearAllError();

                m_invalidControl           = windowControl.Control;
                m_bakColor                 = m_invalidControl.BackColor;
                m_invalidControl.BackColor = System.Drawing.Color.Pink;
            }
            else
            {
                ServiceProvider.GetService <IMessageBox>().ShowWarning(msg);
            }
        }
예제 #20
0
        static void PrintTexts(IEnumerable <IWindowControl> controls, int level)
        {
            for (int i = 0; i < controls.Count(); ++i)
            {
                IWindowControl groupBox      = controls.ElementAt(i);
                object         groupBoxValue = groupBox.GetControlValue();
                string         groupBoxText  = groupBoxValue.ToString();

                StringBuilder builder = new StringBuilder();
                for (int j = 0; j < level; ++j)
                {
                    builder.Append("-");
                }

                Console.WriteLine($"{ i }. { builder.ToString() } { groupBoxText }");
                PrintTexts(groupBox.GetChildControls(), level + 1);
            }
        }
예제 #21
0
        private Control GetControl(IDataControl dc)
        {
            Control        vc  = null;
            IWindowControl ldc = dc as IWindowControl;

            if (ldc != null)
            {
                vc = ldc.Control;
            }
            else
            {
                Control c = dc as Control;
                if (c != null)
                {
                    vc = c;
                }
            }
            return(vc);
        }
예제 #22
0
    protected virtual async Task ShowAsync(IWindowControl windowContent, bool isModal, string title)
    {
        // Create the window
        var window = new BaseIconWindow();

        // Configure the window
        ConfigureWindow(window, windowContent);

        // Set the window instance
        windowContent.WindowInstance = new StandardWindowInstance(window);

        // Set the title
        if (title != null)
        {
            windowContent.WindowInstance.Title = title;
        }

        if (isModal)
        {
            // Show the window as a dialog
            window.ShowDialog();
        }
        else
        {
            var tcs = new TaskCompletionSource <object>();

            void Window_Closed(object sender, EventArgs e)
            {
                window.Closed -= Window_Closed;
                tcs.TrySetResult(null);
            }

            window.Closed += Window_Closed;

            // Show the window
            window.Show();

            // Wait for the window to close
            await tcs.Task;
        }
    }
예제 #23
0
        static void Main(string[] args)
        {
            Process notepadProcess1 = StartNotepad();
            Process notepadProcess2 = StartNotepad();

            // Create connection handler and connection tools for Windows with double-side binding.
            var connectionHandler = new WindowsConnectionHandler(null);

            connectionHandler.AttachToProcess(notepadProcess1, IntPtr.Zero);
            connectionHandler.AttachToProcess(notepadProcess2, IntPtr.Zero);

            // Print all connected processes
            for (int i = 0; i < connectionHandler.ConnectedProcesses.Count; ++i)
            {
                IConnectedProcess connectedProcess = connectionHandler.ConnectedProcesses.ElementAt(i);
                Process           process          = connectedProcess.Process;
                Console.WriteLine($"{ i }. { process.ProcessName }, ProcessId: { process.Id }");
            }
            Console.WriteLine();

            //
            // Test - Return value from specified control. Use only in-AutoBot relations.
            //
            IWindowControlHandler        windowsControlHandler = new WindowControlHandler(connectionHandler.PlatformConnectionTools);
            IConnectedProcess            notepad1       = windowsControlHandler.PlatformConnectionTools.ConnectionHandler.ConnectedProcesses.ElementAt(0);
            IWindowControl               windowsControl = windowsControlHandler.GetWindowControl(notepad1.Process.MainWindowHandle);
            IEnumerable <IWindowControl> childs         = windowsControl.GetChildControls();

            object controlValue = windowsControl.GetControlValue();

            Console.WriteLine($"Control value: { controlValue }");

            Console.WriteLine($"Child controls values:");
            for (int i = 0; i < childs.Count(); ++i)
            {
                Console.WriteLine($"{ i } - { childs.ElementAt(i).GetControlValue() }");
            }

            Console.ReadKey();
        }
예제 #24
0
        static void Main(string[] args)
        {
            IntPtr windowPtr = NativeMethodsHelper.GetWindowByTitle("TicTacToe");

            // Find TextBox with current player char
            IWindowControl windowControl            = new WindowControl(windowPtr, null);
            IEnumerable <IWindowControl> groupBoxes = windowControl.GetChildControls();

            PrintTexts(groupBoxes, 1);
            IWindowControl control = NativeMethodsHelper.GetWindowControlByText(windowControl, "Current Player Turn");
            string         text    = control.GetControlValue().ToString();

            Console.WriteLine(text);

            // Check current player char
            IWindowControl charControl = control.GetChildControls().FirstOrDefault();
            string         tttChar     = charControl.GetControlValue().ToString();

            Console.WriteLine(tttChar);

            Console.ReadKey();
        }
예제 #25
0
 public AbstractWindowControl(IntPtr controlHandler, IWindowControl parentControl)
 {
     this.ControlHandler = controlHandler;
     this.ParentControl  = parentControl;
 }
예제 #26
0
 public static IWindowControl ToWindowControl(this IntPtr windowHandle, IWindowControl parentControl = null)
 {
     return(new WindowControl(windowHandle, parentControl));
 }
예제 #27
0
 public void RemoveChild(IWindowControl child)
 {
 }
예제 #28
0
        void IWindowControl.RemoveChild(IWindowControl child)
        {
            var child1 = (MyWindowControl)child;

            this.control.Controls.Remove(child1.control);
        }
예제 #29
0
        private void PressButton(IEnumerable <IWindowControl> buttons, Point boardCell)
        {
            IWindowControl button = buttons.ElementAt(boardCell.X * BOARD_SIZE + boardCell.Y);

            this.NextAction = () => button.Click();
        }
예제 #30
0
        private static void SetSearchControlsValues(ISearchManager sm, bool allEmpty = false)
        {
            foreach (ISearchControl sc in sm.SearchControls)
            {
                if (allEmpty)
                {
                    sc.SelectedDataValues = null;
                }
                else
                {
                    IWindowControl wc = sc as IWindowControl;
                    if (wc != null)
                    {
                        MyComboBox c = wc.Control as MyComboBox;
                        if (c != null && c.Items.Count > 0)
                        {
                            c.SelectedIndex = 0;
                            continue;
                        }
                        else
                        {
                            MyOptionPicker op = wc.Control as MyOptionPicker;
                            if (op != null && op.DropDownControl.DataRows.Count > 0)
                            {
                                op.DropDownControl.DataRows[0].Cells[Feng.Grid.Columns.CheckColumn.DefaultSelectColumnName].Value = true;
                                continue;
                            }
                        }
                    }
                    System.Collections.ArrayList arr = new System.Collections.ArrayList {
                    };
                    if (sc.ResultType == typeof(DateTime))
                    {
                        arr.Add(System.DateTime.Today);
                    }
                    else if (sc.ResultType == typeof(int))
                    {
                        arr.Add(1);
                    }
                    else if (sc.ResultType == typeof(long))
                    {
                        arr.Add(1L);
                    }
                    else if (sc.ResultType == typeof(string))
                    {
                        arr.Add("1");
                    }
                    else if (sc.ResultType == typeof(double))
                    {
                        arr.Add(1.1d);
                    }
                    else if (sc.ResultType == typeof(decimal))
                    {
                        arr.Add(1.1m);
                    }
                    else if (sc.ResultType == typeof(bool))
                    {
                        arr.Add(true);
                    }

                    sc.SelectedDataValues = arr;
                }
            }
        }
        private static void ShowNotnullIcon(IWindowControl wc)
        {
            if (wc == null)
                return;

            //if (m_notNullIconProvider == null)
            //{
            //    m_notNullIconProvider = new System.Windows.Forms.ErrorProvider();
            //    m_notNullIconProvider.Icon = Feng.PdnResources.GetIconFromImage(Feng.Windows.ImageResource.Get("Icons.asterisk_red.png").Reference);
            //    m_notNullIconProvider.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.NeverBlink;
            //}
            //m_notNullIconProvider.SetIconAlignment(wc.Control, ErrorIconAlignment.MiddleRight);
            //m_notNullIconProvider.SetIconPadding(wc.Control, 0);
            //m_notNullIconProvider.SetError(wc.Control, "必须填写");
        }