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

回答編集履歴

2

見直しキャンペーン中

2023/07/29 07:19

投稿

TN8001
TN8001

スコア10114

answer CHANGED
@@ -1,6 +1,5 @@
1
1
  わかりました!!
2
2
  マニフェストに`disableWindowFiltering`の設定がいるようです。
3
-
4
3
  [c++ - How to get a relational window tree like Spy++ does? - Stack Overflow](https://stackoverflow.com/questions/48613313/how-to-get-a-relational-window-tree-like-spy-does)
5
4
  [アプリケーションマニフェスト - Win32 apps | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/win32/sbscs/application-manifests#disablewindowfiltering)
6
5
 

1

見直しキャンペーン中

2023/07/29 07:17

投稿

TN8001
TN8001

スコア10114

answer CHANGED
@@ -1,80 +1,77 @@
1
- わかりました!!
2
- マニフェストに`disableWindowFiltering`の設定がいるようです。
3
-
4
- [c++ - How to get a relational window tree like Spy++ does? - Stack Overflow](https://stackoverflow.com/questions/48613313/how-to-get-a-relational-window-tree-like-spy-does)
5
-
6
- [アプリケーションマニフェスト - Win32 apps | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/win32/sbscs/application-manifests#disablewindowfiltering)
7
-
8
-
9
- `DllImport`を書くのが面倒だったため↓を使用しました(使わない場合NativeMethods.txtは不要)
10
- [NuGet Gallery | Microsoft.Windows.CsWin32 0.1.588-beta](https://www.nuget.org/packages/Microsoft.Windows.CsWin32/0.1.588-beta)
11
-
12
- 重要なのは**app.manifest**です。他は好きにしてください。
13
-
14
- ```C#
15
- using System;
16
- using System.Runtime.Versioning;
17
- using Windows.Win32;
18
- using Windows.Win32.Foundation;
19
-
20
- namespace Questions364547
21
- {
22
- class Program
23
- {
24
- static void Main()
25
- {
26
- if (OperatingSystem.IsWindowsVersionAtLeast(5))
27
- {
28
- PInvoke.EnumWindows(CallBack, 0);
29
- }
30
- }
31
-
32
- [SupportedOSPlatform("windows5.0")]
33
- static BOOL CallBack(HWND handle, LPARAM param1)
34
- {
35
- unsafe
36
- {
37
- fixed (char* chars = new char[256])
38
- {
39
- if (PInvoke.GetClassName(handle, chars, 256) == 0) return true;
40
-
41
- if (new string(chars) != "Windows.Internal.Shell.TabProxyWindow")
42
- return true;
43
- }
44
-
45
- var size = PInvoke.GetWindowTextLength(handle) + 1;
46
- fixed (char* chars = new char[size])
47
- {
48
- if (PInvoke.GetWindowText(handle, chars, size) == 0) return true;
49
-
50
- Console.WriteLine($"タイトル: {new string(chars)}");
51
- }
52
-
53
- return true;
54
- }
55
- }
56
- }
57
- }
58
- ```
59
-
60
- app.manifest
61
- ```xml
62
- <?xml version="1.0" encoding="utf-8"?>
63
- <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
64
-
65
- <asmv3:application>
66
- <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2011/WindowsSettings">
67
- <disableWindowFiltering>true</disableWindowFiltering>
68
- </asmv3:windowsSettings>
69
- </asmv3:application>
70
-
71
- </assembly>
72
- ```
73
-
74
- NativeMethods.txt
75
- ```
76
- EnumWindows
77
- GetClassName
78
- GetWindowText
79
- GetWindowTextLength
1
+ わかりました!!
2
+ マニフェストに`disableWindowFiltering`の設定がいるようです。
3
+
4
+ [c++ - How to get a relational window tree like Spy++ does? - Stack Overflow](https://stackoverflow.com/questions/48613313/how-to-get-a-relational-window-tree-like-spy-does)
5
+ [アプリケーションマニフェスト - Win32 apps | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/win32/sbscs/application-manifests#disablewindowfiltering)
6
+
7
+
8
+ `DllImport`を書くのが面倒だったため↓を使用しました(使わない場合NativeMethods.txtは不要)
9
+ [NuGet Gallery | Microsoft.Windows.CsWin32 0.1.588-beta](https://www.nuget.org/packages/Microsoft.Windows.CsWin32/0.1.588-beta)
10
+
11
+ 重要なのは**app.manifest**です。他は好きにしてください。
12
+
13
+ ```cs
14
+ using System;
15
+ using System.Runtime.Versioning;
16
+ using Windows.Win32;
17
+ using Windows.Win32.Foundation;
18
+
19
+ namespace Questions364547
20
+ {
21
+ class Program
22
+ {
23
+ static void Main()
24
+ {
25
+ if (OperatingSystem.IsWindowsVersionAtLeast(5))
26
+ {
27
+ PInvoke.EnumWindows(CallBack, 0);
28
+ }
29
+ }
30
+
31
+ [SupportedOSPlatform("windows5.0")]
32
+ static BOOL CallBack(HWND handle, LPARAM param1)
33
+ {
34
+ unsafe
35
+ {
36
+ fixed (char* chars = new char[256])
37
+ {
38
+ if (PInvoke.GetClassName(handle, chars, 256) == 0) return true;
39
+
40
+ if (new string(chars) != "Windows.Internal.Shell.TabProxyWindow")
41
+ return true;
42
+ }
43
+
44
+ var size = PInvoke.GetWindowTextLength(handle) + 1;
45
+ fixed (char* chars = new char[size])
46
+ {
47
+ if (PInvoke.GetWindowText(handle, chars, size) == 0) return true;
48
+
49
+ Console.WriteLine($"タイトル: {new string(chars)}");
50
+ }
51
+
52
+ return true;
53
+ }
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ ```xml:app.manifest
60
+ <?xml version="1.0" encoding="utf-8"?>
61
+ <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
62
+
63
+ <asmv3:application>
64
+ <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2011/WindowsSettings">
65
+ <disableWindowFiltering>true</disableWindowFiltering>
66
+ </asmv3:windowsSettings>
67
+ </asmv3:application>
68
+
69
+ </assembly>
70
+ ```
71
+
72
+ ```txt:NativeMethods.txt
73
+ EnumWindows
74
+ GetClassName
75
+ GetWindowText
76
+ GetWindowTextLength
80
77
  ```