⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmdemo.frm

📁 用vb编的sms源代码
💻 FRM
字号:
VERSION 5.00
Object = "{9859B105-423A-4DEB-BB77-EADF68601321}#1.3#0"; "TransoftSMSControl30.ocx"
Begin VB.Form frmDemo 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "短信控件使用示例(vb6.0)"
   ClientHeight    =   6810
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7530
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   9
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6810
   ScaleWidth      =   7530
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdGetReport 
      Caption         =   "读取sim卡中状态报告"
      Height          =   375
      Left            =   4050
      TabIndex        =   24
      Top             =   6360
      Width           =   1965
   End
   Begin VB.CommandButton cmdGetStandSMS 
      Caption         =   "读取sim卡中的短信"
      Height          =   375
      Left            =   2130
      TabIndex        =   23
      Top             =   6360
      Width           =   1845
   End
   Begin VB.Frame Frame4 
      Caption         =   "提示信息"
      Height          =   2895
      Left            =   30
      TabIndex        =   21
      Top             =   3390
      Width           =   7365
      Begin VB.TextBox txtInfo 
         Height          =   2565
         Left            =   90
         MultiLine       =   -1  'True
         TabIndex        =   22
         Top             =   240
         Width           =   7125
      End
   End
   Begin VB.Timer TimerSend 
      Enabled         =   0   'False
      Interval        =   100
      Left            =   1320
      Top             =   6390
   End
   Begin TransoftSMSControl30.SMS SMS 
      Height          =   495
      Left            =   420
      Top             =   6360
      Width           =   495
      _ExtentX        =   873
      _ExtentY        =   873
   End
   Begin VB.CommandButton cmdClose 
      Caption         =   "关闭(&C)"
      Height          =   345
      Left            =   6390
      TabIndex        =   14
      Top             =   6390
      Width           =   1065
   End
   Begin VB.Frame Frame2 
      Caption         =   "发短信"
      Height          =   2265
      Left            =   30
      TabIndex        =   9
      Top             =   1080
      Width           =   7335
      Begin VB.ListBox lstMobileNo 
         Height          =   1140
         Left            =   270
         TabIndex        =   20
         Top             =   600
         Width           =   3285
      End
      Begin VB.TextBox txtMobileNo 
         Height          =   270
         Left            =   870
         TabIndex        =   19
         Top             =   270
         Width           =   2685
      End
      Begin VB.CommandButton cmdSend 
         Caption         =   "开始发送(&S)"
         Height          =   345
         Left            =   5970
         TabIndex        =   16
         Top             =   1800
         Width           =   1245
      End
      Begin VB.CheckBox chkReport 
         Caption         =   "状态报告"
         Height          =   225
         Left            =   4770
         TabIndex        =   12
         Top             =   1830
         Width           =   1065
      End
      Begin VB.CheckBox chkChinese 
         Caption         =   "中文短信"
         Height          =   285
         Left            =   3720
         TabIndex        =   11
         Top             =   1800
         Value           =   1  'Checked
         Width           =   1095
      End
      Begin VB.TextBox txtmsg 
         Height          =   1125
         Left            =   3720
         MultiLine       =   -1  'True
         TabIndex        =   10
         Top             =   600
         Width           =   3495
      End
      Begin VB.Label Label2 
         Caption         =   "短信内容"
         Height          =   195
         Left            =   3780
         TabIndex        =   15
         Top             =   330
         Width           =   855
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         Caption         =   "手机号码"
         Height          =   180
         Left            =   120
         TabIndex        =   13
         Top             =   300
         Width           =   720
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "连接设备"
      Height          =   915
      Left            =   30
      TabIndex        =   0
      Top             =   120
      Width           =   7335
      Begin VB.ComboBox cboRate 
         Height          =   300
         ItemData        =   "frmDemo.frx":0000
         Left            =   3960
         List            =   "frmDemo.frx":001C
         TabIndex        =   17
         Text            =   "9600,n,8,1"
         Top             =   210
         Width           =   2235
      End
      Begin VB.CommandButton cmdDisConnect 
         Caption         =   "断开(&D)"
         Height          =   285
         Left            =   6270
         TabIndex        =   8
         Top             =   510
         Width           =   975
      End
      Begin VB.CommandButton cmdConnect 
         Caption         =   "连接(&C)"
         Height          =   285
         Left            =   6270
         TabIndex        =   7
         Top             =   180
         Width           =   975
      End
      Begin VB.ComboBox cboMobileType 
         Height          =   300
         ItemData        =   "frmDemo.frx":0087
         Left            =   1260
         List            =   "frmDemo.frx":0097
         Style           =   2  'Dropdown List
         TabIndex        =   3
         Top             =   210
         Width           =   1665
      End
      Begin VB.ComboBox cboSMSPort 
         Height          =   300
         ItemData        =   "frmDemo.frx":00C9
         Left            =   3990
         List            =   "frmDemo.frx":00DC
         Style           =   2  'Dropdown List
         TabIndex        =   2
         Top             =   555
         Width           =   2145
      End
      Begin VB.TextBox txtCenterNo 
         Alignment       =   1  'Right Justify
         Height          =   270
         Left            =   1260
         TabIndex        =   1
         Text            =   "8613800100500"
         Top             =   555
         Width           =   1665
      End
      Begin VB.Label Label8 
         AutoSize        =   -1  'True
         Caption         =   "速率选择:"
         Height          =   180
         Left            =   3090
         TabIndex        =   18
         Top             =   300
         Width           =   810
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         Caption         =   "设备类型:"
         Height          =   180
         Left            =   450
         TabIndex        =   6
         Top             =   285
         Width           =   810
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         Caption         =   "短信中心号码:"
         Height          =   180
         Left            =   90
         TabIndex        =   5
         Top             =   615
         Width           =   1170
      End
      Begin VB.Label Label5 
         AutoSize        =   -1  'True
         Caption         =   "串口选择:"
         Height          =   180
         Left            =   3090
         TabIndex        =   4
         Top             =   630
         Width           =   810
      End
   End
End
Attribute VB_Name = "frmDemo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'//////////////////////////////////////////////////////
'
'
'本程序展示了短信控件的核心功能,希望能为您使用控件提供帮助
'
'
'
'//////////////////////////////////////////////////////



Private Sub cmdClose_Click()
    Unload Me
End Sub

Private Sub cmdConnect_Click()
    
    Select Case cboMobileType.Text      '读手机类型
        Case "标准手机"
            SMS.MobileType = 0
        Case "Wavecom模块"
            SMS.MobileType = 1
        Case "Nokia手机"
            SMS.MobileType = 2
        Case "西门子手机"
            SMS.MobileType = 3
        Case Else
    End Select
    
    
    '设置串口号
    If cboSMSPort.Text <> "" Then SMS.CommPort = Right(cboSMSPort.Text, 1)
    
    '设置中心号码
    SMS.CenterNo = txtCenterNo.Text
    
    '设置波特率
    SMS.Settings = cboRate.Text
    
    '设置振玲次数为4
    SMS.RingCount = 4
    
    '打开与手机的通讯
    If SMS.CommOpen = 0 Then
        MsgBox "连接成功!"
    Else
        MsgBox "连接失败!"
    End If

End Sub

Private Sub cmdDisConnect_Click()
    '关闭与手机的连接
    SMS.CommClose
    MsgBox "断开成功!"
End Sub


Private Sub cmdGetReport_Click()
    Dim strSMSIndex As String
    Dim intMsgNo As Integer
    Dim i As String
    
    On Error GoTo ErrHandle
    
    strSMSIndex = SMS.GetAllReportIndexFromSim
    
    
    If strSMSIndex <> "" Then
        Do While InStr(strSMSIndex, ",") > 0
            intMsgNo = Val(Mid(strSMSIndex, 1, InStr(strSMSIndex, ",") - 1))
            strSMSIndex = Mid(strSMSIndex, InStr(strSMSIndex, ",") + 1)
            '读取短信
            SMS.ReadReport (intMsgNo)
            
            '删除短信
            SMS.DeleteMsg (intMsgNo)
            
            MsgBox "从SIM卡中读取报告:" & "手机号码 " & SMS.LastReportReceiver & ",原发送时间:" & SMS.LastReportOriginSendTime & ",实际到达时间:" & SMS.LastReportArrivedTime & ",状态:" & SMS.LastReportStatus
        Loop
        
        '处理最后的短信
        intMsgNo = Val(strSMSIndex)
        '读取短信
        SMS.ReadReport (intMsgNo)
        
        '删除短信
        SMS.DeleteMsg (intMsgNo)
        
        MsgBox "从SIM卡中读取报告:" & "手机号码 " & SMS.LastReportReceiver & ",原发送时间:" & SMS.LastReportOriginSendTime & ",实际到达时间:" & SMS.LastReportArrivedTime & ",状态:" & SMS.LastReportStatus
        
    End If
    Exit Sub
ErrHandle:
    MsgBox "从SIM卡中读取信息失败"

End Sub

Private Sub cmdGetStandSMS_Click()
    Dim strSMSIndex As String
    Dim intMsgNo As Integer
    Dim i As String
    
    On Error GoTo ErrHandle
    
    strSMSIndex = SMS.GetAllSMSIndexFromSim
    
    
    
    If strSMSIndex <> "" Then
        Do While InStr(strSMSIndex, ",") > 0
            intMsgNo = Val(Mid(strSMSIndex, 1, InStr(strSMSIndex, ",") - 1))
            strSMSIndex = Mid(strSMSIndex, InStr(strSMSIndex, ",") + 1)
            '读取短信
            SMS.ReadMsg (intMsgNo)
            
            '删除短信
            SMS.DeleteMsg (intMsgNo)
            
            MsgBox "从SIM卡中读取信息:" & "手机号码 " & SMS.LastReadSender & ",内容:" & SMS.LastReadMsg
        Loop
        
        '处理最后的短信
        intMsgNo = Val(strSMSIndex)
        '读取短信
        SMS.ReadMsg (intMsgNo)
        
        '删除短信
        SMS.DeleteMsg (intMsgNo)
        
        MsgBox "从SIM卡中读取信息:" & "手机号码 " & SMS.LastReadSender & ",内容:" & SMS.LastReadMsg
        
    End If
    Exit Sub
ErrHandle:
    MsgBox "从SIM卡中读取信息失败"
    
    
End Sub

Private Sub cmdSend_Click()
    If lstMobileNo.ListCount < 1 Then
        MsgBox "请输入手机号码,并回车!", vbInformation, "提示"
    Else
        TimerSend.Enabled = True
    End If
End Sub
Private Sub Form_Load()
    cboMobileType.Text = "Wavecom模块"
    cboSMSPort.Text = "COM1"
End Sub

Private Sub SMS_Error(ByVal Number As Integer, ByVal Description As String)
    txtInfo.Text = txtInfo.Text & "[" & Now & "]" & "发送给" & lstMobileNo.Text & "失败!" & vbCrLf
    If lstMobileNo.ListCount > 0 Then
        lstMobileNo.RemoveItem 0
    End If
End Sub

Private Sub SMS_InComingCall(ByVal InComingCallNo As String, ByVal InComingCallTime As Date)
   txtInfo.Text = txtInfo.Text & InComingCallTime & "呼入电话:" & InComingCallNo & vbCrLf
End Sub

Private Sub SMS_MsgReceived(ByVal MsgSender As String, ByVal Msg As String, ByVal ArrivedTime As Date)
    txtInfo.Text = txtInfo.Text & "[" & ArrivedTime & "]接收短信" & MsgSender & ":" & Msg & vbCrLf
End Sub

Private Sub SMS_ReportReceived(ByVal MsgReference As Integer, ByVal Receiver As String, ByVal OriginSendTime As Date, ByVal ArrivedTime As Date, ByVal Status As Integer)
    txtInfo.Text = txtInfo.Text & "[" & Now & "]接受状态报告从" & Receiver & vbCrLf
End Sub

Private Sub SMS_SendComplete(ByVal intMsgReference As Integer)
    txtInfo.Text = txtInfo.Text & "[" & Now & "]" & "发送给" & lstMobileNo.Text & "成功!" & vbCrLf
    If lstMobileNo.ListCount > 0 Then
        lstMobileNo.RemoveItem 0
    End If
    
End Sub

Private Sub TimerSend_Timer()
    Dim i As Integer

'  这里是发送短信的核心代码,
' 注:定时触发一次,一定是只发送一条短信
'    发送之前判断控件状态是否忙
'
    If lstMobileNo.ListCount > 0 Then
        '下面的判断很重要
        If SMS.IsBusy = False Then
            Call SMS.SendMsg(lstMobileNo.List(0), txtmsg.Text, IIf((chkChinese.Value = 1), True, False), IIf((chkReport.Value = 1), True, False))
        End If
    End If
End Sub

Private Sub txtMobileNo_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        lstMobileNo.AddItem txtMobileNo.Text
        txtMobileNo.Text = ""
    End If
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -