프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / APIDConverter / Utils / AccessPropertyForm.cs @ 4622d687

이력 | 보기 | 이력해설 | 다운로드 (1.74 KB)

1 932933ed gaqhf
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 AVEVA.PID.CustomizationUtility
10
{
11
    class AccessPropertyForm
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
        const int BM_CLICK = 0x00F5;
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.IsBackground = true;
34
            thread.Start();
35
        }
36
37
        public static void Stop()
38
        {
39
            run = false;
40
        }
41
42
        public static void CloseForm()
43
        {
44
            try
45
            {
46
                int handle = FindWindow(null, AvevaACAD18String.PipePropertyUI);
47
                if (handle > 0)
48
                {
49
                    int button = FindWindowEx(handle, 0, null, "Ok");
50
                    if (button > 0)
51
                    {
52
                        Thread.Sleep(500);
53
                        SendMessage((IntPtr)button, BM_CLICK, (IntPtr)0, (IntPtr)0);
54
                        Thread.Sleep(2000);
55
                    }
56
                }
57
                Thread.Sleep(1000);
58
            }
59
            catch (Exception ex)
60
            {
61
62
            }
63
        }
64
    }
65
}
클립보드 이미지 추가 (최대 크기: 500 MB)