C # and VB. net use Windows API to control system volume and mute

Source: Internet
Author: User
Document directory
  • I. Introduce API Definitions
  • Ii. Increase the volume
  • Iii. volume reduction
  • Iv. Mute and recovery (restore the original state twice)

Today, a friend asked: how to use. Net to control the volume and mute of the system?

I checked the information and found the method for using the API. It was very simple to use, but I didn't know why the specific values of some parameters were obtained. it was practical to use them first, haha

The implementation code is as follows:

I. Introduce API Definitions
[Dllimport ("user32.dll", charset = charset. auto, setlasterror = true)] Static extern intptr sendmessage (intptr hwnd, uint MSG, uint wparam, uint lparam); const uint wm_appcommand = 0x319; const uint appcommand_volume_up = 0x0a; const uint appcommand_volume_down = 0x09; const uint appcommand_volume_mute = 0x08;
Ii. Increase the volume

Sendmessage (this. Handle, wm_appcommand, 0x30292, appcommand_volume_up * 0x10000 );
Iii. volume reduction
Sendmessage (this. Handle, wm_appcommand, 0x30292, appcommand_volume_down * 0x10000 );
Iv. Mute and recovery (restore the original state twice)
Sendmessage (this. Handle, wm_appcommand, 0x200eb0, appcommand_volume_mute x 0x10000 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.