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

📄 form1.cs

📁 手机短信平台的标准代码,包括完整dll,开发简单,调用方便
💻 CS
📖 第 1 页 / 共 2 页
字号:
            this.Sms_Start_Button.TabIndex = 1;
            this.Sms_Start_Button.Text = "启动";
            this.Sms_Start_Button.Click += new System.EventHandler(this.button4_Click);
            // 
            // NewSms_Show
            // 
            this.NewSms_Show.BackColor = System.Drawing.SystemColors.Desktop;
            this.NewSms_Show.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.NewSms_Show.Location = new System.Drawing.Point(8, 24);
            this.NewSms_Show.Name = "NewSms_Show";
            this.NewSms_Show.Size = new System.Drawing.Size(264, 24);
            this.NewSms_Show.TabIndex = 0;
            this.NewSms_Show.Text = "自动接收短信功能处于关闭状态";
            this.NewSms_Show.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // groupBox4
            // 
            this.groupBox4.Controls.Add(this.Sms_Receive_Button);
            this.groupBox4.Controls.Add(this.ReceiveSms_Text);
            this.groupBox4.Location = new System.Drawing.Point(280, 112);
            this.groupBox4.Name = "groupBox4";
            this.groupBox4.Size = new System.Drawing.Size(280, 208);
            this.groupBox4.TabIndex = 7;
            this.groupBox4.TabStop = false;
            this.groupBox4.Text = "接收短信";
            // 
            // Sms_Receive_Button
            // 
            this.Sms_Receive_Button.Location = new System.Drawing.Point(88, 176);
            this.Sms_Receive_Button.Name = "Sms_Receive_Button";
            this.Sms_Receive_Button.Size = new System.Drawing.Size(76, 24);
            this.Sms_Receive_Button.TabIndex = 1;
            this.Sms_Receive_Button.Text = "接收";
            this.Sms_Receive_Button.Click += new System.EventHandler(this.Sms_Receive_Button_Click);
            // 
            // ReceiveSms_Text
            // 
            this.ReceiveSms_Text.Location = new System.Drawing.Point(8, 24);
            this.ReceiveSms_Text.Multiline = true;
            this.ReceiveSms_Text.Name = "ReceiveSms_Text";
            this.ReceiveSms_Text.Size = new System.Drawing.Size(264, 144);
            this.ReceiveSms_Text.TabIndex = 0;
            // 
            // groupBox5
            // 
            this.groupBox5.Controls.Add(this.Sms_Delete_Button);
            this.groupBox5.Controls.Add(this.DeleteSms_Index);
            this.groupBox5.Controls.Add(this.label9);
            this.groupBox5.Location = new System.Drawing.Point(280, 328);
            this.groupBox5.Name = "groupBox5";
            this.groupBox5.Size = new System.Drawing.Size(200, 48);
            this.groupBox5.TabIndex = 8;
            this.groupBox5.TabStop = false;
            this.groupBox5.Text = "删除短信";
            // 
            // Sms_Delete_Button
            // 
            this.Sms_Delete_Button.Location = new System.Drawing.Point(128, 16);
            this.Sms_Delete_Button.Name = "Sms_Delete_Button";
            this.Sms_Delete_Button.Size = new System.Drawing.Size(48, 24);
            this.Sms_Delete_Button.TabIndex = 2;
            this.Sms_Delete_Button.Text = "删除";
            this.Sms_Delete_Button.Click += new System.EventHandler(this.Sms_Delete_Button_Click);
            // 
            // DeleteSms_Index
            // 
            this.DeleteSms_Index.Location = new System.Drawing.Point(80, 16);
            this.DeleteSms_Index.Name = "DeleteSms_Index";
            this.DeleteSms_Index.Size = new System.Drawing.Size(40, 21);
            this.DeleteSms_Index.TabIndex = 1;
            // 
            // label9
            // 
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(8, 24);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(77, 12);
            this.label9.TabIndex = 0;
            this.label9.Text = "短信索引号:";
            this.label9.Click += new System.EventHandler(this.label9_Click);
            // 
            // Sms_Exit_Button
            // 
            this.Sms_Exit_Button.Location = new System.Drawing.Point(496, 336);
            this.Sms_Exit_Button.Name = "Sms_Exit_Button";
            this.Sms_Exit_Button.Size = new System.Drawing.Size(56, 32);
            this.Sms_Exit_Button.TabIndex = 9;
            this.Sms_Exit_Button.Text = "退出";
            this.Sms_Exit_Button.Click += new System.EventHandler(this.Sms_Exit_Button_Click);
            // 
            // NewSms_Timer
            // 
            this.NewSms_Timer.Interval = 1000;
            this.NewSms_Timer.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(576, 390);
            this.Controls.Add(this.Sms_Exit_Button);
            this.Controls.Add(this.groupBox5);
            this.Controls.Add(this.groupBox4);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.MobPort);
            this.Controls.Add(this.label1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "调用短信收发二次开发接口例程源码(C#版)";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.groupBox3.ResumeLayout(false);
            this.groupBox4.ResumeLayout(false);
            this.groupBox4.PerformLayout();
            this.groupBox5.ResumeLayout(false);
            this.groupBox5.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		/// 
		[STAThread]

		[DllImport("sms.dll", EntryPoint="Sms_Connection")] 
      public static extern uint Sms_Connection(string CopyRight,uint Com_Port,uint Com_BaudRate ,out string Mobile_Type,out string CopyRightToCOM); 

		[DllImport("sms.dll", EntryPoint="Sms_Disconnection")] 
      public static extern uint Sms_Disconnection(); 

		[DllImport("sms.dll", EntryPoint="Sms_Send")] 
      public static extern uint Sms_Send(string Sms_TelNum,string Sms_Text); 

		[DllImport("sms.dll", EntryPoint="Sms_Receive")] 
      public static extern uint Sms_Receive(string Sms_Type,out string Sms_Text); 

		[DllImport("sms.dll", EntryPoint="Sms_Delete")] 
      public static extern uint Sms_Delete(string Sms_Index); 

		[DllImport("sms.dll", EntryPoint="Sms_AutoFlag")] 
      public static extern uint Sms_AutoFlag(); 

		[DllImport("sms.dll", EntryPoint="Sms_NewFlag")] 
      public static extern uint Sms_NewFlag(); 

		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
		
		}

		private void button4_Click(object sender, System.EventArgs e)
		{
			if (Sms_AutoFlag()==1) 
			{
				NewSms_Show.Text = "未收到新短信";
				NewSms_Timer.Enabled = true;
		    }
            else
            {
				NewSms_Show.Text = "该短信猫不支持自动接收短信功能";
	         }

		}

		private void button5_Click(object sender, System.EventArgs e)
		{
			NewSms_Show.Text = "自动接收短信功能处于关闭状态";
            NewSms_Timer.Enabled = false;
		}

		private void label9_Click(object sender, System.EventArgs e)
		{
		
		}

		private void Sms_Connection_Button_Click(object sender, System.EventArgs e)
		{

           String TypeStr="";
		   String CopyRightToCOM="";
           //String CopyRightStr = "//上海迅赛信息技术有限公司,网址www.xunsai.com//";
           String CopyRightStr = "//testetsetfbhsdfkjs//";
			if( Sms_Connection(CopyRightStr,uint.Parse(MobPort.Text), 9600,out TypeStr,out CopyRightToCOM) == 1) ///5为串口号,0为红外接口,1,2,3,...为串口
			{
				State_Show.Text=TypeStr;
				Sms_Connection_Button.Enabled=false;
                Sms_Disconnection_Button.Enabled=true;

	      
			}
			else
			{
				State_Show.Text="连接失败!";
				Sms_Connection_Button.Enabled=true;
				Sms_Disconnection_Button.Enabled=false;
			}
			

		}

		private void Sms_Disconnection_Button_Click(object sender, System.EventArgs e)
		{
			Sms_Disconnection();
			Sms_Connection_Button.Enabled=true;
			Sms_Disconnection_Button.Enabled=false;
		}

		private void Sms_Send_Button_Click(object sender, System.EventArgs e)
		{
			if( Sms_Send(TelNum_Text.Text,SendSms_Text.Text) == 1)
			{
				MessageBox.Show ("发送成功!");
			}
			else
			{
				MessageBox.Show ("发送失败!");
			}
		}

		private void Sms_Receive_Button_Click(object sender, System.EventArgs e)
		{
			String ReceiveSmsStr="";
			if (Sms_Receive("4", out ReceiveSmsStr) == 1)
		   {
			ReceiveSms_Text.Text = ReceiveSmsStr;
		   }
			else
			{
				ReceiveSms_Text.Text = "读取短信失败";
			}
		}

		private void Sms_Delete_Button_Click(object sender, System.EventArgs e)
		{
			Sms_Delete (DeleteSms_Index.Text);
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			  if (Sms_NewFlag() == 1)
			  {
                 NewSms_Show.Text = "收到新短信,请查收!";
		       }
		}

		private void Sms_Exit_Button_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

		private void groupBox1_Enter(object sender, System.EventArgs e)
		{
		
		}
	}
}

⌨️ 快捷键说明

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