public void GetDeviceLists() { System.Threading.Thread t = new System.Threading.Thread(() => { // Get the handle of the window IntPtr soundDialogHandle = OpenSoundDialog(0); if (soundDialogHandle == IntPtr.Zero) { return; } // Hide the window if (soundDialogHandle != IntPtr.Zero) { NativeMethods.SetWindowPos(soundDialogHandle, IntPtr.Zero, -100, -100, 100, 100, 0); } // Create the AutomationElement from the window handle AutomationElement aeSoundDialog = AutomationElement.FromHandle(soundDialogHandle); // Get the TabControl AutomationElement aeTab = aeSoundDialog.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Tab)); // Switch to Playback tab in case the user opened the window with an other tab selected SwitchTab(aeTab, 0); // Get the list of available playback devices playbackDevices = new List <SoundDevice>(); playbackDevices = GetDeviceList(aeSoundDialog); // Switch to Recording tab SwitchTab(aeTab, 1); // Get the list of available recording devices recordingDevices = new List <SoundDevice>(); recordingDevices = GetDeviceList(aeSoundDialog); CloseDialog(aeSoundDialog); DeviceListEventArgs e = new DeviceListEventArgs(); e.playbackDevices = playbackDevices; e.recordingDevices = recordingDevices; if (OnDeviceListReturned != null) { OnDeviceListReturned(this, e); } }); t.Start(); }
public void GetDeviceLists() { System.Threading.Thread t = new System.Threading.Thread(() => { // Get the handle of the window IntPtr soundDialogHandle = OpenSoundDialog(0); if (soundDialogHandle == IntPtr.Zero) return; // Hide the window if (soundDialogHandle != IntPtr.Zero) NativeMethods.SetWindowPos(soundDialogHandle, IntPtr.Zero, -100, -100, 100, 100, 0); // Create the AutomationElement from the window handle AutomationElement aeSoundDialog = AutomationElement.FromHandle(soundDialogHandle); // Get the TabControl AutomationElement aeTab = aeSoundDialog.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Tab)); // Switch to Playback tab in case the user opened the window with an other tab selected SwitchTab(aeTab, 0); // Get the list of available playback devices playbackDevices = new List<SoundDevice>(); playbackDevices = GetDeviceList(aeSoundDialog); // Switch to Recording tab SwitchTab(aeTab, 1); // Get the list of available recording devices recordingDevices = new List<SoundDevice>(); recordingDevices = GetDeviceList(aeSoundDialog); CloseDialog(aeSoundDialog); DeviceListEventArgs e = new DeviceListEventArgs(); e.playbackDevices = playbackDevices; e.recordingDevices = recordingDevices; if (OnDeviceListReturned != null) OnDeviceListReturned(this, e); }); t.Start(); }