hytos / DTI_PID / SPPIDConverter / CloseOPCForm.cs @ bded697f
이력 | 보기 | 이력해설 | 다운로드 (1.5 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Runtime.InteropServices; |
5 |
using System.Text; |
6 |
using System.Threading.Tasks; |
7 |
using System.Threading; |
8 |
|
9 |
namespace Converter.SPPID |
10 |
{ |
11 |
class CloseOPCForm |
12 |
{ |
13 |
[DllImport("user32")] |
14 |
public static extern int FindWindow(string lpClassName, string lpWindowName); |
15 |
[DllImport("user32.dll")] |
16 |
public static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2); |
17 |
[DllImport("user32")] |
18 |
public static extern int SendMessage(IntPtr hWnd, int uMsg, IntPtr WParam, IntPtr LParam); |
19 |
|
20 |
static int WM_CLOSE = 0x0010; |
21 |
|
22 |
private static bool run; |
23 |
|
24 |
public static void Run() |
25 |
{ |
26 |
run = true; |
27 |
Thread thread = new Thread(loop => { |
28 |
while (run) |
29 |
{ |
30 |
CloseForm(); |
31 |
} |
32 |
}); |
33 |
thread.Start(); |
34 |
} |
35 |
|
36 |
public static void Stop() |
37 |
{ |
38 |
run = false; |
39 |
} |
40 |
|
41 |
public static void CloseForm() |
42 |
{ |
43 |
try |
44 |
{ |
45 |
int handle = FindWindow("ThunderRT6FormDC", "Set Stockpile Location of Partner OPC"); |
46 |
if (handle > 0) |
47 |
{ |
48 |
Thread.Sleep(100); |
49 |
SendMessage((IntPtr)handle, WM_CLOSE, (IntPtr)0, (IntPtr)0); |
50 |
Thread.Sleep(100); |
51 |
} |
52 |
} |
53 |
catch (Exception ex) |
54 |
{ |
55 |
|
56 |
} |
57 |
} |
58 |
} |
59 |
} |