65.9K
CodeProject 正在变化。 阅读更多。
Home

在 Pocket PC 上发送 SMS

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.86/5 (6投票s)

2007 年 5 月 22 日

CPOL
viewsIcon

43510

downloadIcon

779

使用C#发送消息的简单方法。

引言

这是一个使用Pocket PC发送短信的示例。

背景

我尝试解决在我的项目中利用Pocket PC发送短信的问题。我下载了Microsoft SDK并找到了这个示例。现在我希望它对其他程序员有用。

Using the Code

using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.Telephony;
private OutlookSession outlookSession;

public ContactSelector()
{
    this.outlookSession = new OutlookSession();          
}

        private void NewButton_Click(object sender, System.EventArgs e)
        {                   
            // Add contact to the contacts folder. 
            // Just do an update once the information has been entered.
            contactToSelect = new Contact();                        
            this.outlookSession.Contacts.Items.Add(contactToSelect);
            
            // Edit the newly created contact.
            ContactEditor contactDialog = new ContactEditor();
            contactDialog.Edit(ref contactToSelect);    
         
            this.InitializeListBox();
        }
        /// <summary>
        /// This event handler gets called when the "Edit" button is pressed.
        /// It sets contactToSelect as the contact selected on the ListBox.         
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">Event arguments.</param>
        private void EditButton_Click(object sender, System.EventArgs e)
        {            
            if (this.listBox1.SelectedItem != null)
            {
                contactToSelect = (Contact)this.listBox1.SelectedItem;
            } 
            
            ContactEditor contactDialog = new ContactEditor();
            contactDialog.Edit(ref contactToSelect);
        }
        /// <summary>
        /// This will send an SMS Message.
        /// </summary>
        /// <param name="sender">Sender of the message</param>
        /// <param name="e">Event arguments.</param>
        private void SendSmsButton_Click(object sender, System.EventArgs e)
        {
           try
           {
                contactToSelect = (Contact)this.listBox1.SelectedItem;
                if (outlookSession.SmsAccount == null)
                    throw new ArgumentException("The account is not initialized");
                MessageBox.Show("Transport:"+outlookSession.SmsAccount.Name);
                SmsMessage s = new SmsMessage(contactToSelect.MobileTelephoneNumber, 
                    this.smsText.Text);
                s.Body = this.smsText.Text; //Create some input.
                s.Send();
           }
           catch (NullReferenceException except)
           {
                MessageBox.Show(except.ToString());
           }
        }
        
        /// <summary>
        /// Call BusinessTelephoneNumber
        /// </summary>
        /// <param name="sender">Sender of event.</param>
        /// <param name="e">Event Arguments</param>
        private void CallWorkButton_Click(object sender, System.EventArgs e)
        {
           contactToSelect = (Contact)this.listBox1.SelectedItem;
            Phone p = new Phone();
            p.Talk(contactToSelect.BusinessTelephoneNumber);
            
        }
© . All rights reserved.