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

📄 form1.cs

📁 短信源程序代码,请大家试用短信源程序代码,请大家试用短信源程序代码,请大家试用
💻 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.AddRange(new System.Windows.Forms.Control[] {
																					this.Sms_Receive_Button,
																					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;
			this.ReceiveSms_Text.Text = "";
			// 
			// groupBox5
			// 
			this.groupBox5.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.Sms_Delete_Button,
																					this.DeleteSms_Index,
																					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, 20);
			this.DeleteSms_Index.TabIndex = 1;
			this.DeleteSms_Index.Text = "";
			// 
			// 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(72, 13);
			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);
			// 
			// label3
			// 
			this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.Location = new System.Drawing.Point(8, 416);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(552, 24);
			this.label3.TabIndex = 10;
			this.label3.Text = "版权所有 北京诺亚软件有限公司";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label8
			// 
			this.label8.BackColor = System.Drawing.SystemColors.Info;
			this.label8.Location = new System.Drawing.Point(16, 440);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(544, 24);
			this.label8.TabIndex = 11;
			this.label8.Text = "公司网址:www.noahsoft.cn 咨询与售后服务热线:010-87416460";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 13);
			this.ClientSize = new System.Drawing.Size(576, 485);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.label8,
																		  this.label3,
																		  this.Sms_Exit_Button,
																		  this.groupBox5,
																		  this.groupBox4,
																		  this.groupBox3,
																		  this.label7,
																		  this.groupBox2,
																		  this.groupBox1,
																		  this.label2,
																		  this.MobPort,
																		  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.groupBox3.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.groupBox5.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

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


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

		[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="";

			if( Sms_Connection(uint.Parse(MobPort.Text), 9600,out TypeStr ) == 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();
		}
	}
}

⌨️ 快捷键说明

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