'Author comments: I often get asked the question "How can
'I dial a phone number from VB?". Well, you can add
'the MSCOMM32.OCX control to a form but that isn't necessary
'if you just want to dial a phone number.
Private Declare Function tapiRequestMakeCall Lib "TAPI32.DLL" (ByVal Dest As String, ByVal AppName As String, ByVal CalledParty As String, ByVal Comment As String) As Long
Private Sub PhoneCall(sNumber As String, sName As String)
Dim lRetVal As Long
lRetVal = tapiRequestMakeCall(Trim$(sNumber), App.Title, Trim$(sName), "")
If lRetVal <> 0 Then
'Couldn't make the call.
'Take appropriate action
End If
End Sub
Private Sub Form_Load()
PhoneCall "123456", "TheName"
End Sub
利用 API 可以直接拨号
声明:
Private Declare Function tapiRequestMakeCall Lib "TAPI32.DLL" (ByVal DestAddr$, ByVal AppName As String, ByVal CalledParty As String, ByVal Comment As String) As Long
例子:
Public Sub CallPhone(Number As String, Name As String)
Dim lRes As Long
If (Trim(Number) = "") Then
Exit Sub
End If
If (MsgBox("About to call " & Trim(Name) & " at phone number " & Trim(Number) & vbCrLf & "Do it?", vbYesNo, App.Title) = vbYes) Then
lRes = tapiRequestMakeCall(Trim(Number), App.Title, Trim(Name), "")
Debug.Print Now; " CallPhone -> tapiRequestMakeCall Result code = "; lRes
End If
End Sub