VB 如何用程式來設定 "靜音"

VB 如何用程式來設定 "靜音"

VB 如何用程式來設定 "靜音"

<< VB6 >>

' API 宣告

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 SendMessageLong& Lib "user32" Alias "SendMessageA" _

(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _

(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub Command1_Click()

Quiet ' 方法 1

' 或

Silence ' 方法 2

' 擇其一即可

End Sub

Private Sub Quiet()

Dim lngWnd As Long

Shell "SndVol32 /T"

Do Until lngWnd

lngWnd = FindWindow("Tray Volume", vbNullString)

DoEvents

Loop

lngWnd = FindWindowEx(lngWnd, 0&, "Button", vbNullString)

SendMessageLong lngWnd, 256, 32, 0&

SendMessageLong lngWnd, 257, 32, 0&

On Error Resume Next

SetFocus

End Sub

Private Sub Silence()

Dim lngVolHnd As Long, lngHnd As Long

Shell "SndVol32", vbHide

Do Until lngVolHnd

lngVolHnd = FindWindow("Volume Control", vbNullString)

DoEvents

Loop

lngHnd = FindWindowEx(lngVolHnd, 0&, "Button", vbNullString)

lngHnd = FindWindowEx(lngVolHnd, lngHnd, "Button", vbNullString)

SendMessageLong lngHnd, 256, 32, 0&

SendMessageLong lngHnd, 257, 32, 0&

PostMessage lngVolHnd, 16, 0&, 0&

End Sub

' ================================================================

<< VB.Net >>

請將 VB6 的 Code 轉成 VB.Net 即可

PS : 前陣子回覆網友的問題 ( 蠻怪的做法 ) , 不過還是Po 出給網友參考看看 !