//CONSIDER: add mouse xy like in Delm. //CONSIDER: add wnd Activate if pixels from screen. public Duiimage() { Title = "Find image or color in window"; _noeventValueChanged = true; var b = new wpfBuilder(this).WinSize((410, 400..), (380, 330..)).Columns(160, -1); b.R.Add(out _info).Height(60); b.R.StartGrid().Columns(76, 76, 76, -1); //row 1 b.R.AddButton("Capture", _bCapture_Click); b.AddButton(out _bTest, "Test", _Test).Disabled().Tooltip("Executes the code now (except wait/fail/mouse) and shows the found image"); b.AddButton(out _bInsert, "Insert", _Insert).Disabled(); b.Add(out _cbAction).Align("L").Width(140).Items("|MouseMove|MouseClick|MouseClickD|MouseClickR|PostClick|PostClickD|PostClickR|waitNot|new uiimageFinder").Select(2); //row 3 b.R.AddButton("More ▾", _bEtc_Click).Align("L"); b.StartStack(); waitC = b.xAddCheckText("Wait", "1", check: true); b.Width(53); (waitnoC = b.xAddCheckText("Timeout", "5")).Visible = false; b.Width(53); b.xAddCheck(out exceptionC, "Fail if not found").Checked(); b.xAddCheck(out exceptionnoC, "Fail on timeout").Checked().Hidden(null); b.End(); b.End(); //row 4 b.R.AddButton("Window...", _bWnd_Click).And(-70).Add(out controlC, "Control").Disabled(); b.xStartPropertyGrid(); rectC = b.xAddCheckText("Rectangle", "0, 0, ^0, ^0"); b.And(21).AddButton("...", _bRect_Click); wiflagsC = b.xAddCheckCombo("Window pixels", "WindowDC|PrintWindow"); diffC = b.xAddCheckText("Color diff", "10"); skipC = b.xAddCheckText("Skip"); b.xAddCheck(out allC, "Get all", noR: true); b.xEndPropertyGrid(); b.SpanRows(2); b.Row(80).xAddInBorder(out _pict); b.Span(1); b.Row(-1).xAddInBorder(out _code); b.End(); _noeventValueChanged = false; WndSavedRect.Restore(this, App.Settings.wndpos.uiimage, o => App.Settings.wndpos.uiimage = o); }
public void Init() { //_StartProfileOptimization(); Title = App.AppNameLong; //don't append document name etc if (App.Settings.wndpos.main == null) { Width = 1000; Height = 700; WindowStartupLocation = WindowStartupLocation.CenterScreen; //and will EnsureInScreen } WndSavedRect.Restore(this, App.Settings.wndpos.main, o => App.Settings.wndpos.main = o); Panels.LoadAndCreateToolbars(); App.Commands = new KMenuCommands(typeof(Menus), Panels.Menu); App.Commands[nameof(Menus.File.New)].SubmenuOpened = (o, _) => FilesModel.FillMenuNew(o as MenuItem); App.Commands[nameof(Menus.File.Workspace)].SubmenuOpened = (o, _) => FilesModel.FillMenuRecentWorkspaces(o as MenuItem); var atb = new ToolBar[7] { Panels.THelp, Panels.TTools, Panels.TFile, Panels.TRun, Panels.TEdit, Panels.TCustom1, Panels.TCustom2 }; App.Commands.InitToolbarsAndCustomize(folders.ThisAppBS + @"Default\Commands.xml", AppSettings.DirBS + "Commands.xml", atb); var bRun = App.Commands[nameof(Menus.Run.Run_script)].FindButtonInToolbar(Panels.TRun); if (bRun != null) { bRun.Width = 50; bRun.Margin = new(10, 0, 10, 0); } //make Run button bigger //SHOULDDO: bad if vertical toolbar var bNew = App.Commands[nameof(Menus.File.New)].FindMenuButtonInToolbar(Panels.TFile); if (bNew != null) { bNew.MouseDoubleClick += (_, e) => { e.Handled = true; Menus.File.New.New_script(); } } ; Panels.CreatePanels(); App.Commands.BindKeysTarget(this, ""); Panels.PanelManager.Container = g => { this.Content = g; }; //timer.after(100, _ => DOptions.ZShow()); //timer.after(100, _ => App.Model.Properties()); //timer.after(100, _ => Menus.File.Workspace.New_workspace()); //timer.after(100, _ => DIcons.ZShow()); //timer.after(600, _ => Au.Tools.Dwnd.Dialog(wnd.find(null, "Shell_TrayWnd"))); //timer.after(600, _ => Au.Tools.Dwnd.Dialog(wnd.findOrRun(null, "Notepad", run: () => run.it(folders.System + "notepad.exe")))); //timer.after(500, _ => Au.Tools.Delm.Dialog(new POINT(806, 1580))); //timer.after(500, _ => Au.Tools.Delm.Dialog()); //timer.after(400, _ => Au.Tools.Duiimage.Dialog()); //timer2.every(200, _ => { GC.Collect(); }); #if DEBUG App.Timer1s += () => { var e = Keyboard.FocusedElement as FrameworkElement; Debug_.PrintIf(e != null && !e.IsVisible, "focused invisible"); //print.it(e, FocusManager.GetFocusedElement(App.Wmain)); }; #endif }
public Dwnd(wnd w = default, DwndFlags flags = 0, string title = "Find window") { _dontInsert = flags.Has(DwndFlags.DontInsert); _noControl = flags.Has(DwndFlags.NoControl); _checkControl = flags.Has(DwndFlags.CheckControl); _forTrigger = flags.Has(DwndFlags.ForTrigger); Title = title; var b = new wpfBuilder(this).WinSize((500, 450..), (600, 430..)).Columns(-1); b.R.Add(out _info).Height(60); b.R.StartGrid().Columns(0, 76, 76, 0, 0, -1); _cCapture = b.xAddCheckIcon("*Unicons.Capture #FF4040", $"Enable capturing ({App.Settings.delm.hk_capture}) and show window/control rectangles"); b.AddButton(out _bTest, "Test", _bTest_Click).Disabled().Tooltip("Executes the 'find' part of the code now and shows the rectangle"); b.AddButton(out _bInsert, _dontInsert ? "OK" : "Insert", _Insert).Disabled(); if (!_dontInsert) { b.Tooltip("Insert code in editor"); } b.Add(out _cbFunc).Items("find|findOrRun|runAndFind").Tooltip("Function").Width(90); //rejected: |wndFinder. Rare, etc. _cbFunc.SelectionChanged += _cbFunc_SelectionChanged; b.Add(out _cActivate, "Activate").Tooltip("Activate the found window"); b.Add(out _cException, "Fail if not found").Checked(!_forTrigger).Tooltip("Throw exception if not found"); //cActivate.CheckChanged += (_, _) => { cException.Visibility = cActivate.IsChecked ? Visibility.Hidden : Visibility.Visible; }; //no, need for control too b.End(); //window and control properties and search settings b.R.AddSeparator(false).Margin("B"); b.Row(0); //auto height, else adds v scrollbar when textbox height changes when a textbox text is multiline or too long (with h scrollbar) _scroller = b.xStartPropertyGrid("L2 T3 R2 B1"); //actually never shows scrollbar because of row auto height, but sets some options etc _scroller.Visibility = Visibility.Hidden; b.Columns(-3, 0, -1.2); //window b.R.Add <TextBlock>("Window").Margin("T1 B3").xSetHeaderProp(); //rejected: vertical headers. Tested, looks not good, too small for vertical Control checkbox. b.Row(0).StartGrid().Columns(70, -1); nameW = b.xAddCheckText("name"); classW = b.xAddCheckText("class"); programW = b.xAddCheckTextDropdown("program"); containsW = b.xAddCheckTextDropdown("contains"); b.End(); b.xAddSplitterV(span: 4, thickness: 12); b.StartGrid().Columns(44, -1); b.xAddCheck(out cHiddenTooW, "Find hidden too"); b.xAddCheck(out cCloakedTooW, "Find cloaked too"); alsoW = b.xAddCheckText("also", "o=>true"); waitW = b.xAddCheckText("wait", "1", check: !_forTrigger); b.End(); //control b.R.AddSeparator(false).Margin("T4 B0"); _sepControl = b.Last as Separator; b.R.Add(out _cControl, "Control").Margin("T5 B3").xSetHeaderProp(); b.Row(0).StartGrid().Columns(70, -1); _gCon1 = b.Panel as Grid; nameC = b.xAddCheckTextDropdown("name"); classC = b.xAddCheckText("class"); idC = b.xAddCheckText("id"); b.End().Skip(); b.StartGrid().Columns(44, -1); _gCon2 = b.Panel as Grid; b.xAddCheck(out cHiddenTooC, "Find hidden too"); alsoC = b.xAddCheckText("also", "o=>true"); skipC = b.xAddCheckText("skip"); b.End(); b.xEndPropertyGrid(); b.R.AddSeparator(false); if (_forTrigger) { _cActivate.Visibility = Visibility.Hidden; _cException.Visibility = Visibility.Hidden; _cbFunc.Visibility = Visibility.Hidden; waitW.Visible = false; } //code b.Row(64).xAddInBorder(out _code, "B"); //tree and window info b.xAddSplitterH(span: -1); b.Row(-1).StartGrid().Columns(-1, 0, -1); b.Row(-1).xAddInBorder(out _tree, "TR"); b.xAddSplitterV(); b.xAddInBorder(out _winInfo, "TL"); _winInfo.ZWrapLines = false; _winInfo.Name = "window_info"; b.End(); b.End(); _InitTree(); _con = w; b.WinProperties( topmost: true, showActivated: _dontInsert || w.Is0 ? null : false //eg if captured a popup menu, activating this window closes the menu and we cannot get properties ); WndSavedRect.Restore(this, App.Settings.wndpos.wnd, o => App.Settings.wndpos.wnd = o); }
public _Floating(_Node node, bool onDrag) { _node = node; _owner = _node._pm._ContainerWindow; _isToolbar = _node._IsToolbarsNode; //workaround for: if a HwndHost-ed native control in this panel is focused, WPF will activate the floating panel and disable next mouse click if (Keyboard.FocusedElement == null) { var wFocus = Api.GetFocus(); if (!wFocus.Is0 && wFocus.IsChildOf(_owner.Hwnd())) { if (null != _node.Elem.FindVisualDescendant(o => o is HwndHost h && h.Handle == wFocus.Handle)) { _owner.Focus(); } } } var style = WS.THICKFRAME | WS.POPUP | WS.CLIPCHILDREN; if (node._IsStack) { style |= WS.CAPTION; } var estyle = WSE.TOOLWINDOW | WSE.WINDOWEDGE; if (_isToolbar) { estyle |= WSE.NOACTIVATE; } RECT rect = default; bool defaultRect = onDrag | (_node._floatSavedRect == null); if (defaultRect) { var c2 = _node._ParentIsTab ? _node.Parent._elem : _node._elem; if (c2.IsVisible) { rect = c2.RectInScreen(); Dpi.AdjustWindowRectEx(c2, ref rect, style, estyle); } else { var p = mouse.xy; rect = (p.x - 10, p.y - 10, 200, 200); } } base.SourceInitialized += (_, _) => { var w = this.Hwnd(); w.SetStyle(style); if (_isToolbar) { w.SetExStyle(estyle); } }; base.Title = script.name + " - " + _node.ToString(); base.Owner = _owner; base.WindowStartupLocation = WindowStartupLocation.Manual; base.WindowStyle = WindowStyle.ToolWindow; base.ShowInTaskbar = false; //never mind: if false, WPF creates a "Hidden Window", probably as owner, even if owner specified base.ShowActivated = false; if (defaultRect) { this.SetRect(rect); } else { WndSavedRect.Restore(this, _node._floatSavedRect); } _owner.Closing += _Owner_Closing; _owner.IsVisibleChanged += _Owner_IsVisibleChanged; }