Mute Windows Volume using C#

后端 未结 7 1322
广开言路
广开言路 2020-11-30 05:01

Anyone know how to programmatically mute the Windows XP Volume using C#?

7条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 05:43

    Declare this for P/Invoke:

    private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
    private const int WM_APPCOMMAND = 0x319;
    
    [DllImport("user32.dll")]
    public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
    

    And then use this line to mute/unmute the sound.

    SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr) APPCOMMAND_VOLUME_MUTE);
    

提交回复
热议问题