Introduction
This is a sample for using Pocket PC to send SMS.
Background
I tried to solve a problem that uses Pocket PC to send SMS in my projects. I downloaded Microsoft SDK and found this sample. Now I hope that it can be useful for other programmers.
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)
{
contactToSelect = new Contact();
this.outlookSession.Contacts.Items.Add(contactToSelect);
ContactEditor contactDialog = new ContactEditor();
contactDialog.Edit(ref contactToSelect);
this.InitializeListBox();
}
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);
}
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; s.Send();
}
catch (NullReferenceException except)
{
MessageBox.Show(except.ToString());
}
}
private void CallWorkButton_Click(object sender, System.EventArgs e)
{
contactToSelect = (Contact)this.listBox1.SelectedItem;
Phone p = new Phone();
p.Talk(contactToSelect.BusinessTelephoneNumber);
}