修改下列代码:错误:类型不匹配:Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, lParam As Long) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExW" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameW" (ByVal hWnd As Long, ByVal lpClassName As Long, ByVal nMaxCount As Long) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextW" (ByVal hWnd As Long, ByVal lpWindowText As Long, ByVal nMaxCount As Long) As Long Private Const WM_APPCOMMAND As Long = &H319 Private Const APPCOMMAND_VOLUME_UP As Long = &HA Private Const APPCOMMAND_VOLUME_DOWN As Long = &H9 Private Const APPCOMMAND_VOLUME_MUTE As Long = &H8 Public Sub SetSystemVolume(ByVal level As Integer) Dim hWndTaskbar As Long Dim hWndVolumeCtrl As Long Dim hWndParent As Long Dim hWndChild As Long Dim className As String hWndTaskbar = FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString) If hWndTaskbar = 0 Then Exit Sub hWndVolumeCtrl = FindWindowEx(hWndTaskbar, 0, "TrayNotifyWnd", vbNullString) If hWndVolumeCtrl = 0 Then Exit Sub hWndParent = FindWindowEx(hWndVolumeCtrl, 0, "SysPager", vbNullString) If hWndParent = 0 Then Exit Sub hWndChild = FindWindowEx(hWndParent, 0, "ToolbarWindow32", vbNullString) If hWndChild = 0 Then Exit Sub ' get class name of the volume control className = Space(256) GetClassName hWndChild, StrPtr(className), Len(className) className = Left$(className, InStr(className, vbNullChar) - 1) ' find the volume control by window title hWndChild = FindWindowEx(hWndChild, 0, className, "Volume") If hWndChild = 0 Then Exit Sub SendMessage hWndChild, WM_APPCOMMAND, 0, APPCOMMAND_VOLUME_UP * &H10000 + level End Sub Public Sub MuteSystemVolume() Dim hWndTaskbar As Long Dim hWndVolumeCtrl As Long Dim hWndParent As Long Dim hWndChild As Long Dim className As String hWndTaskbar = FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString) If hWndTaskbar = 0 Then Exit Sub hWndVolumeCtrl = FindWindowEx(hWndTaskbar, 0, "TrayNotifyWnd", vbNullString) If hWndVolumeCtrl = 0 Then Exit Sub hWndParent = FindWindowEx(hWndVolumeCtrl, 0, "SysPager", vbNullString) If hWndParent = 0 Then Exit Sub hWndChild = FindWindowEx(hWndParent, 0, "ToolbarWindow32", vbNullString) If hWndChild = 0 Then Exit Sub ' get class name of the volume control className = Space(256) GetClassName hWndChild, StrPtr(className), Len(className) className = Left$(className, InStr(className, vbNullChar) - 1) ' find the volume control by window title hWndChild = FindWindowEx(hWndChild, 0, className, "Volume") If hWndChild = 0 Then Exit Sub SendMessage hWndChild, WM_APPCOMMAND, 0, APPCOMMAND_VOLUME_MUTE * &H10000 End Sub Private Sub Command1_Click() MuteSystemVolume End Sub
最新发布