雖然不是用 sendmessage 但是解決了你的問題Option ExplicitPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As LongPrivate Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Const KEYEVENTF_KEYUP = &H2Private Sub Command1_Click() "靜音 "keybd_event &HAD, MapVirtualKey(&HAD, 0), 0, 0 "Sleep 100 "keybd_event &HAD, MapVirtualKey(&HAD, 0), KEYEVENTF_KEYUP, 0 "音量減小 "keybd_event &HAE, MapVirtualKey(&HAE, 0), 0, 0 "Sleep 100 "keybd_event &HAE, MapVirtualKey(&HAE, 0), KEYEVENTF_KEYUP, 0 "音量增大 keybd_event &HAF, MapVirtualKey(&HAF, 0), 0, 0 Sleep 100 keybd_event &HAF, MapVirtualKey(&HAF, 0), KEYEVENTF_KEYUP, 0End Sub
雖然不是用 sendmessage 但是解決了你的問題Option ExplicitPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As LongPrivate Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Const KEYEVENTF_KEYUP = &H2Private Sub Command1_Click() "靜音 "keybd_event &HAD, MapVirtualKey(&HAD, 0), 0, 0 "Sleep 100 "keybd_event &HAD, MapVirtualKey(&HAD, 0), KEYEVENTF_KEYUP, 0 "音量減小 "keybd_event &HAE, MapVirtualKey(&HAE, 0), 0, 0 "Sleep 100 "keybd_event &HAE, MapVirtualKey(&HAE, 0), KEYEVENTF_KEYUP, 0 "音量增大 keybd_event &HAF, MapVirtualKey(&HAF, 0), 0, 0 Sleep 100 keybd_event &HAF, MapVirtualKey(&HAF, 0), KEYEVENTF_KEYUP, 0End Sub