質問編集履歴

4

ソースコード追加

2021/10/14 21:30

投稿

qqfsdfsafd
qqfsdfsafd

スコア599

test CHANGED
File without changes
test CHANGED
@@ -329,3 +329,169 @@
329
329
  p.MainWindowHandleも間違い?
330
330
 
331
331
  ペイントのクライアント領域のウインドウハンドルを指定しないとダメ?
332
+
333
+
334
+
335
+ 追記
336
+
337
+ 子ウインドウを拾ってもダメだ
338
+
339
+ ```C#
340
+
341
+ using System;
342
+
343
+ using System.Drawing;
344
+
345
+ using System.Runtime.InteropServices;
346
+
347
+ using System.Windows.Forms;
348
+
349
+
350
+
351
+ namespace Transparent
352
+
353
+ {
354
+
355
+ public partial class Form1 : Form
356
+
357
+ {
358
+
359
+ private const int SWP_NOSIZE = 0x0001;
360
+
361
+ private const int SWP_NOMOVE = 0x0002;
362
+
363
+ private const int SWP_SHOWWINDOW = 0x0040;
364
+
365
+
366
+
367
+ private const int HWND_TOPMOST = -1;
368
+
369
+ private const int HWND_NOTOPMOST = -2;
370
+
371
+
372
+
373
+ static bool isTop = false;
374
+
375
+ public Form1()
376
+
377
+ {
378
+
379
+ InitializeComponent();
380
+
381
+ this.TransparencyKey = Color.Red;
382
+
383
+ StartTimer();
384
+
385
+ }
386
+
387
+ private Timer _timer = null;
388
+
389
+
390
+
391
+ private void StartTimer()
392
+
393
+ {
394
+
395
+ Timer timer = new Timer();
396
+
397
+ timer.Tick += new EventHandler(TickHandler);
398
+
399
+ timer.Interval = 2000;
400
+
401
+ timer.Start();
402
+
403
+ _timer = timer;
404
+
405
+ }
406
+
407
+
408
+
409
+ private void StopTimer()
410
+
411
+ {
412
+
413
+ if (_timer == null)
414
+
415
+ {
416
+
417
+ return;
418
+
419
+ }
420
+
421
+ _timer.Stop();
422
+
423
+ _timer = null;
424
+
425
+ }
426
+
427
+
428
+
429
+ private void TickHandler(object sender, EventArgs e)
430
+
431
+ {
432
+
433
+ foreach (System.Diagnostics.Process p in
434
+
435
+ System.Diagnostics.Process.GetProcesses())
436
+
437
+ {
438
+
439
+ if (p.MainWindowTitle.Equals("無題 - ペイント"))
440
+
441
+ {
442
+
443
+ if (isTop)
444
+
445
+ {
446
+
447
+ isTop = false;
448
+
449
+ this.TopMost = false;
450
+
451
+ SetWindowPos(p.MainWindowHandle, HWND_TOPMOST, 0, 0, 0, 0,
452
+
453
+ SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
454
+
455
+ SetWindowPos(p.MainWindowHandle, HWND_NOTOPMOST, 0, 0, 0, 0,
456
+
457
+ SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
458
+
459
+ }
460
+
461
+ else
462
+
463
+ {
464
+
465
+ isTop = true;
466
+
467
+ this.TopMost = true;
468
+
469
+ }
470
+
471
+ }
472
+
473
+ }
474
+
475
+ }
476
+
477
+ [DllImport("user32.dll", SetLastError = true)]
478
+
479
+ private static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
480
+
481
+ [DllImport("user32.dll", SetLastError = true)]
482
+
483
+ [return: MarshalAs(UnmanagedType.Bool)]
484
+
485
+ private static extern bool SetWindowPos(IntPtr hWnd,
486
+
487
+ int hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);
488
+
489
+ }
490
+
491
+ }
492
+
493
+ ```
494
+
495
+ 今のところ、これが限界。
496
+
497
+ もっといい方法はありませんか?

3

ソースコード追加

2021/10/14 21:30

投稿

qqfsdfsafd
qqfsdfsafd

スコア599

test CHANGED
File without changes
test CHANGED
@@ -173,3 +173,159 @@
173
173
  ハンドルが間違っているのかと思い、変えてみましたがやっぱりダメでした。
174
174
 
175
175
  なぜでしょうか?
176
+
177
+
178
+
179
+ 追記
180
+
181
+ ```C#
182
+
183
+ using System;
184
+
185
+ using System.Collections.Generic;
186
+
187
+ using System.ComponentModel;
188
+
189
+ using System.Data;
190
+
191
+ using System.Drawing;
192
+
193
+ using System.Linq;
194
+
195
+ using System.Runtime.InteropServices;
196
+
197
+ using System.Text;
198
+
199
+ using System.Threading.Tasks;
200
+
201
+ using System.Windows.Forms;
202
+
203
+
204
+
205
+ namespace Transparent
206
+
207
+ {
208
+
209
+ public partial class Form1 : Form
210
+
211
+ {
212
+
213
+ public Form1()
214
+
215
+ {
216
+
217
+ InitializeComponent();
218
+
219
+ this.TransparencyKey = Color.Red;
220
+
221
+ }
222
+
223
+ override protected void OnMouseDown(MouseEventArgs e)
224
+
225
+ {
226
+
227
+ foreach (System.Diagnostics.Process p in
228
+
229
+ System.Diagnostics.Process.GetProcesses())
230
+
231
+ {
232
+
233
+ if (p.MainWindowTitle.Equals("無題 - ペイント") ||
234
+
235
+ p.MainWindowTitle.Equals("Form2"))
236
+
237
+ {
238
+
239
+ SendMessage(p.MainWindowHandle, 0x0201, (IntPtr)0x0001, (IntPtr)MakeLParam(e.X, e.Y));
240
+
241
+ }
242
+
243
+ }
244
+
245
+ }
246
+
247
+ override protected void OnMouseUp(MouseEventArgs e)
248
+
249
+ {
250
+
251
+ foreach (System.Diagnostics.Process p in
252
+
253
+ System.Diagnostics.Process.GetProcesses())
254
+
255
+ {
256
+
257
+ if (p.MainWindowTitle.Equals("無題 - ペイント") ||
258
+
259
+ p.MainWindowTitle.Equals("Form2"))
260
+
261
+ {
262
+
263
+ SendMessage(p.MainWindowHandle, 0x0202, (IntPtr)0, (IntPtr)0);
264
+
265
+ }
266
+
267
+ }
268
+
269
+ }
270
+
271
+
272
+
273
+ protected override void OnMouseMove(MouseEventArgs e)
274
+
275
+ {
276
+
277
+ foreach (System.Diagnostics.Process p in
278
+
279
+ System.Diagnostics.Process.GetProcesses())
280
+
281
+ {
282
+
283
+ if (p.MainWindowTitle.Equals("無題 - ペイント") ||
284
+
285
+ p.MainWindowTitle.Equals("Form2"))
286
+
287
+ {
288
+
289
+ IntPtr lParam = (IntPtr)MakeLParam(e.X, e.Y);
290
+
291
+ SendMessage(p.MainWindowHandle, 0x0200, (IntPtr)0, lParam);
292
+
293
+ }
294
+
295
+ }
296
+
297
+ }
298
+
299
+ public static int MakeLParam(int wLow, int wHigh)
300
+
301
+ {
302
+
303
+ return (((short)wHigh << 16) | (wLow & 0xffff));
304
+
305
+ }
306
+
307
+ [DllImport("user32.dll")]
308
+
309
+ extern static System.IntPtr SendMessage(
310
+
311
+ System.IntPtr hWnd, // 送信先ウィンドウのハンドル
312
+
313
+ System.UInt32 Msg, // メッセージ
314
+
315
+ System.IntPtr wParam, // メッセージの最初のパラメータ
316
+
317
+ System.IntPtr lParam // メッセージの 2 番目のパラメータ
318
+
319
+ );
320
+
321
+ }
322
+
323
+ }
324
+
325
+ ```
326
+
327
+ えっと、透明ウインドウをもう一つ作って、もう一つの透明ウインドウ上でマウスをクリックしたら、ちゃんとOnMouseDownの中に入って来ました。なぜペイントにメッセージが渡らないのでしょうか?
328
+
329
+ p.MainWindowHandleも間違い?
330
+
331
+ ペイントのクライアント領域のウインドウハンドルを指定しないとダメ?

2

ソースコード追加

2021/10/14 19:33

投稿

qqfsdfsafd
qqfsdfsafd

スコア599

test CHANGED
File without changes
test CHANGED
@@ -155,3 +155,21 @@
155
155
  いやいや、今回はこれが課題です。
156
156
 
157
157
  なぜSendMessageがペイントに行かないのかわかりません。
158
+
159
+
160
+
161
+ 追記
162
+
163
+ ```C#
164
+
165
+ SendMessage(p.Handle, 0x0201, (IntPtr)0x0001, (IntPtr)MakeLParam(e.X, e.Y));
166
+
167
+
168
+
169
+ SendMessage(p.MainWindowHandle, 0x0201, (IntPtr)0x0001, (IntPtr)MakeLParam(e.X, e.Y));
170
+
171
+ ```
172
+
173
+ ハンドルが間違っているのかと思い、変えてみましたがやっぱりダメでした。
174
+
175
+ なぜでしょうか?

1

2021/10/14 19:08

投稿

qqfsdfsafd
qqfsdfsafd

スコア599

test CHANGED
File without changes
test CHANGED
@@ -147,3 +147,11 @@
147
147
  SendMessageがうまくいってないようです。
148
148
 
149
149
  なぜでしょうか?
150
+
151
+
152
+
153
+ 補足
154
+
155
+ いやいや、今回はこれが課題です。
156
+
157
+ なぜSendMessageがペイントに行かないのかわかりません。