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 );