office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Access VBA 使用API 關閉系統聲音和打開系統聲音的 方法

2017-09-08 09:30:00
zstmtony
原創
1107

Access VBA 使用API 關閉系統聲音和打開系統聲音的 方法

即讓整個系統靜音及取消靜音的代碼如下



------VBA 實現 源碼--------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hwnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const BM_GETCHECK = &HF0      ' 取得復選框狀態
Private Const BM_SETCHECK = &HF1      '設置復選框狀態
' Private Const BST_UNCHECKED = &00      設置復選框為未選中狀態
' Private Const BST_CHECKED = &01           設置復選框為選中狀態
Private Sub Command1_Click()
     Dim hwnd0 As Long      ' 用于記錄“音量控制”程序的句柄
     Shell "sndvol32.exe"        ' 啟動“音量控制”程序
     hwnd0 = FindWindow(vbNullString, "主音量")
     Dim hwnd1 As Long     ' 用于記錄“全部靜音”復選框句柄
     hwnd1 = FindWindowEx(hwnd0, 0&, "Button", "全部靜音(&M)")   ' 復選框的類名是"Button"
     Dim State As Long       ' 用于記錄復選框狀態,如果復選框處于未選中狀態,則返回0,選中狀態返回1
     State = SendMessage(hwnd1, BM_GETCHECK, ByVal CLng(0), ByVal CLng(0))
     SendMessage hwnd1, BM_SETCHECK, 1, 0 '使系統靜音
     SendMessage hwnd1, BM_SETCHECK, 0, 0 '使系統發音
End Sub
分享
北京十一选五基本走势