回答編集履歴

1

修正

2020/04/29 12:32

投稿

yuujiMotoki
yuujiMotoki

スコア90

test CHANGED
@@ -4,220 +4,4 @@
4
4
 
5
5
 
6
6
 
7
-
8
-
9
-
10
-
11
- ```C#
12
-
13
-
14
-
15
- using System;
16
-
17
- using System.Runtime.InteropServices;
18
-
19
- using System.Text;
20
-
21
-
22
-
23
- namespace ExcelVbaExt
24
-
25
- {
26
-
27
- [ComVisible(true)]
28
-
29
- [ClassInterface(ClassInterfaceType.AutoDual)]
30
-
31
- public class InnerClass
32
-
33
- {
34
-
35
- public int WHnd;
36
-
37
- public string APPName;
38
-
39
- public int Left;
40
-
41
- public int Top;
42
-
43
- public int Right;
44
-
45
- public int Bottom;
46
-
47
- }
48
-
49
-
50
-
51
- [ComVisible(true)]
52
-
53
- [ClassInterface(ClassInterfaceType.AutoDual)]
54
-
55
- public class ClassApp
56
-
57
- {
58
-
59
- public InnerClass[] Interface;
60
-
61
- }
62
-
63
-
64
-
65
- [ComVisible(true)]
66
-
67
- [InterfaceType(ComInterfaceType.InterfaceIsDual)]
68
-
69
- public interface IWindowWhnd
70
-
71
- {
72
-
73
- ClassApp WindowTitleList();
74
-
75
- }
76
-
77
-
78
-
79
- [ClassInterface(ClassInterfaceType.None)]
80
-
81
- public class WindowWhnd : IWindowWhnd
82
-
83
- {
84
-
85
- public static ClassApp _hWndList;
86
-
87
- public static int count;
88
-
89
-
90
-
91
- [DllImport("user32.dll")]
92
-
93
- private static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
94
-
95
-
96
-
97
- [StructLayout(LayoutKind.Sequential)]
98
-
99
- private struct RECT
100
-
101
- {
102
-
103
- public int left;
104
-
105
- public int top;
106
-
107
- public int right;
108
-
109
- public int bottom;
110
-
111
- }
112
-
113
-
114
-
115
- [DllImport("user32.dll")]
116
-
117
- [return: MarshalAs(UnmanagedType.Bool)]
118
-
119
- private extern static bool EnumWindows(EnumWindowsDelegate lpEnumFunc, IntPtr lparam);
120
-
121
-
122
-
123
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
124
-
125
- private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
126
-
127
-
128
-
129
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
130
-
131
- private static extern int GetWindowTextLength(IntPtr hWnd);
132
-
133
-
134
-
135
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
136
-
137
- private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
138
-
139
-
140
-
141
- private delegate bool EnumWindowsDelegate(IntPtr hWnd, IntPtr lparam);
142
-
143
-
144
-
145
- public ClassApp WindowTitleList()
146
-
147
- {
148
-
149
- count = 0;
150
-
151
- _hWndList = new ClassApp();
152
-
153
- _hWndList.Interface = new InnerClass[1];
154
-
155
-
156
-
157
- EnumWindows(new EnumWindowsDelegate(EnumWindowCallBack), IntPtr.Zero);
158
-
159
-
160
-
161
- return _hWndList;
162
-
163
- }
164
-
165
-
166
-
167
- private static bool EnumWindowCallBack(IntPtr hWnd, IntPtr lparam)
168
-
169
- {
170
-
171
- int textLen = GetWindowTextLength(hWnd);
172
-
173
- if (0 < textLen)
174
-
175
- {
176
-
177
- StringBuilder tsb = new StringBuilder(textLen + 1);
178
-
179
- GetWindowText(hWnd, tsb, tsb.Capacity);
180
-
181
-
182
-
183
- RECT rect;
184
-
185
- bool flag = GetWindowRect(hWnd, out rect);
186
-
187
-
188
-
189
- _hWndList.Interface[count] = new InnerClass();
190
-
191
- _hWndList.Interface[count].WHnd = (int)hWnd;
192
-
193
- _hWndList.Interface[count].APPName = tsb.ToString();
194
-
195
- _hWndList.Interface[count].Left = rect.left;
196
-
197
- _hWndList.Interface[count].Top = rect.top;
198
-
199
- _hWndList.Interface[count].Right = rect.right;
200
-
201
- _hWndList.Interface[count].Bottom = rect.bottom;
202
-
203
- count += 1;
204
-
205
- Array.Resize(ref _hWndList.Interface, count+1);
7
+ Array.Resize(ref _hWndList.Interface, count **+1** );
206
-
207
- }
208
-
209
- return true;
210
-
211
- }
212
-
213
- }
214
-
215
- }
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
- ```