private static void DebugAddMockDevice() { var id = Guid.NewGuid().ToString(); var devManager = WindowsAudioFactory.Create(AudioDeviceKind.Playback); var devManagerNotify = (Interop.MMDeviceAPI.IMMNotificationClient)devManager; var mockDevice = new DataModel.Audio.Mocks.AudioDevice(id, devManager); AddMockApp(mockDevice, "System Sounds", "*SystemSounds", AppInformationFactory.CreateForProcess(0).SmallLogoPath); AddMockApp(mockDevice, "Firefaux", "Firefaux", @"%ProgramFiles%\Mozilla Firefox\firefox.exe"); AddMockApp(mockDevice, "Chr0me", "Chr0me", @"%ProgramFilesx86%\Google\Chrome\Application\chrome.exe"); var addInfo = devManager.GetType().GetMethod("Add", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); addInfo.Invoke(devManager, new object[] { mockDevice }); }
private static IAudioDeviceSession FindForegroundApp(ObservableCollection <IAudioDeviceSession> groups) { var hWnd = User32.GetForegroundWindow(); var foregroundClassName = new StringBuilder(User32.MAX_CLASSNAME_LENGTH); User32.GetClassName(hWnd, foregroundClassName, foregroundClassName.Capacity); if (hWnd == IntPtr.Zero) { Trace.WriteLine($"ActionProcessor FindForegroundApp: No Window (1)"); return(null); } // ApplicationFrameWindow.exe, find the real hosted process in the child CoreWindow. if (foregroundClassName.ToString() == "ApplicationFrameWindow") { hWnd = User32.FindWindowEx(hWnd, IntPtr.Zero, "Windows.UI.Core.CoreWindow", IntPtr.Zero); } if (hWnd == IntPtr.Zero) { Trace.WriteLine($"ActionProcessor FindForegroundApp: No Window (2)"); return(null); } User32.GetWindowThreadProcessId(hWnd, out uint processId); try { var appInfo = AppInformationFactory.CreateForProcess((int)processId); foreach (var group in groups) { if (group.AppId == appInfo.PackageInstallPath) { Trace.WriteLine($"ActionProcessor FindForegroundApp: {group.DisplayName}"); return(group); } } } catch (Exception ex) { Trace.WriteLine(ex); } Trace.WriteLine("ActionProcessor FindForegroundApp Didn't locate foreground app"); return(null); }