teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

まともな回答が得られなかったため

2018/10/02 08:26

投稿

dewdtm
dewdtm

スコア8

title CHANGED
File without changes
body CHANGED
@@ -1,175 +1,1 @@
1
- いつもお世話になっております。
2
-
3
- 以前にこちらのサイト様で、ExcelVBAにおける外部アプリの操作(主にハンドル関連)についてご質問させていただき、おかげさまで外部データベース入力の自動化を実現させることが出来ました。
4
-
5
- 【以前の質問ページ】
6
- https://teratail.com/questions/135393
7
- https://teratail.com/questions/135546
8
-
9
- 今回は、ExcelVBAでコーディングしたそのプログラムを、VB.NETでも使用できるよう、
10
- 変換したいと思い、再度ご質問に上がりました。
11
-
12
- システムの根幹となるハンドル取得のコードは、
13
- 下記のサイト様からコピーしたものです。
14
- 【参考にしたコード】
15
- http://nonsoft.la.coocan.jp/SoftSample/SampleEnumWindows.html
16
-
17
- こちらにはご親切にもVB6とVB.NET両方のコードが載せられているのですが、
18
- VB.NETの方は、肝心のハンドルが取得できず、Class名とTitleしか取得できません。
19
- まずこのハンドル+Class名+titleをTreeView1に列挙すること、
20
- Class名とtitleを除外したハンドルのみの情報をTreeView2に列挙すること、
21
- そして、ハンドル取得⇒送信すること、
22
- この三点のコードを変換したい思っております。
23
-
24
- ```ここに言語を入力
25
- 【ハンドル+Class名+title情報をTreeView1に列挙するコード】
26
-
27
- Private Sub NodesW()
28
- Dim i As Long
29
- Dim J As Long
30
- Dim strClass As String
31
- Dim strTitle As String
32
- Dim strSpace As String
33
-
34
- ' ウィンドウとコントロールの全ての情報を取得
35
- Dim colWindows As Collection
36
- Set colWindows = GetAllWindows()
37
-
38
- ' 親ウィンドウ毎のコレクションループ
39
- For i = 1 To colWindows.Count
40
- ' 子コントロール毎のコレクション取得
41
- Dim colChilds As Collection
42
- Set colChilds = colWindows.Item(i)
43
-
44
- 'If colChilds.Count >= 1 Then ' 全ての親ウィンドウを対象
45
- If colChilds.Count > 1 Then ' 子コントロールを持つ物のみ対象
46
- ' 子コントロール毎のコレクションループ
47
-
48
- For J = 1 To colChilds.Count
49
- strSpace = StrConv(String(50, " "), vbFromUnicode)
50
-
51
- ' コレクションからクラス名取得
52
- strClass = StrConv(colChilds.Item(J)(1), vbFromUnicode)
53
- If LenB(strClass) < 30 Then
54
- strClass = LeftB$(strClass & strSpace, 30)
55
- End If
56
- strClass = StrConv(strClass, vbUnicode)
57
-
58
- ' コレクションから文字列取得
59
- strTitle = StrConv(colChilds.Item(J)(2), vbFromUnicode)
60
- If LenB(strTitle) < 50 Then
61
- strTitle = LeftB$(strTitle & strSpace, 50)
62
- End If
63
- strTitle = StrConv(strTitle, vbUnicode)
64
-
65
- If J = 1 Then
66
- ' 親ウィンドウの情報をツリービューへ追加
67
- Call TreeView1.Nodes.Add( _
68
- , , "R" & _
69
- Right$("00000000" & Hex(colChilds.Item(J)(0)), 8), _
70
- Right$("00000000" & Hex(colChilds.Item(J)(0)), 8) & " - " & _
71
- strClass & " - " & strTitle)
72
- Else
73
- ' 子コントロールの情報をツリービューへ追加
74
- Call TreeView1.Nodes.Add( _
75
- "R" & Right$("00000000" & Hex(colChilds.Item(1)(0)), 8), _
76
- tvwChild, "C" & _
77
- Right$("00000000" & Hex(colChilds.Item(J)(0)), 8), _
78
- Right$("00000000" & Hex(colChilds.Item(J)(0)), 8) & " - " & _
79
- strClass & " - " & strTitle)
80
- End If
81
- Next J
82
- End If
83
- Next i
84
- End Sub
85
- ```
86
-
87
- ```ここに言語を入力
88
- 【ハンドル情報のみをTreeView2に列挙するコード】
89
-
90
- Private Sub NodesS()
91
- Dim i As Long
92
- Dim J As Long
93
- Dim strClass As String
94
- Dim strTitle As String
95
- Dim strSpace As String
96
-
97
- ' ウィンドウとコントロールの全ての情報を取得
98
- Dim colWindows As Collection
99
- Set colWindows = GetAllWindows()
100
-
101
- ' 親ウィンドウ毎のコレクションループ
102
- For i = 1 To colWindows.Count
103
- ' 子コントロール毎のコレクション取得
104
- Dim colChilds As Collection
105
- Set colChilds = colWindows.Item(i)
106
-
107
- 'If colChilds.Count >= 1 Then ' 全ての親ウィンドウを対象
108
- If colChilds.Count > 1 Then ' 子コントロールを持つ物のみ対象
109
- ' 子コントロール毎のコレクションループ
110
- For J = 1 To colChilds.Count
111
- If J = 1 Then
112
- ' 親ウィンドウの情報をツリービューへ追加
113
- Call TreeView2.Nodes.Add(, , _
114
- "R" & Right$("00000000" & Hex(colChilds.Item(J)(0)), 8), _
115
- "&H" & Right$("00000000" & Hex(colChilds.Item(J)(0)), 8))
116
- Else
117
- ' 子コントロールの情報をツリービューへ追加
118
- Call TreeView2.Nodes.Add("R" & Right$("00000000" & Hex(colChilds.Item(1)(0)), 8), _
119
- tvwChild, _
120
- "C" & Right$("00000000" & Hex(colChilds.Item(J)(0)), 8), _
121
- "&H" & Right$("00000000" & Hex(colChilds.Item(J)(0)), 8))
122
- End If
123
- Next J
124
- End If
125
- Next i
126
- End Sub
127
- ```
128
-
129
- ```ここに言語を入力
130
- 【外部ハンドルを取得して文字列とクリック処理を送信するコード】
131
- 'Login画面の親子ハンドルの取得とLoginID・Password・OKボタンを送信
132
- hWndChild1 = 0
133
- hWndChild2 = 0
134
- hWndChild3 = 0
135
- Do
136
- hwndParent = FindWindow("Class名", "title")
137
- Call NodesS
138
- Call NodesW
139
- If hwndParent <> 0 Then
140
- Call NodesS
141
- Call NodesW
142
- For idx = 1 To TreeView2.Nodes.Count
143
- If CLng(TreeView2.Nodes(idx)) = hwndParent Then
144
- hWndChild1 = TreeView2.Nodes(idx + 9)
145
- hWndChild2 = TreeView2.Nodes(idx + 10)
146
- hWndChild3 = TreeView2.Nodes(idx + 11)
147
- Exit Do
148
- End If
149
- Next
150
- End If
151
- DoEvents
152
- Loop
153
-
154
- st = Now
155
- Do
156
- DoEvents
157
- Ret = IsWindowEnabled(hWndChild1)
158
- If DateDiff("s", st, Now) >= 10 Then Exit Do
159
- Loop While Ret = 0
160
-
161
- If Ret = 0 Then
162
- Debug.Print "time out"
163
- End If
164
-
165
- SetForegroundWindow hwndParent
166
- strDt = "LoginID"
167
- lngRc = SendMessage(hWndChild1, WM_SETTEXT, 0, strDt)
168
- strDt2 = "password"
169
- lngRc = SendMessage(hWndChild2, WM_SETTEXT, 0, strDt2)
170
- lngRc = SendMessage(hWndChild3, BM_CLICK, 0, 0)
171
- ```
172
-
173
- 現在標準モジュールは、VB.NET側のコードを使用ており
1
+ 的確な回答が得られなかったためのコメントは削除いたしました
174
-
175
- どうかご教示の程、よろしくお願い致します。

2

error項目の削除 本題は変換について知りたい

2018/10/02 08:26

投稿

dewdtm
dewdtm

スコア8

title CHANGED
File without changes
body CHANGED
@@ -171,13 +171,5 @@
171
171
  ```
172
172
 
173
173
  現在、標準モジュールは、VB.NET側のコードを使用しております。
174
- また、当方が修正できそうにないエラーが出る箇所は、
175
- .Nodes
176
- DoEvents
177
- Right$
178
- Set
179
- LenB
180
- strSpace = StrConv(String(50, " "), vbFromUnicode)
181
174
 
182
- かなり複雑になっておりますが、
183
175
  どうかご教示の程、よろしくお願い致します。

1

コードブロックの適用

2018/10/02 06:37

投稿

dewdtm
dewdtm

スコア8

title CHANGED
File without changes
body CHANGED
@@ -21,9 +21,9 @@
21
21
  そして、ハンドル取得⇒送信すること、
22
22
  この三点のコードを変換したい思っております。
23
23
 
24
+ ```ここに言語を入力
24
- ここからコードーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
25
+ 【ハンドル+Class名+title情報をTreeView1に列挙するコード
25
26
 
26
- 【ハンドル+Class名+title情報をTreeView1に列挙するコード】
27
27
  Private Sub NodesW()
28
28
  Dim i As Long
29
29
  Dim J As Long
@@ -82,7 +82,9 @@
82
82
  End If
83
83
  Next i
84
84
  End Sub
85
+ ```
85
86
 
87
+ ```ここに言語を入力
86
88
  【ハンドル情報のみをTreeView2に列挙するコード】
87
89
 
88
90
  Private Sub NodesS()
@@ -122,7 +124,9 @@
122
124
  End If
123
125
  Next i
124
126
  End Sub
127
+ ```
125
128
 
129
+ ```ここに言語を入力
126
130
  【外部ハンドルを取得して文字列とクリック処理を送信するコード】
127
131
  'Login画面の親子ハンドルの取得とLoginID・Password・OKボタンを送信
128
132
  hWndChild1 = 0
@@ -164,9 +168,8 @@
164
168
  strDt2 = "password"
165
169
  lngRc = SendMessage(hWndChild2, WM_SETTEXT, 0, strDt2)
166
170
  lngRc = SendMessage(hWndChild3, BM_CLICK, 0, 0)
171
+ ```
167
172
 
168
- ここまでーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
169
-
170
173
  現在、標準モジュールは、VB.NET側のコードを使用しております。
171
174
  また、当方が修正できそうにないエラーが出る箇所は、
172
175
  .Nodes