}
Cursor.Current = Cursors.Default;
}
Данная процедура использует класс WindowHelper, который позволяет получить информацию о запущенных приложениях. В листинге 7.25 приведен код метода EnumerateTopWindows, который находит все окна запущенных в системе приложений.
public static Window[] EnumerateTopWindows() {
ArrayList windowList = new ArrayList();
IntPtr hWnd = IntPtr.Zero;
Window window = null;
// Получим первое окно
hWnd = GetActiveWindow();
hWnd = GetWindow(hWnd, GW_HWNDFIRST);
while(hWnd != IntPtr.Zero) {
if (IsWindow(hWnd) && IsWindowVisible(hWnd)) {
IntPtr parentWin = GetParent(hWnd);
if ((parentWin == IntPtr.Zero)) {
int length = GetWindowTextLength(hWnd);
if (length > 0) {
string s = new string('\0', length + 1);
GetWindowText(hWnd, s.length + 1);
s = s.Substring(0, s.IndexOf('\0'));
if (s != "Tray" && s != "Start" && s != "Task Manager") {
window = new Window();
window.Handle = hWnd;
window.Text = s;
windowList.Add(window);
}
}
}
}
hWnd = GetWindow(hWnd, GW_HWNDNEXT);