Form1.cs
上传用户:zjazhou
上传日期:2022-03-22
资源大小:137k
文件大小:5k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using Microsoft.WindowsMobile.PocketOutlook;
- using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
- using System.Reflection;
- namespace ConnectTest
- {
- public partial class Form1 : Form
- {
- // 蓝牙
- [DllImport("BthUtil.dll",SetLastError = true)]
- public static extern int BthSetMode(RadioMode dwMode);
- [DllImport("BthUtil.dll",SetLastError = true)]
- public static extern int BthGetMode(out RadioMode dwMode);
- public static RadioMode Mode
- {
- get
- {
- RadioMode val;
- int result = BthGetMode(out val);
- if (result != 0)
- {
- throw new System.ComponentModel.Win32Exception(result, "Error");
- }
- return val;
- }
- set
- {
- int result = BthSetMode(value);
- if (result != 0)
- {
- throw new System.ComponentModel.Win32Exception(result, "Error");
- }
- }
- }
- public enum RadioMode
- {
- PowerOff,
- Connectable,
- Discoverable,
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Microsoft.WindowsMobile.Telephony.Phone p = new Microsoft.WindowsMobile.Telephony.Phone();
- p.Talk("13810306806",false);
- }
- private void button4_Click(object sender, EventArgs e)
- {
- Mode = RadioMode.PowerOff;
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Mode = RadioMode.Connectable;
- }
- private void button3_Click(object sender, EventArgs e)
- {
- Mode = RadioMode.Discoverable;
- }
- private MessageInterceptor mi;
- private void Form1_Load(object sender, EventArgs e)
- {
- //setup the sms interceptor
- if (MessageInterceptor.IsApplicationLauncherEnabled("Chapter9"))
- {
- //load existing settings
- mi = new MessageInterceptor("Chapter9");
- }
- else
- {
- //setup rule and register with application id "Chapter9"
- mi = new MessageInterceptor(InterceptionAction.NotifyAndDelete);
- mi.MessageCondition = new MessageCondition(MessageProperty.Body, MessagePropertyComparisonType.StartsWith, "Chapter9");
- string appPath = Assembly.GetExecutingAssembly().GetName().CodeBase;
- mi.EnableApplicationLauncher("Chapter9", appPath);
- }
- mi.MessageReceived += new MessageInterceptorEventHandler(mi_MessageReceived);
- }
- //sms
- void mi_MessageReceived(object sender, MessageInterceptorEventArgs e)
- {
- MessageBox.Show(((SmsMessage)e.Message).Body, "SMS Received");
- }
- private void button5_Click(object sender, EventArgs e)
- {
- OutlookSession m_outlookSession = new OutlookSession();
- try
- {
- // 构造短信息对象
- SmsMessage msg = new SmsMessage(
- "14254448851",//手机号
- "hello");//短信内容
- // 使用OutlookSession中的SMS帐户进行发送
- m_outlookSession.SmsAccount.Send(msg);
- // 向用户提示发送成功的信息
- MessageBox.Show(
- "Your message has been sent.",
- "Send",
- MessageBoxButtons.OK,
- MessageBoxIcon.Asterisk,
- MessageBoxDefaultButton.Button1);
- // 清空两个文本框,以备填写下一条消息
- // this.textBox1.Text = String.Empty;
- //
- // this.textBox2.Text = String.Empty;
- }
- catch (Exception ex)
- {
- MessageBox.Show(
- String.Format("Error: {0}", ex.Message),
- "Send",
- MessageBoxButtons.OK,
- MessageBoxIcon.Hand,
- MessageBoxDefaultButton.Button1);
- }
- }
- private void button6_Click(object sender, EventArgs e)
- {
- string telephoneNum = "110";
- string text = "abc";
- System.Diagnostics.Process.Start("tmail.exe", "-transport "SMS" -to "" + telephoneNum + "" -body ""+text+""");
- }
- }
- }