Exemplo n.º 1
0
 /// <summary>
 /// Gets all running processes which have opened window
 /// </summary>
 private static void GetRunningProcesses()
 {
     foreach (Process p in Process.GetProcesses())
     {
         if (p.MainWindowTitle != string.Empty)
         {
             _processes.Add(p.Id, p.ProcessName + WinApiWrapper.GetProcDescription(p.Id));
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets icon from executable file of the process
        /// </summary>
        /// <param name="appName">Application process name (like in task manager)</param>
        /// <param name="appDesc">Application process description (like in task manager)</param>
        /// <param name="isLarge">Set it true to grab large icon, else - false</param>
        /// <returns>
        /// Returns icon of the application or null if application does not contains any icon
        /// </returns>
        public static Icon GetApplicationIcon(string appName, string appDesc, bool isLarge)
        {
            IconExtractor extractor;

            try
            {
                extractor = new IconExtractor(WinApiWrapper.GetProcExecutablePath(appName, appDesc));
            }
            catch (Exception e)
            {
                ErrorManager.Instance.RiseError("could not create extractor", e.Message);
                return(GetProcIcon(WinApiWrapper.GetProcExecutablePath(appName, appDesc)));
            }

            var il = new List <Icon>();

            for (int i = 0; i < extractor.IconCount; i++)
            {
                //TODO : not all files contains icons. needs another solution
                try
                {
                    il.AddRange(IconExtractor.SplitIcon(extractor.GetIcon(i)));
                }
                catch (Exception e)
                {
                    ErrorManager.Instance.RiseError("wrong resource", e.Message);
                    return(GetProcIcon(WinApiWrapper.GetProcExecutablePath(appName, appDesc)));
                }
            }

            var resIconInfo = new IconInfo();

            foreach (Icon ic in il)
            {
                int depth = GetIconBitDepth(ic);
                if (depth <= DefaultColorDepth && depth > resIconInfo.Depth)
                {
                    resIconInfo.Ico   = ic;
                    resIconInfo.Depth = depth;
                    resIconInfo.Size  = ic.Size;
                }
                if (IsSizeFit(ic.Size, resIconInfo.Size, isLarge))
                {
                    resIconInfo.Ico   = ic;
                    resIconInfo.Depth = depth;
                    resIconInfo.Size  = ic.Size;
                }
                if (IsIconFit(resIconInfo, isLarge))
                {
                    break;
                }
            }
            return(resIconInfo.Ico);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Procedure handles timer ticks
        /// </summary>
        /// <param name="state">Service parmeter</param>
        private void TimerTick(object state)
        {
            bool invokeStateChRequired = false;
            bool invokeAppChRequired   = false;
            int  newPid = WinApiWrapper.GetActWindowPID();

            // No active process detected
            if (newPid == 0)
            {
                return;
            }

            string newWTitle = WinApiWrapper.GetWindowTitle();
            string newPName  = WinApiWrapper.GetWindowProcName(newPid);
            string newPdesc  = WinApiWrapper.GetProcDescription(newPid);

            if (!_processes.ContainsKey(newPid))
            {
                _processes.Add(newPid, newPName);
            }

            CheckProcessesAlive();

            if (newPid != _actPid)
            {
                InvokeActPidChanged(new ProcessEventArgs(newPid));
                _actPid = newPid;
                invokeStateChRequired = true;
            }
            if (newPName != _actPname)
            {
                InvokeActPNameChanged(new ActPNameChangedHandlerArgs(newPName));
                _actPname             = newPName;
                invokeStateChRequired = true;
                invokeAppChRequired   = true;
            }
            if (newPdesc != _actPdesc)
            {
                InvokeActPDescChanged(new ActPDescChangedHandlerArgs(newPdesc));
                _actPdesc             = newPdesc;
                invokeStateChRequired = true;
                invokeAppChRequired   = true;
            }
            if (newWTitle != _actWinText)
            {
                InvokeActWindowTextChanged(new ActWindowTextChangedHandlerArgs(newWTitle));
                _actWinText           = newWTitle;
                invokeStateChRequired = true;
            }

            if (invokeAppChRequired)
            {
                InvokeActApplicationChanged(new ActApplicationChangedHandlerArgs(newPName, newPdesc, newPid));
            }

            //State changed event must be invoked last
            if (invokeStateChRequired)
            {
                InvokeActStateChanged(new ActStateChangedHandlerArgs(newPid, newPName, newPdesc, newWTitle));
            }
        }