Програмная регулировка звука (громкости) C#

Добрый день. Решил написать чисто для себя небольшую программку, для регулировки громкости на ПК по хот-кеям, так как мультимедийной клавы нет, а сворачиваться и регулировать громкость не всегда удобно.
Ну к делу, вобщем :)
Прочитал кучу топиков, тем и т.п. нашел несколько полезных статей, все сделал, работает, но есть одно НО. При регулировки громкости из моего приложения ползунок громкости в трее (Системный WinXP) не перемещается. И мне кажется, что я меняю совсем какую-то другую громкость, хоть и системную, но не ту(.
Что писал:

    class VolumeControl
    {
        [DllImport("winmm.dll")]

        public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);


        [DllImport("winmm.dll")]

        public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);

        /// <summary>
        /// Returned current value of System Volume in Windows XP or less.
        /// </summary>
        /// <returns>Returns int between 0 and 100 (min and max value).</returns>
        public static int GetVolumeXP()
        {
            // By the default set the volume to 0
            uint CurrentVolume = 0;
            // At this point, CurrVol gets assigned the volume
            waveOutGetVolume(IntPtr.Zero, out CurrentVolume);
            // Calculate the volume
            ushort CalcVol = (ushort)(CurrentVolume & 0x0000ffff);
            // Get the volume on a scale of 1 to 100 (to fit the trackbar)
            int Value = CalcVol / (ushort.MaxValue / 100);
            // Return result
            return Value;
        }

        /// <summary>
        /// Sets specified System Volume in Windows XP or less.
        /// </summary>
        /// <param name="Value">Value of volume that will be set. Must be between 0 and 100.</param>
        /// <returns>Struct with contained all information on the implementation of this method</returns>
        public static VolumeResult SetVolumeXP(int Value)
        {
            // Create a return variable
            VolumeResult res = new VolumeResult(false, string.Empty);
            // Check the input parameters
            if ((Value > 100) || (Value < 0))
            {
                res.HasError = true;
                res.ErrorText = "Eng: Value must be between 0 and 100. \nRus: Значение должно быть между 0 и 100.";
                return res;
            }
            // Calculate the volume that's being set
            int NewVolume = ((ushort.MaxValue / 100) * Value);
            // Set the same volume for both the left and the right channels
            uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
            // Set the volume
            waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
            return res;
        }
}

Перемення res имеет следующую структуру:

 public struct VolumeResult
    {
        private bool Error;
        private string Text;

        /// <summary>
        /// Create a object of struct with specified parameters.
        /// </summary>
        /// <param name="SetError">Value of variable HasError.</param>
        /// <param name="ErrorText">Value of variable ErrorText.</param>
        public VolumeResult(bool SetError, string ErrorText)
        {
            Error = SetError;
            Text = ErrorText;
        }

        /// <summary>
        /// Gets or sets variable HasError. If "true" - the error occurred, if "false" - didn't.
        /// </summary>
        public bool HasError
        {
            get {return Error;}
            set {Error=value;}
        }

        /// <summary>
        /// Gets or sets text of the error.
        /// </summary>
        public string ErrorText
        {
            get {return Text;}
            set {Text=value;}
        }
    }
По данной проблемы есть вопросы, но нет ответов в интернете. Кто работал с этим, или знаете способ решения — помогите пожалуйста.
Скажите, как менять именно «ту» громкость «их трея» ?:)
👍ПодобаєтьсяСподобалось0
До обраногоВ обраному0
LinkedIn
Дозволені теги: blockquote, a, pre, code, ul, ol, li, b, i, del.
Ctrl + Enter
Дозволені теги: blockquote, a, pre, code, ul, ol, li, b, i, del.
Ctrl + Enter
я писал плеер обычный)
использовал класс Аудио
а в нем уже и есть Volume
может пересмотришь реализацию? ...=)

using Microsoft.DirectX.AudioVideoPlayback;

Спасибо, попробую. Как-то не попадал на эту страницу, хотя по второй ссылке (на указанной Вами странице) был.

Підписатись на коментарі