WinCE5发短信打电话的代码

在winCE5.0里,已经提供了发短信和打电话的接口封装,直接调用就可以了,主要是Microsoft.WindowsMobile.PocketOutlook和Microsoft.WindowsMobile.Telephony可以实现大部分对手机计划任务,联系人以及电话呼出的功能都包涵了,下面就举个简单的列子说明一下:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Forms;                            //添加引用Microsoft.WindowsMobile.Forms.dll
using Microsoft.WindowsMobile.PocketOutlook;                    //添加引用Microsoft.WindowsMobile.PocketOutlook.dll
using Microsoft.WindowsMobile.Telephony;                        //添加引用Microsoft.WindowsMobile.Telephony.dll

namespace SMSPhone
{
    public partial class MainFrm : Form
    {
        private SmsMessage sms = new SmsMessage();              //Microsoft.WindowsMobile.PocketOutlook名字空间里的短信类,
        private Phone phone = new Phone();                      //Microsoft.WindowsMobile.Telephony名字空间里的电话类
        private ChooseContactDialog dialog = new ChooseContactDialog();         //Microsoft.WindowsMobile.Forms名字空间里联系人类
        public MainFrm()
        {
            InitializeComponent();
        }

        private void AddLinkman_menuItem_Click(object sender, EventArgs e)
        {
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                PhoneNumber_textBox.Text = dialog.SelectedContact.MobileTelephoneNumber;                //将联系的移动号码符给PhoneNumber文件框
            }
        }

        private void SMS_menuItem_Click(object sender, EventArgs e)
        {
            sms.Body = Message_textBox.Text;                        //添加短信正文
            sms.To.Add(new Recipient(PhoneNumber_textBox.Text));                //指定要发送的号码
            sms.RequestDeliveryReport = false;                      //发送成功以后不发送送达通知
            try
            {
                sms.Send();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "错误", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                return;
            }
            MessageBox.Show("短信发送成功", "成功", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
        }

        private void Phone_menuItem_Click(object sender, EventArgs e)
        {
            try
            {
                phone.Talk(PhoneNumber_textBox.Text);           //拨打指定电话
            }
            catch(Exception err)
            {
                MessageBox.Show(err.Message, "错误", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                return;
            }
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值