/[RomCheater]/trunk/RomCheater/Docking/PIDSelector.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/PIDSelector.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater/PIDSelector.cs	2012/05/10 11:16:03	107
+++ trunk/RomCheater/PIDSelector.cs	2012/05/10 12:16:41	110
@@ -8,6 +8,8 @@
 using System.Diagnostics;
 using RomCheater.PluginFramework.Interfaces;
 using RomCheater.PluginFramework.Core;
+using System.IO;
+using RomCheater.Logging;
 
 namespace RomCheater
 {
@@ -78,35 +80,77 @@
             List<ListViewItem> items = new List<ListViewItem>();
             ImageList small_image_list = new ImageList();
             ImageList large_image_list = new ImageList();
-            foreach (ProcContainer p in proc_list) { this.AddProcessItem(p, ref items, out small_image_list, out large_image_list); }
+
+            int small_width = 32;
+            int large_width = 48;
+
+            small_image_list.ImageSize = new Size(small_width, small_width);
+            large_image_list.ImageSize = new Size(large_width, large_width);
+            foreach (ProcContainer p in proc_list) 
+            {
+                Bitmap small_image = null;
+                Bitmap large_image = null;
+                string image_key = string.Empty;
+                this.AddProcessItem(p, small_image_list.ImageSize, large_image_list.ImageSize, out image_key, out small_image, out large_image);
+                if (image_key != string.Empty)
+                {
+                    if (small_image != null) { small_image_list.Images.Add(image_key, small_image); }
+                    if (large_image != null) { large_image_list.Images.Add(image_key, large_image); }
+                    ListViewItem item = new ListViewItem();
+                    // process name
+                    item.Text = p.Name;
+                    // pid
+                    item.SubItems.Add(p.ProcessInfo.Id.ToString());
+                    // FullPath
+                    item.SubItems.Add(p.FileName);
+                    // image key
+                    item.ImageKey = p.FileName;
+                    if (!items.Contains(item)) items.Add(item);
+                }
+                else
+                {
+                    logger.Error.Write("image_key is an empty string!");
+                    if (small_image != null) { logger.Error.Write(" [however small_image is not null]"); }
+                    if (large_image != null) { logger.Error.Write(" [however large_image is not null]\n"); }
+                }
+            }
             lstProcessList.SmallImageList = small_image_list;
             lstProcessList.LargeImageList = large_image_list;
             this.lstProcessList.Items.AddRange(items.ToArray());
             return true;
         }
 
-        private void AddProcessItem(ProcContainer p, ref  List<ListViewItem> items, out ImageList small_image_list, out ImageList large_image_list)
+        private void AddProcessItem(ProcContainer p, Size small, Size large, out string image_key, out Bitmap small_image, out Bitmap large_image)
         {
-            small_image_list = new ImageList();
-            large_image_list = new ImageList();
-            ListViewItem item = new ListViewItem();
-            // process
-            item.Text = p.Name;
-            if (p.ProcessIcon != null)
+            image_key = "";
+            small_image = null;
+            large_image = null;
+            ////small_image_list = new ImageList();
+            ////large_image_list = new ImageList();
+            //ListViewItem item = new ListViewItem();
+            //// process
+            //item.Text = p.Name;
+            //if (p.ProcessIcon != null)
+            //{   
+            //    //small_image_list.Images.Add(
+            //    //large_image_list.Images.Add(p.FileName, p.ProcessIcon);                
+            //    item.ImageKey = p.FileName;
+            //}
+            //// pid
+            //item.SubItems.Add(p.ProcessInfo.Id.ToString());
+            //// FullPath
+            //item.SubItems.Add(p.FileName);
+            //if (!items.Contains(item)) items.Add(item);
+            if (p != null)
             {
-                Bitmap small_image = ProcContainer.CreateIconFromProcess(p, 1);
-                Bitmap large_image = ProcContainer.CreateIconFromProcess(p, 2);
-                small_image_list.Images.Add(p.FileName, ProcContainer.CreateIconFromProcess(p, 1));
-                small_image_list.ImageSize = new Size(small_image.Width, small_image.Height);
-                large_image_list.Images.Add(p.FileName, ProcContainer.CreateIconFromProcess(p, 2));
-                large_image_list.ImageSize = new Size(large_image.Width, large_image.Height);
-                item.ImageKey = p.FileName;
+                if (p.ProcessIcon != null)
+                {
+                    image_key = p.FileName;
+                    small_image = new Bitmap(p.ProcessIcon, small);
+                    large_image = new Bitmap(p.ProcessIcon, large);
+                }
             }
-            // pid
-            item.SubItems.Add(p.ProcessInfo.Id.ToString());
-            // FullPath
-            item.SubItems.Add(p.FileName);
-            if (!items.Contains(item)) items.Add(item);
+
         }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22