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

📄 form1.frm

📁 用vb写的GSM短信示例程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Saro VB SMS Demo V3.3"
   ClientHeight    =   6855
   ClientLeft      =   540
   ClientTop       =   405
   ClientWidth     =   11415
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   6855
   ScaleWidth      =   11415
   StartUpPosition =   3  '窗口缺省
   Begin VB.Frame Frame4 
      Caption         =   "发送区"
      Height          =   2610
      Left            =   5295
      TabIndex        =   12
      Top             =   4140
      Width           =   6015
      Begin VB.Timer Timer1 
         Interval        =   300
         Left            =   5400
         Top             =   1500
      End
      Begin VB.CommandButton Command_send 
         Caption         =   "发送"
         Height          =   360
         Left            =   4890
         TabIndex        =   17
         Top             =   2160
         Width           =   855
      End
      Begin VB.TextBox Text_phone 
         Height          =   300
         Left            =   1275
         TabIndex        =   16
         Text            =   "13799273095"
         Top             =   2175
         Width           =   1455
      End
      Begin VB.TextBox Text_send 
         Height          =   1815
         Left            =   75
         MaxLength       =   140
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   14
         Text            =   "Form1.frx":1CCA
         Top             =   180
         Width           =   5850
      End
      Begin VB.Label Label4 
         Caption         =   "对方号码:"
         Height          =   225
         Left            =   210
         TabIndex        =   15
         Top             =   2205
         Width           =   930
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "接收区"
      Height          =   3000
      Left            =   5310
      TabIndex        =   11
      Top             =   1035
      Width           =   6000
      Begin VB.TextBox Text_rec 
         Height          =   2730
         Left            =   75
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   13
         Top             =   165
         Width           =   5850
      End
   End
   Begin VB.CommandButton Command_stop 
      Caption         =   "停止"
      Height          =   375
      Left            =   9300
      TabIndex        =   3
      Top             =   360
      Width           =   870
   End
   Begin VB.Frame Frame2 
      Caption         =   "状态显示区"
      Height          =   5850
      Left            =   75
      TabIndex        =   2
      Top             =   930
      Width           =   5115
      Begin VB.TextBox Text_sd 
         Height          =   5535
         Left            =   75
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   10
         Top             =   225
         Width           =   4935
      End
   End
   Begin VB.CommandButton Command_start 
      Caption         =   "开始"
      Height          =   375
      Left            =   8250
      TabIndex        =   0
      Top             =   360
      Width           =   930
   End
   Begin VB.Frame Frame1 
      Caption         =   "设置区"
      Height          =   735
      Left            =   75
      TabIndex        =   1
      Top             =   135
      Width           =   11220
      Begin VB.CommandButton Command1 
         Caption         =   "清空"
         Height          =   375
         Left            =   10215
         TabIndex        =   18
         Top             =   225
         Width           =   870
      End
      Begin VB.TextBox Text_csca 
         Height          =   300
         Left            =   5805
         TabIndex        =   9
         Top             =   240
         Width           =   2160
      End
      Begin VB.ComboBox Combo_baud 
         Height          =   300
         ItemData        =   "Form1.frx":1CDE
         Left            =   3120
         List            =   "Form1.frx":1CEE
         TabIndex        =   7
         Text            =   "57600"
         Top             =   270
         Width           =   1035
      End
      Begin VB.ComboBox Combo_com 
         Height          =   300
         ItemData        =   "Form1.frx":1D0E
         Left            =   735
         List            =   "Form1.frx":1D2D
         TabIndex        =   5
         Text            =   "COM1"
         Top             =   270
         Width           =   1005
      End
      Begin VB.Label Label3 
         Caption         =   "短信中心号码:"
         Height          =   285
         Left            =   4500
         TabIndex        =   8
         Top             =   300
         Width           =   1185
      End
      Begin VB.Label Label2 
         Caption         =   "波特率:"
         Height          =   270
         Left            =   2370
         TabIndex        =   6
         Top             =   315
         Width           =   795
      End
      Begin VB.Label Label1 
         Caption         =   "串口:"
         Height          =   255
         Left            =   150
         TabIndex        =   4
         Top             =   315
         Width           =   555
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit



Private Sub Command_send_Click()
   If Me.Text_send.Text <> "" Then
      Dim index As Long
      'Dim Msg() As Byte
     ' Dim phone() As Byte
     ' Msg = StrConv(Me.Text_send.Text, vbFromUnicode)
     ' phone = StrConv(Me.Text_phone.Text, vbFromUnicode)
      
      index = SMSSendMessage(Me.Text_send.Text, Me.Text_phone.Text)
   End If
End Sub

Private Sub Command_start_Click()
   Dim com As Integer
   Dim baud As Long
   Dim suc As Long
   Dim err As String
   com = Int(Mid(Me.Combo_com.Text, 4))
   baud = CLng(Me.Combo_baud.Text)

   If Me.Text_csca.Text = "" Then
      suc = SMSDef.SMSStartService(com, baud, 2, 8, 0, 0, "card") '如果想用SIM卡内的短信中心号码,请把最后一个参数设为"card"(小写)
   Else
      suc = SMSDef.SMSStartService(com, baud, 2, 8, 0, 0, Me.Text_csca.Text)
   End If

  
   If suc = 1 Then
      Me.Command_start.Enabled = False
      Me.Command_stop.Enabled = True
      Me.Command_send.Enabled = True
      Me.Text_sd.SelText = "启动成功" & vbCrLf
      Me.Timer1.Enabled = True
   Else
      Me.Command_start.Enabled = True
      Me.Command_stop.Enabled = False
      Me.Command_send.Enabled = False
      Me.Text_sd.SelText = "启动失败" & vbCrLf
      err = "这里填一些字符,以免SMSGetLastError内操作此字符串时溢出,在SMSGetLastError该字符串定义为1024byte"
      
      
      SMSGetLastError err
      
      Me.Text_sd.SelText = err
      Me.Text_sd.SelText = vbCrLf
   End If
  
      
   
End Sub

Private Sub Command_stop_Click()
    Me.Timer1.Enabled = False
    SMSStopSerice
    Me.Command_start.Enabled = True
    Me.Command_stop.Enabled = False
    Me.Command_send.Enabled = False
    Me.Text_sd.SelText = "停止成功" & vbCrLf
   
End Sub



Private Sub Command1_Click()
   Me.Text_sd.Text = ""
   Me.Text_rec.Text = ""
End Sub

Private Sub Form_Unload(Cancel As Integer)
   SMSStopSerice  '关闭窗口前先关闭服务,否则在VB中有时会报错。
End Sub

Private Sub Timer1_Timer()
    Dim smg As SMSMessageStruct
    Dim srs As SMSReportStruct
    If SMSReport(srs) <> 0 Then
        If srs.Success = 1 Then
            Me.Text_sd.SelText = "发往" & StrConv(srs.PhoneNo, vbUnicode)
            Me.Text_sd.SelText = "的短信发送成功,内容:" & StrConv(srs.Msg, vbUnicode)
            Me.Text_sd.SelText = vbCrLf
            
            
        Else
            Me.Text_sd.SelText = "发往" & StrConv(srs.PhoneNo, vbUnicode)
            Me.Text_sd.SelText = "的短信发送失败,内容:" & StrConv(srs.Msg, vbUnicode)
            Me.Text_sd.SelText = vbCrLf
           
        End If
    End If
    
    If SMSGetNextMessage(smg) = 1 Then
        Me.Text_rec.SelText = "收到短信:<" & StrConv(smg.ReceTime, vbUnicode)
        Me.Text_rec.SelText = "> <" & StrConv(smg.PhoneNo, vbUnicode)
        Me.Text_rec.SelText = ">:" & vbCrLf & "  " & StrConv(smg.Msg, vbUnicode)
        Me.Text_rec.SelText = vbCrLf
    
    End If

    
End Sub

⌨️ 快捷键说明

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