Exemple #1
0
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            InitializeTrayIcon();

            windowMonitor.StartMonitoringAsync();
            windowMonitor.ForegroundWindowInfoUpdated += windowInfo =>
            {
                var process = processLocator.GetProcessInfo(windowInfo);
                ApplicationProfile profile = null;
                if (process != null)
                {
                    profile = configurationManager.GetProfileForExecutable(process.ExecutablePath);
                }

                if (process == null || profile == null)
                {
                    Debug.WriteLine("Process: " + process?.ExecutablePath);
                    Debug.WriteLine("No process or profile. Resetting clipping.");
                    // reset cursor clip
                    Cursor.Clip = new Rectangle();
                    return;
                }

                Debug.WriteLine("Setting window clipping.");
                Cursor.Clip = new System.Drawing.Rectangle(
                    new System.Drawing.Point(windowInfo.Left + windowBorder, windowInfo.Top),
                    new System.Drawing.Size(
                        windowInfo.Right - windowInfo.Left - windowBorder * 2,
                        windowInfo.Bottom - windowInfo.Top - windowBorder));
            };
        }
Exemple #2
0
        private void OnForegroundWindowInfoUpdated(ForegroundWindowInfo info)
        {
            var processInfo = processLocator.GetProcessInfo(info);

            if (processInfo == null)
            {
                return;
            }

            this.Model.ForegroundText = info.Handle.ToString();
            this.Model.Left           = info.Left;
            this.Model.Top            = info.Top;
            this.Model.Right          = info.Right;
            this.Model.Bottom         = info.Bottom;
            this.Model.ProcessId      = processInfo.ProcessId;
        }