コード例 #1
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;
        }
コード例 #2
0
        public ProcessInfo GetProcessInfo(ForegroundWindowInfo windowInfo)
        {
            Ensure.ArgumentNotNull(windowInfo, nameof(windowInfo));

            User32.GetWindowThreadProcessId(windowInfo.Handle, out int processId);
            var processExecutablePath = GetMainModuleFilepath(processId);

            if (processId == 0 || string.IsNullOrEmpty(processExecutablePath))
            {
                return(null);
            }

            return(new ProcessInfo
            {
                ProcessId = processId,
                ExecutablePath = processExecutablePath
            });
        }
コード例 #3
0
 protected virtual void OnForegroundWindowChanged(ForegroundWindowInfo windowInfo)
 {
     ForegroundWindowInfoUpdated?.Invoke(windowInfo);
 }