使用Windows API控制電腦靜音與音量
使用Windows API控制電腦靜音與音量
// 宣告常式
private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
private const int APPCOMMAND_VOLUME_UP = 0x0a0000;
private const int APPCOMMAND_VOLUME_DOWN = 0x090000;
private const int WM_APPCOMMAND = 0x319;
[DllImport("user32.dll")]
public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private void btnVup_Click(object sender, EventArgs e)
{
// 聲音變大
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_UP);
}
private void btnVdown_Click(object sender, EventArgs e)
{
// 聲音變小
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_DOWN);
}
private void btnMute_Click(object sender, EventArgs e)
{
// 靜音
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_MUTE);
}
抱走Acer Aspire one、您還持續「鐵」下去!加油、終點要到咯!(您眼睛好像在看...)^_^
用SendMessage去操作控制音量?
寫法好像怪怪的
你有實驗過真的能用嗎?
如果我沒記錯的話
操作控制音量應該要去Call mciSendCommand 這個API
去送 MCI_SETAUDIO 命令
以 MCI_DGV_SETAUDIO_VALUE | MCI_DGV_SETAUDIO_ITEM
mciSendCommand
http://msdn.microsoft.com/en-us/library/windows/desktop/dd757160%28v=vs.85%29.aspx
MCI_SETAUDIO
http://msdn.microsoft.com/en-us/library/windows/desktop/dd743468%28v=vs.85%29.aspx