Beispiel #1
0
 public override bool Equals(object obj)
 {
     if (!this.GetType().Equals(obj.GetType()))
     {
         return(false);
     }
     else
     {
         ProcessData UWPObj = (ProcessData)obj;
         return((this.WindowName == UWPObj.WindowName && this.ProcessNamePng == UWPObj.ProcessNamePng) ? true : false);
     }
 }
Beispiel #2
0
 //Copy Constructor
 public ProcessData(ProcessData copyobj)
 {
     WindowName     = copyobj.WindowName;
     ProcessNamePng = copyobj.ProcessNamePng;
     ExeAddress     = copyobj.ExeAddress;
 }
Beispiel #3
0
        public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
        {
            Measure measure = (Measure)data;

            Rainmeter.API api = (Rainmeter.API)rm;


            //Filter all background and redundant processes, keeping all application process stored in TraySysProcesses
            // TotalSize       = total no of normal running application after filtering
            // ProcessesRecord = a temporary record of measure.TraySysProcesses in form of string name
            // UWPRecord       = a temporary record of measure.UWPRecord in form of UWP's Windows Title
            int TotalSize = 0;
            HashSet <string> ProcessesRecord = new HashSet <string>();
            HashSet <string> UWPRecord       = new HashSet <string>();

            EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                //Get Window Title
                StringBuilder strbTitle = new StringBuilder(255);
                int           nLength   = GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
                string        strTitle  = strbTitle.ToString();


                if (IsWindowVisible(hWnd))
                {
                    Int64 style  = (Int64)GetWindowLongPtr(hWnd, -16); // GWL_STYLE
                    Int64 style2 = (Int64)GetWindowLongPtr(hWnd, -20); // GWL_EXSTYLE

                    //Does not have a WindowCaption
                    if ((style & 0x00C00000L) != 0x00C00000L)
                    {
                        return(true);
                    }

                    //Is Tool Window
                    if ((style2 & 0x00000080L) == 0x00000080L)
                    {
                        return(true);
                    }

                    //Get Target Process
                    uint ProcessID = 0;
                    GetWindowThreadProcessId(hWnd, ref ProcessID);
                    Process Process = Process.GetProcessById((int)ProcessID);

                    //Reaching Limit
                    if (TotalSize >= Measure.MaxSize)
                    {
                        return(true);
                    }

                    int IsApp = measure.IsRunningApplication(Process, measure.TraySysProcesses, TotalSize);

                    //Detect if it is Universal Window App
                    if (IsApp == 1 && (Process.ProcessName == "ApplicationFrameHost" || Process.ProcessName == "WWAHost"))
                    {
                        //Check if it is not a coated window ( important for determining UWP being visible or not )
                        IntPtr attribute = new IntPtr();
                        int    result    = DwmGetWindowAttribute(hWnd, (int)DWMWINDOWATTRIBUTE.DWMWA_CLOAKED, out attribute, 256);

                        //Actual Running Application, put it inside UWPList which will be dealt with later on
                        if (attribute.ToInt32() == 0)
                        {
                            UWPRecord.Add(strTitle);
                            measure.UWPList[measure.UWPCount] = new ProcessData(strTitle, "Default.png", "");
                            measure.UWPCount++;
                            return(true);
                        }
                    }
                    //Detect if it is windows application
                    else if (IsApp == 1 && !String.IsNullOrEmpty(strTitle))
                    {
                        string ProcessNameinPNG = string.Concat(Process.ProcessName, ".png");

                        ProcessesRecord.Add(ProcessNameinPNG);
                        measure.TraySysProcesses[TotalSize] = new ProcessData(strTitle, ProcessNameinPNG, "");
                        try { measure.TraySysProcesses[TotalSize].ExeAddress = Process.MainModule.FileName; } catch { measure.TraySysProcesses[TotalSize].ExeAddress = ""; }

                        //Check if a new application is running
                        if (measure.PreSysProcesses.Contains(ProcessNameinPNG) == false)
                        {
                            Measure.IsUpdate = 1;
                        }
                        TotalSize = TotalSize + 1;
                    }
                    // Not a Windows application
                    else
                    {
                        return(true);
                    }
                }


                return(true);
            };

            EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);


            //Check if any Application(s) being deleted
            if (TotalSize < measure.PrevSize)
            {
                Measure.IsUpdate = 1;
            }


            if (measure.DelayCycle > 0)
            {
                measure.DelayCycle--;
            }
            if (measure.PrevUWPCount + measure.PrevWinSettingCount != measure.UWPCount + measure.WinSettingCount && measure.DelayCycle <= 0)
            {
                Measure.IsUpdate = 1;
            }


            //Record current processes list, which can be used to compare next update later
            measure.PreSysProcesses = new HashSet <string>(ProcessesRecord);
            measure.PrevSize        = TotalSize;
            if (measure.DelayCycle <= 0)
            {
                measure.PrevUWPList         = new HashSet <string>(UWPRecord);
                measure.PrevUWPCount        = measure.UWPCount;
                measure.PrevWinSettingCount = measure.WinSettingCount;
            }


            //Ignore Extract Icon process if no need to update
            if (Measure.IsUpdate == 0)
            {
                return;
            }


            //Write UWPCount in ini file, and display it if there is/are UWP(s) running
            measure.SetVariable("WinAppCount", (measure.UWPCount + measure.WinSettingCount).ToString(), rm);
            int start = ((measure.UWPCount + measure.WinSettingCount) > 0) ? 1 : 0;

            if (start == 1)
            {
                measure.SetVariable("PValue0", "WinAppAndUWP.png", rm);
            }


            //Extract Icon from Process and saved it inside icon folder
            for (int pcount = start; pcount < measure.TraySysProcesses.Length; pcount++)
            {
                ProcessData ServiceData = measure.TraySysProcesses[pcount - start];
                string      KeyName     = string.Concat("PValue", pcount.ToString());

                // reaching empty items
                if (ServiceData.ProcessNamePng == "Default.png" || String.IsNullOrEmpty(ServiceData.ProcessNamePng))
                {
                    //write to ini file, Set Variable
                    measure.SetVariable(KeyName, "Default.png", rm);
                    continue;
                }

                //write to ini file, Set Variable
                measure.SetVariable(KeyName, ServiceData.ProcessNamePng, rm);

                //icon path
                string path = string.Concat(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString(), "\\Rainmeter\\Skins\\Distiller_Block\\@Resources\\Icon\\", ServiceData.ProcessNamePng);

                //avoid re-saving the same icon picture
                if (File.Exists(path))
                {
                    continue;
                }


                // Saving the icon picture into @Resource\Icon Folder
                try
                {
                    using (Icon ico = Icon.ExtractAssociatedIcon(ServiceData.ExeAddress))
                    {
                        using (Bitmap btmap = ico.ToBitmap())
                        {
                            btmap.Save(path, System.Drawing.Imaging.ImageFormat.Png);
                        }
                    }
                    Measure.IsUpdate = 2;
                }
                catch (Exception e)
                {
                    //failure in getting the icon, use Default.png instead
                    measure.SetVariable(KeyName, "Default.png", rm);
                    Measure.IsUpdate = 1;
                }
            }
        }