示例#1
0
        };                                                                                                                               //Color.BlueViolet

        /// <summary>
        /// Briefly shows standard blinking on-screen rectangle.
        /// </summary>
        public static void ShowOsdRect(RECT r, bool limitToScreen = false)
        {
            var osr = CreateOsdRect();

            r.Inflate(2, 2);             //2 pixels inside, 2 outside
            if (limitToScreen)
            {
                var k = AScreen.Of(r).Bounds;
                r.Intersect(k);
            }
            osr.Rect = r;
            osr.Show();

            int i = 0;

            ATimer.Every(250, t => {
                if (i++ < 5)
                {
                    osr.Color = (i & 1) != 0 ? 0xFFFFFF00 : 0xFF8A2BE2;
                }
                else
                {
                    t.Stop();
                    osr.Dispose();
                }
            });
        }
示例#2
0
    static void _TimerProc(ATimer t)
    {
        Timer1sOr025s?.Invoke();
        bool needFast = MainForm.Visible;

        if (needFast != (s_timerCounter > 0))
        {
            t.Every(needFast ? 250 : 1000);
        }
        if (needFast)
        {
            Timer025sWhenVisible?.Invoke();
            s_timerCounter++;
            if (MousePosChangedWhenProgramVisible != null)
            {
                var p = AMouse.XY;
                if (p != s_mousePos)
                {
                    s_mousePos = p;
                    MousePosChangedWhenProgramVisible(p);
                }
            }
        }
        else
        {
            s_timerCounter = 0;
        }
        if (0 == (s_timerCounter & 3))
        {
            Timer1s?.Invoke();
        }
    }
示例#3
0
 void _StartedDragMode()
 {
     //AOutput.Write("START");
     _isDragMode     = true;
     _endCounter     = 0;
     _wTransparent   = default;
     _wWindow        = default;
     _wTargetControl = default;
     _data           = null;
     _timer.Every(30);
 }
示例#4
0
    static void _Main(string[] args)
    {
        //Test(); return;
        //Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)1; //test how works with 1 CPU
        //Task.Run(() => { while(true) { Thread.Sleep(1000); GC.Collect(); } });

        if (CommandLine.OnProgramStarted(args))
        {
            return;
        }

        OutputServer.NoNewline = true;
        OutputServer.Start();

        Api.SetErrorMode(Api.GetErrorMode() | Api.SEM_FAILCRITICALERRORS);         //disable some error message boxes, eg when removable media not found; MSDN recommends too.
        Api.SetSearchPathMode(Api.BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE);        //let SearchPath search in current directory after system directories

        //Application.SetHighDpiMode(HighDpiMode.SystemAware); //no, we have manifest
        //Application.EnableVisualStyles(); //no, we have manifest
        Application.SetCompatibleTextRenderingDefault(false);

        Settings = ProgramSettings.Load();

        UserGuid = Settings.user; if (UserGuid == null)
        {
            Settings.user = UserGuid = Guid.NewGuid().ToString();
        }

        ATimer.Every(1000, t => _TimerProc(t));
        //note: timer can make Process Hacker/Explorer show CPU usage, even if we do nothing. Eg 0.02 if 250, 0.01 if 500, <0.01 if 1000.
        //Timer1s += () => AOutput.Write("1 s");
        //Timer1sOr025s += () => AOutput.Write("0.25 s");

        FMain.ZRunApplication();

        OutputServer.Stop();
    }
示例#5
0
            /// <summary>
            /// Starts or stops capturing.
            /// Does nothing if already in that state.
            /// </summary>
            public void StartStop(bool start)
            {
                if (start == Capturing)
                {
                    return;
                }
                var wForm = (AWnd)_form;

                if (start)
                {
                    //let other forms stop capturing
                    wForm.Prop.Set(c_propName, 1);
                    AWnd.Find(null, "WindowsForms*", also: o => {
                        if (o != wForm && o.Prop[c_propName] == 1)
                        {
                            o.Send(c_stopMessage);
                        }
                        return(false);
                    });

                    if (!Api.RegisterHotKey(wForm, 1, 0, KKey.F3))
                    {
                        ADialog.ShowError("Failed to register hotkey F3", owner: _form);
                        return;
                    }
                    Capturing = true;

                    //set timer that shows AO rect
                    if (_timer == null)
                    {
                        _osr   = TUtil.CreateOsdRect();
                        _timer = new ATimer(t => {
                            //Don't capture too frequently.
                            //	Eg if the callback is very slow. Or if multiple timer messages are received without time interval (possible in some conditions).
                            long t1 = ATime.PerfMilliseconds, t2 = t1 - _prevTime; _prevTime = t1; if (t2 < 100)
                            {
                                return;
                            }

                            //show rect of UI object from mouse
                            AWnd w = AWnd.FromMouse(WXYFlags.NeedWindow);
                            RECT?r = default;
                            if (!(w.Is0 || w == wForm || w.OwnerWindow == wForm))
                            {
                                r = _cbGetRect();
                            }
                            if (r.HasValue)
                            {
                                var rr = r.GetValueOrDefault();
                                rr.Inflate(2, 2);                                 //2 pixels inside, 2 outside
                                _osr.Rect = rr;
                                _osr.Show();
                            }
                            else
                            {
                                _osr.Visible = false;
                            }
                        });
                    }
                    _timer.Every(250);
                }
                else
                {
                    Capturing = false;
                    Api.UnregisterHotKey(wForm, 1);
                    wForm.Prop.Remove(c_propName);
                    _timer.Stop();
                    _osr.Hide();
                }
            }