控制windows系统音量

网上有一些控制系统音量的方法:

win xp系统可以用mixerOpen等方式;

win 7系统可以用wsapi等方式;WASAPI的全称是Windows Audio Session API(Windows音频会话API),是从Windows Vista之后引入的UAA(Universal Audio Architecture)音频架构所属的API

但是上述方法比较麻烦,当然,如果封装好控制类,可以方便应用;


现在可以用另一种方法,模拟键盘快捷键实现系统音量控制;


1:放大音量:

keybd_event(VK_VOLUME_UP,MapVirtualKey(VK_VOLUME_UP,0),KEYEVENTF_EXTENDEDKEY,0);    
keybd_event(VK_VOLUME_UP,MapVirtualKey(VK_VOLUME_UP,0),KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0);


2:减小音量:

keybd_event(VK_VOLUME_DOWN,MapVirtualKey(VK_VOLUME_DOWN,0),KEYEVENTF_EXTENDEDKEY,0);   
keybd_event(VK_VOLUME_DOWN,MapVirtualKey(VK_VOLUME_DOWN,0),KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); 


3:静音/非静音:

keybd_event(VK_VOLUME_MUTE,MapVirtualKey(VK_VOLUME_MUTE,0),KEYEVENTF_EXTENDEDKEY,0);   
keybd_event(VK_VOLUME_MUTE,MapVirtualKey(VK_VOLUME_MUTE,0),KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0);    

你可能感兴趣的:(VC++)