public static HWND CyberpunkWindowActiv() { HWND CurrentActiveWindow = GetForegroundWindow(); if (CurrentActiveWindow == IntPtr.Zero) { //this triggers Debug.WriteLine("CurrentActiveWindow: " + CurrentActiveWindow.ToString()); Debug.WriteLine("Unable to get window handle."); } foreach (var process in Process.GetProcessesByName("Cyberpunk2077")) { if (CurrentActiveWindow == process.MainWindowHandle) { VolumeMixer.SetApplicationMute(process.Id, false); } else { VolumeMixer.SetApplicationMute(process.Id, true); } return(process.MainWindowHandle); } return(HWND.Zero); }
private static void renewF9F10vol() { dictpIDF9F10.Clear(); foreach (Process processname in getProcessByName(processNameF9F10)) { if (VolumeMixer.GetApplicationVolume(processname.Id) == null) { //return; } else { if (!dictpIDF9F10.ContainsKey(processname.Id)) //if process Id isnt part of table yet do.... { currentVolumeF9F10 = (float)VolumeMixer.GetApplicationVolume(processname.Id); dictpIDF9F10.Add(processname.Id, processname); } } } }
// ################################ (End) ofTheHook ################################ static void setVolume(string programmClass, string windowName, IntPtr?processHandle = null) //as soon as a parameter have a default value they become OPTIONAL, multiple Optional parameters require an argument { if (processHandle == null) { IntPtr hWnd = FindWindow(programmClass, windowName); if (hWnd == IntPtr.Zero) { return; } GetWindowThreadProcessId(hWnd, out pID); if (pID == 0) { return; } } else { pID = (uint)processHandle; } float newApplicationVolume = -1; //float? is a float accepting also NULL as value exists for every Datatype (except string which can be NULL allready) //Get valid pID's/pID-List if (VolumeMixer.GetApplicationVolume((int)pID) == null) { return; } if (programmClass == "F9" || programmClass == "F10") { newApplicationVolume = currentVolumeF9F10; } else if (programmClass == programmClassF11F12) { newApplicationVolume = currentVolumeF11F12; } if (newApplicationVolume != -1) { VolumeMixer.SetApplicationVolume((int)pID, newApplicationVolume); } }
private static void renewF11F12vol() { var hWnd = FindWindow(programmClassF11F12, windowNameF11F12); if (hWnd == IntPtr.Zero) { //return; } else { GetWindowThreadProcessId(hWnd, out pID); if (pID == 0) { //return; } else { currentVolumeF11F12 = (float)VolumeMixer.GetApplicationVolume((int)pID); validProcessF11F12 = 1; //hashpIDF11F12.Add(pID); } } }