电话拔号程序

来源:互联网 发布:vb.net 批量注释 编辑:程序博客网 时间:2024/06/10 01:25

Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows 窗体设计器生成的代码 " Public Sub New() MyBase.New() '该调用是 Windows 窗体设计器所必需的。 InitializeComponent() '在 InitializeComponent() 调用之后添加任何初始化 End Sub '窗体重写 dispose 以清理组件列表。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Windows 窗体设计器所必需的 Private components As System.ComponentModel.IContainer '注意: 以下过程是 Windows 窗体设计器所必需的 '可以使用 Windows 窗体设计器修改此过程。 '不要使用代码编辑器修改它。 Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents ListBox1 As System.Windows.Forms.ListBox Friend WithEvents Icon1 As System.Windows.Forms.NotifyIcon Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.Label1 = New System.Windows.Forms.Label Me.TextBox1 = New System.Windows.Forms.TextBox Me.Button1 = New System.Windows.Forms.Button Me.Button2 = New System.Windows.Forms.Button Me.ListBox1 = New System.Windows.Forms.ListBox Me.Icon1 = New System.Windows.Forms.NotifyIcon(Me.components) Me.ContextMenu1 = New System.Windows.Forms.ContextMenu Me.MenuItem1 = New System.Windows.Forms.MenuItem Me.MenuItem2 = New System.Windows.Forms.MenuItem Me.SuspendLayout() ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(8, 8) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(160, 16) Me.Label1.TabIndex = 0 Me.Label1.Text = "请输入你要拨的电话号码:" ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(8, 24) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(272, 21) Me.TextBox1.TabIndex = 1 Me.TextBox1.Text = "" ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(24, 56) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 2 Me.Button1.Text = "拨号" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(192, 56) Me.Button2.Name = "Button2" Me.Button2.TabIndex = 3 Me.Button2.Text = "退出" ' 'ListBox1 ' Me.ListBox1.ItemHeight = 12 Me.ListBox1.Location = New System.Drawing.Point(8, 88) Me.ListBox1.Name = "ListBox1" Me.ListBox1.Size = New System.Drawing.Size(272, 76) Me.ListBox1.TabIndex = 4 ' 'Icon1 ' Me.Icon1.ContextMenu = Me.ContextMenu1 Me.Icon1.Icon = CType(resources.GetObject("Icon1.Icon"), System.Drawing.Icon) Me.Icon1.Text = "电话拨号" Me.Icon1.Visible = True ' 'ContextMenu1 ' Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2}) ' 'MenuItem1 ' Me.MenuItem1.Index = 0 Me.MenuItem1.Text = "退出" ' 'MenuItem2 ' Me.MenuItem2.Index = 1 Me.MenuItem2.Text = "还原" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) Me.ClientSize = New System.Drawing.Size(292, 174) Me.Controls.Add(Me.ListBox1) Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.Label1) Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) Me.Name = "Form1" Me.Text = "电话拨号" Me.ResumeLayout(False) End Sub #End Region Private Declare Function tapiRequestMakeCall Lib "tapi32.dll" (ByVal DestAddress As String, ByVal AppName As String, ByVal CalledParty As String, ByVal comment As String) As Integer Const TAPIERR_CONNECTED As Short = 0 Const TAPIERR_DROPPED As Short = -1 Const TAPIERR_NOREQUESTRECIPIENT As Short = -2 Const TAPIERR_REQUESTQUEUEFULL As Short = -3 Const TAPIERR_INVALDESTADDRESS As Short = -4 Const TAPIERR_DESTBUSY As Short = -11 Const TAPIERR_UNKNOWNREQUESTID As Short = -15 Const TAPIERR_REQUESTFAILED As Short = -16 Private Sub EnableDial() Button1.Enabled = Len(Trim(TextBox1.Text)) > 0 End Sub Sub tapiStatus(ByRef strres As Integer) Select Case strres Case TAPIERR_CONNECTED ListBox1.Items.Add("信息:拨号已连接!") Case TAPIERR_INVALDESTADDRESS ListBox1.Items.Add("错误:错误的目的地址!") Case TAPIERR_NOREQUESTRECIPIENT ListBox1.Items.Add("错误:没有电话接口程序运行!") Case TAPIERR_REQUESTFAILED ListBox1.Items.Add("错误:拨号请求由于未知原因失败!") Case TAPIERR_DESTBUSY ListBox1.Items.Add("错误:对方电话正忙!") Case TAPIERR_UNKNOWNREQUESTID ListBox1.Items.Add("错误:没有这个电话号码!") Case TAPIERR_DROPPED ListBox1.Items.Add("错误:对方已挂断!") End Select End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strPhoneNum As String Dim res As Integer If Trim(TextBox1.Text) = "" Then ListBox1.Items.Add("错误:没有输入电话号码!") Exit Sub Else strPhoneNum = TextBox1.Text End If res = tapiRequestMakeCall(strPhoneNum, "Tapi Sample", strPhoneNum, "") Call tapiStatus(res) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Close() End Sub Private Sub Form1_MinimumSizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MinimumSizeChanged Icon1.Visible = True End Sub Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click Close() End Sub Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click Me.Show() End Sub End Class

原创粉丝点击