개정판 87f22597
dev issue #1230 : edit AvevaThread.cs
Change-Id: I40100799655315bbb4ae9f681083a75caba420c4
DTI_PID/APIDConverter/Utils/AvevaThread.cs | ||
---|---|---|
53 | 53 |
public static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2); |
54 | 54 |
[DllImport("user32")] |
55 | 55 |
public static extern int SendMessage(IntPtr hWnd, int uMsg, IntPtr WParam, IntPtr LParam); |
56 |
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)] |
|
57 |
static extern long GetClassName(IntPtr hwnd, StringBuilder lpClassName, long nMaxCount); |
|
58 |
static string GetClassNameOfWindow(IntPtr hwnd) |
|
59 |
{ |
|
60 |
string className = ""; |
|
61 |
StringBuilder classText = null; |
|
62 |
try |
|
63 |
{ |
|
64 |
int cls_max_length = 1000; |
|
65 |
classText = new StringBuilder("", cls_max_length + 5); |
|
66 |
GetClassName(hwnd, classText, cls_max_length + 2); |
|
56 | 67 |
|
57 |
const int BM_CLICK = 0x00F5; |
|
68 |
if (!String.IsNullOrEmpty(classText.ToString()) && !String.IsNullOrWhiteSpace(classText.ToString())) |
|
69 |
className = classText.ToString(); |
|
70 |
} |
|
71 |
catch (System.Exception ex) |
|
72 |
{ |
|
73 |
className = ex.Message; |
|
74 |
} |
|
75 |
finally |
|
76 |
{ |
|
77 |
classText = null; |
|
78 |
} |
|
79 |
return className; |
|
80 |
} |
|
58 | 81 |
|
82 |
const int BM_CLICK = 0x00F5; |
|
83 |
const int LoopTime = 500; |
|
59 | 84 |
private static ThreadType Running; |
60 | 85 |
|
61 | 86 |
public static bool IsRunning(ThreadType type) |
... | ... | |
105 | 130 |
{ |
106 | 131 |
while (Running.HasFlag(ThreadType.LineNumberModeling)) |
107 | 132 |
{ |
108 |
int handle = FindWindow(null, AvevaACAD18String.PipePropertyUI);
|
|
133 |
int handle = FindPropertiesFormHandle();
|
|
109 | 134 |
if (handle > 0) |
110 | 135 |
{ |
111 |
Thread.Sleep(1000);
|
|
136 |
string name = GetClassNameOfWindow((IntPtr)handle);
|
|
112 | 137 |
|
113 | 138 |
System.Windows.Forms.Control control = System.Windows.Forms.Control.FromHandle((IntPtr)handle); |
114 | 139 |
if (control != null && control.GetType() == typeof(ComponentPropertiesUI)) |
... | ... | |
122 | 147 |
int button = FindWindowEx(handle, 0, null, "Ok"); |
123 | 148 |
if (button > 0) |
124 | 149 |
{ |
125 |
Thread.Sleep(500); |
|
126 | 150 |
SendMessage((IntPtr)button, BM_CLICK, (IntPtr)0, (IntPtr)0); |
127 |
Thread.Sleep(500); |
|
128 | 151 |
Running &= ~ThreadType.LineNumberModeling; |
129 | 152 |
} |
130 | 153 |
} |
131 |
Thread.Sleep(1000);
|
|
154 |
Thread.Sleep(LoopTime);
|
|
132 | 155 |
} |
133 | 156 |
} |
134 | 157 |
catch (System.Exception ex) |
... | ... | |
142 | 165 |
{ |
143 | 166 |
while (Running.HasFlag(ThreadType.AddProperty)) |
144 | 167 |
{ |
145 |
int handle = FindWindow(null, AvevaACAD18String.PipePropertyUI);
|
|
168 |
int handle = FindPropertiesFormHandle();
|
|
146 | 169 |
if (handle > 0) |
147 | 170 |
{ |
148 |
Thread.Sleep(1000); |
|
149 |
|
|
150 | 171 |
System.Windows.Forms.Control control = System.Windows.Forms.Control.FromHandle((IntPtr)handle); |
151 | 172 |
if (control != null && control.GetType() == typeof(ComponentPropertiesUI)) |
152 | 173 |
{ |
... | ... | |
161 | 182 |
int button = FindWindowEx(handle, 0, null, "Ok"); |
162 | 183 |
if (button > 0) |
163 | 184 |
{ |
164 |
Thread.Sleep(500); |
|
165 | 185 |
SendMessage((IntPtr)button, BM_CLICK, (IntPtr)0, (IntPtr)0); |
166 |
Thread.Sleep(500); |
|
167 | 186 |
} |
168 | 187 |
} |
169 | 188 |
Running &= ~ThreadType.AddProperty; |
170 | 189 |
break; |
171 | 190 |
} |
172 |
Thread.Sleep(1000);
|
|
191 |
Thread.Sleep(LoopTime);
|
|
173 | 192 |
} |
174 | 193 |
} |
175 | 194 |
catch (System.Exception ex) |
... | ... | |
189 | 208 |
int button = FindWindowEx(handle, 0, null, "Ok"); |
190 | 209 |
if (button > 0) |
191 | 210 |
{ |
192 |
Thread.Sleep(500); |
|
193 | 211 |
SendMessage((IntPtr)button, BM_CLICK, (IntPtr)0, (IntPtr)0); |
194 |
Thread.Sleep(500); |
|
195 | 212 |
} |
196 | 213 |
} |
197 |
Thread.Sleep(1000);
|
|
214 |
Thread.Sleep(LoopTime);
|
|
198 | 215 |
} |
199 | 216 |
} |
200 | 217 |
catch (System.Exception ex) |
... | ... | |
203 | 220 |
} |
204 | 221 |
} |
205 | 222 |
|
223 |
public static int FindPropertiesFormHandle() |
|
224 |
{ |
|
225 |
int result = 0; |
|
226 |
foreach (var item in AvevaACAD18String.PropertiesFormNames) |
|
227 |
{ |
|
228 |
result = FindWindow(null, item); |
|
229 |
if (result > 0) |
|
230 |
break; |
|
231 |
} |
|
232 |
|
|
233 |
return result; |
|
234 |
} |
|
206 | 235 |
public static void Test() |
207 | 236 |
{ |
208 | 237 |
|
내보내기 Unified diff