下列代码在windows10 64位 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 16:02:24 浏览: 243
这段代码可能是因为在64位的操作系统中,VB6编译的程序无法直接使用32位的API函数。可以尝试将Declare语句中的Long类型改为Ptr类型,以适应64位系统:
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Const HWND_BROADCAST As LongPtr = &HFFFF&
Const WM_APPCOMMAND As Long = &H319
Const APPCOMMAND_VOLUME_UP As Long = &HA
Const APPCOMMAND_VOLUME_DOWN As Long = &H9
Const APPCOMMAND_VOLUME_MUTE As Long = &H8
Public Sub SetSystemVolume(ByVal level As Integer)
Dim command As LongPtr
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
请注意,上述代码只能在64位系统上运行,如果是32位系统,需要将Declare语句改回Long类型。
阅读全文