Form1.cs
上传用户:zjazhou
上传日期:2022-03-22
资源大小:137k
文件大小:5k
源码类别:

Windows Mobile

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using Microsoft.WindowsMobile.PocketOutlook;
  10. using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
  11. using System.Reflection;
  12. namespace ConnectTest
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         // 蓝牙
  17.         [DllImport("BthUtil.dll",SetLastError = true)]
  18.         public static extern int BthSetMode(RadioMode dwMode);
  19.                 [DllImport("BthUtil.dll",SetLastError = true)]
  20.         public static extern int BthGetMode(out RadioMode dwMode);
  21.         public static RadioMode Mode
  22.         { 
  23.             get
  24.             {
  25.                 RadioMode val;
  26.                 int result = BthGetMode(out val);
  27.                 if (result != 0)
  28.                 {
  29.                     throw new System.ComponentModel.Win32Exception(result, "Error");
  30.                 }
  31.                 return val;
  32.             }
  33.             set
  34.             {
  35.                 int result = BthSetMode(value);
  36.                 if (result != 0)
  37.                 {
  38.                     throw new System.ComponentModel.Win32Exception(result, "Error");
  39.                 }
  40.             }
  41.         }
  42.         public enum RadioMode
  43.         {
  44.             PowerOff,
  45.             Connectable,
  46.             Discoverable,
  47.         }
  48.         public Form1()
  49.         {
  50.             InitializeComponent();
  51.         }
  52.         private void button1_Click(object sender, EventArgs e)
  53.         {
  54.             Microsoft.WindowsMobile.Telephony.Phone p = new Microsoft.WindowsMobile.Telephony.Phone();
  55.             p.Talk("13810306806",false);
  56.         }
  57.         private void button4_Click(object sender, EventArgs e)
  58.         {
  59.             Mode = RadioMode.PowerOff;
  60.         }
  61.         private void button2_Click(object sender, EventArgs e)
  62.         {
  63.             Mode = RadioMode.Connectable;
  64.         }
  65.         private void button3_Click(object sender, EventArgs e)
  66.         {
  67.             Mode = RadioMode.Discoverable;
  68.         }
  69.         private MessageInterceptor mi;
  70.         private void Form1_Load(object sender, EventArgs e)
  71.         {
  72.             //setup the sms interceptor
  73.             if (MessageInterceptor.IsApplicationLauncherEnabled("Chapter9"))
  74.             {
  75.                 //load existing settings
  76.                 mi = new MessageInterceptor("Chapter9");
  77.             }
  78.             else
  79.             {
  80.                 //setup rule and register with application id "Chapter9"
  81.                 mi = new MessageInterceptor(InterceptionAction.NotifyAndDelete);
  82.                 mi.MessageCondition = new MessageCondition(MessageProperty.Body, MessagePropertyComparisonType.StartsWith, "Chapter9");
  83.                 string appPath = Assembly.GetExecutingAssembly().GetName().CodeBase;
  84.                 mi.EnableApplicationLauncher("Chapter9", appPath);
  85.             }
  86.             mi.MessageReceived += new MessageInterceptorEventHandler(mi_MessageReceived);
  87.         }
  88.         //sms
  89.         void mi_MessageReceived(object sender, MessageInterceptorEventArgs e)
  90.         {
  91.             MessageBox.Show(((SmsMessage)e.Message).Body, "SMS Received");
  92.         }
  93.         private void button5_Click(object sender, EventArgs e)
  94.         {
  95.             OutlookSession m_outlookSession = new OutlookSession();
  96.             try
  97.             {
  98.                 // 构造短信息对象
  99.                 SmsMessage msg = new SmsMessage(
  100.                     "14254448851",//手机号
  101.                     "hello");//短信内容
  102.                 // 使用OutlookSession中的SMS帐户进行发送
  103.                 m_outlookSession.SmsAccount.Send(msg);
  104.                 // 向用户提示发送成功的信息
  105.                 MessageBox.Show(
  106.                     "Your message has been sent.",
  107.                     "Send",
  108.                     MessageBoxButtons.OK,
  109.                     MessageBoxIcon.Asterisk,
  110.                     MessageBoxDefaultButton.Button1);
  111.                 // 清空两个文本框,以备填写下一条消息
  112. //                 this.textBox1.Text = String.Empty;
  113. // 
  114. //                 this.textBox2.Text = String.Empty;
  115.             }
  116.             catch (Exception ex)
  117.             {
  118.                 MessageBox.Show(
  119.                     String.Format("Error: {0}", ex.Message),
  120.                     "Send",
  121.                     MessageBoxButtons.OK,
  122.                     MessageBoxIcon.Hand,
  123.                     MessageBoxDefaultButton.Button1);
  124.             }
  125.         }
  126.         private void button6_Click(object sender, EventArgs e)
  127.         {
  128.             string telephoneNum = "110";
  129.             string text = "abc";
  130.             System.Diagnostics.Process.Start("tmail.exe", "-transport "SMS" -to "" + telephoneNum + "" -body ""+text+""");
  131.         }
  132.     }
  133. }