下列代码vb6中程序未响应,请修改:Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Const WM_APPCOMMAND = &H319 Const APPCOMMAND_VOLUME_UP = &HA Const APPCOMMAND_VOLUME_DOWN = &H9 Const APPCOMMAND_VOLUME_MUTE = &H8 Const HWND_BROADCAST = &HFFFF& Public Sub SetSystemVolume(ByVal level As Integer) Dim command As Long command = ((level And &HFFFF&) Or ((APPCOMMAND_VOLUME_UP * &H10000) And &HFFFF0000)) SendMessage HWND_BROADCAST, WM_APPCOMMAND, 0, ByVal command End Sub Public Sub MuteSystemVolume() SendMessage HWND_BROADCAST, WM_APPCOMMAND, 0, ByVal (APPCOMMAND_VOLUME_MUTE * &H10000) End Sub
时间: 2023-06-18 19:02:30 浏览: 274
在 VB6 中,`Long` 类型应该改为 `Integer` 类型。
修改后的代码如下:
```
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
Const WM_APPCOMMAND = &H319
Const APPCOMMAND_VOLUME_UP = &HA
Const APPCOMMAND_VOLUME_DOWN = &H9
Const APPCOMMAND_VOLUME_MUTE = &H8
Const HWND_BROADCAST = &HFFFF&
Public Sub SetSystemVolume(ByVal level As Integer)
Dim command As Long
command = ((level And &HFFFF&) Or ((APPCOMMAND_VOLUME_UP * &H10000) And &HFFFF0000))
SendMessage HWND_BROADCAST, WM_APPCOMMAND, 0, ByVal command
End Sub
Public Sub MuteSystemVolume()
SendMessage HWND_BROADCAST, WM_APPCOMMAND, 0, ByVal (APPCOMMAND_VOLUME_MUTE * &H10000)
End Sub
```
另外,需要注意的是,此代码只适用于 Windows 操作系统。
阅读全文