質問編集履歴

3

SendMessageの戻り/引数をIntPtrに変更。

2020/11/04 00:12

投稿

ta2ta2.tk
ta2ta2.tk

スコア0

test CHANGED
File without changes
test CHANGED
@@ -40,16 +40,24 @@
40
40
 
41
41
  private const int MK_LBUTTON = 0x0001;
42
42
 
43
-
43
+ /*
44
44
 
45
45
  [DllImport("user32.dll")]
46
46
 
47
47
  public static extern int SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
48
48
 
49
-
49
+ */
50
+
51
+ // 戻り/引数をIntPtrに変更
50
52
 
51
53
  [DllImport("user32.dll")]
52
54
 
55
+ public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
56
+
57
+
58
+
59
+ [DllImport("user32.dll")]
60
+
53
61
  public extern static int SendMessage(
54
62
 
55
63
  IntPtr hWnd, // 送信先ウィンドウのハンドル
@@ -64,7 +72,7 @@
64
72
 
65
73
 
66
74
 
67
-
75
+ /*
68
76
 
69
77
  /// <summary>
70
78
 
@@ -124,6 +132,68 @@
124
132
 
125
133
  }
126
134
 
135
+ */    
136
+
137
+      /// <summary>
138
+
139
+ /// ボタンハンドルのクリック制御を行います。(IntPtrに変更したため反映)
140
+
141
+ /// </summary>
142
+
143
+ /// <param name="hBtn">ウィンドウボタンハンドル</param>
144
+
145
+ public static void ClickButton(IntPtr hBtn)
146
+
147
+ {
148
+
149
+ MessageBox.Show(GetWindowText(hBtn));
150
+
151
+ SendMessage(hBtn, WM_LBUTTONDOWN, (IntPtr)MK_LBUTTON, IntPtr.Zero);
152
+
153
+ SendMessage(hBtn, WM_LBUTTONDOWN, (IntPtr)MK_LBUTTON, IntPtr.Zero);
154
+
155
+ Thread.Sleep(100);
156
+
157
+ SendMessage(hBtn, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
158
+
159
+
160
+
161
+ SendMessage(hBtn, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
162
+
163
+ }
164
+
165
+
166
+
167
+
168
+
169
+ /// <summary>
170
+
171
+ /// 指定ウィンドウハンドルのテキストを取得します。(IntPtrに変更したため反映)
172
+
173
+ /// </summary>
174
+
175
+ /// <param name="hWnd"></param>
176
+
177
+ /// <returns>テキスト</returns>
178
+
179
+ public static string GetWindowText(IntPtr hWnd)
180
+
181
+ {
182
+
183
+ int length = (int)SendMessage(hWnd, 0xe, IntPtr.Zero, IntPtr.Zero) * 2 + 1;
184
+
185
+ StringBuilder sb = new StringBuilder(new string('\0', length));
186
+
187
+
188
+
189
+ SendMessage(hWnd, 0xd, (uint)sb.Length, sb);
190
+
191
+
192
+
193
+ return sb.ToString();
194
+
195
+ }
196
+
127
197
  ```
128
198
 
129
199
 

2

メッセージキャプチャ画像を追加。

2020/11/04 00:12

投稿

ta2ta2.tk
ta2ta2.tk

スコア0

test CHANGED
File without changes
test CHANGED
@@ -88,7 +88,7 @@
88
88
 
89
89
  SendMessage(hBtn, WM_LBUTTONUP, 0, 0);
90
90
 
91
-
91
+
92
92
 
93
93
  SendMessage(hBtn, BM_CLICK, 0, 0);
94
94
 
@@ -136,7 +136,9 @@
136
136
 
137
137
  プラットフォームターゲットを”Any CPU”から”x86”に変更→クリックされない。
138
138
 
139
+ ボタンハンドルをキャプチャし、ClickButtonメソッドを実行→GETTEXTのみしかキャプチャできない。
139
140
 
141
+ ![ ](dc75c8c0044f5346a026d12b0d03c60c.jpeg)
140
142
 
141
143
 
142
144
 

1

メッセージキャプチャ画像を追加しました。

2020/11/04 00:05

投稿

ta2ta2.tk
ta2ta2.tk

スコア0

test CHANGED
File without changes
test CHANGED
@@ -138,6 +138,8 @@
138
138
 
139
139
 
140
140
 
141
+
142
+
141
143
  ### 補足情報(FW/ツールのバージョンなど)
142
144
 
143
145