private void Mute() { try { VolumeManager volume = GetVolumeManager(); if (volume != null && !volume.IsMute) { volume.IsMute = true; oldMuteState = false; } } catch { }//浏览器已打开但未载入网页 }
private VolumeManager GetVolumeManager() { if (volumeManager == null) { //获得浏览器进程的窗口句柄 IntPtr browserHwnd = NativeMethods.FindWindowEx(mainForm.Browser.Handle, IntPtr.Zero, null, null); if (browserHwnd == IntPtr.Zero) { return(null); } //获得浏览器进程的PID uint processID; NativeMethods.GetWindowThreadProcessId(browserHwnd, out processID); if (processID == 0U) { return(null); } volumeManager = new VolumeManager(processID); } return(volumeManager); }