ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.PluginFramework/Core/ProcContainer.cs
Revision: 109
Committed: Thu May 10 12:12:26 2012 UTC (11 years, 4 months ago) by william
File size: 6121 byte(s)
Log Message:
fix code to properly display icons in PIDSelector

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Diagnostics;
6 using System.Drawing;
7 using System.IO;
8 using libWin32.Win32.Threading;
9
10 namespace RomCheater.PluginFramework.Core
11 {
12 public class ProcContainer
13 {
14 public ProcContainer() { this.init(); }
15 public ProcContainer(Process process)
16 : this()
17 {
18 this.ProcessInfo = process;
19 FileInfo fi = null;
20 string fname = "";
21 try
22 {
23 fname = ProcessModeleInfoEx.GetMainModulePath(process);
24 fi = new FileInfo(fname);
25 }
26 catch (Exception)
27 {
28 throw;
29 }
30 this.FileName = fi.FullName;
31 this.Name = fi.Name;
32 this.CreateProcessIcon(4);
33 }
34 public ProcContainer(Process process, Icon icon)
35 : this()
36 {
37 this.ProcessInfo = process; this.ProcessIcon = icon.ToBitmap();
38 string fname = ProcessModeleInfoEx.GetMainModulePath(process);
39 FileInfo fi = new FileInfo(fname);
40 this.FileName = fi.FullName;
41 this.Name = fi.Name;
42 }
43 public ProcContainer(Process process, Bitmap icon)
44 : this()
45 {
46 this.ProcessInfo = process; this.ProcessIcon = icon;
47 string fname = ProcessModeleInfoEx.GetMainModulePath(process);
48 FileInfo fi = new FileInfo(fname);
49 this.FileName = fi.FullName;
50 this.Name = fi.Name;
51 }
52 private void init() { this.ProcessInfo = null; this.ProcessIcon = null; }
53
54
55 public string Name { get; set; }
56 public string FileName { get; set; }
57
58 private Process _ProcessInfo;
59 public Process ProcessInfo { get { return _ProcessInfo; } set { _ProcessInfo = value; } }
60 private Bitmap _ProcessIcon;
61 public Bitmap ProcessIcon { get { return _ProcessIcon; } set { _ProcessIcon = value; } }
62
63 public override string ToString()
64 {
65 return this.FileName;
66 }
67
68 public static Bitmap CreateIconFromProcess(ProcContainer proc)
69 {
70 if (proc == null) return null;
71 Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true);
72 if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false);
73 Bitmap ret = null;
74 if (large != null)
75 ret = large.ToBitmap();
76 if (ret == null)
77 {
78 return null;
79 }
80 return ret;
81 }
82 public static Bitmap CreateIconFromProcess(ProcContainer proc, int Scale)
83 {
84 if (proc == null) return null;
85 Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true);
86 if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false);
87 Bitmap ret = null;
88 if (large != null)
89 ret = large.ToBitmap();
90 if (ret == null)
91 {
92 return null;
93 }
94 ret = new Bitmap(ret, ret.Width * Scale, ret.Height * Scale);
95 return ret;
96 }
97 public static Bitmap CreateIconFromProcess(ProcContainer proc, int Width, int Height)
98 {
99 if (proc == null) return null;
100 Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true);
101 if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false);
102 Bitmap ret = null;
103 if (large != null)
104 ret = large.ToBitmap();
105 if (ret == null)
106 {
107 return null;
108 }
109 ret = new Bitmap(ret, Width, Height);
110 return ret;
111 }
112 private void CreateProcessIcon()
113 {
114 if (this.ProcessInfo == null) return;
115 Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true);
116 if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false);
117 Bitmap ret = null;
118 if (large != null)
119 ret = large.ToBitmap();
120 if (ret == null)
121 {
122 this.ProcessIcon = null;
123 return;
124 }
125 this.ProcessIcon = ret;
126 }
127 private void CreateProcessIcon(int Scale)
128 {
129 if (this.ProcessInfo == null) return;
130 Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true);
131 if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false);
132 Bitmap ret = null;
133 if (large != null)
134 ret = large.ToBitmap();
135 if (ret == null)
136 {
137 this.ProcessIcon = null;
138 return;
139 }
140 ////Bitmap bmp = large.ToBitmap();
141 //string save_path = @"c:\temp";
142 //string icon_file = string.Format(@"{0}\{1}.bmp", save_path, new FileInfo(this.FileName).Name);
143
144
145 ret = new Bitmap(ret, ret.Width * Scale, ret.Height * Scale);
146 //ret.Save(icon_file, System.Drawing.Imaging.ImageFormat.Bmp);
147 this.ProcessIcon = ret;
148 }
149 private void CreateProcessIcon(int Width, int Height)
150 {
151 if (this.ProcessInfo == null) return;
152 Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true);
153 if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false);
154 Bitmap ret = null;
155 if (large != null)
156 ret = large.ToBitmap();
157 if (ret == null)
158 {
159 this.ProcessIcon = null;
160 return;
161 }
162 ret = new Bitmap(ret, Width, Height);
163 this.ProcessIcon = ret;
164 }
165 }
166 }