Retrieving SIM Card Information
The SIM card that you used for your Windows Mobile device can be used to store your contact's information. And sometimes you might need to programmatically retrieve them from the SIM card and perhaps back them up in a storage card.
To do so, you can use the classes provided in the
OpenNETCF.Phone.dll library. The following code segment prints out the name and telephone numbers of all the contacts stored in the SIM card using the Sim class:
Dim mySim As New OpenNETCF.Phone.Sim.Sim
For i As Integer = 0 To mySim.Phonebook.Count - 1
ListBox1.Items.Add(mySim.Phonebook(i).Text & "-" & _
mySim.Phonebook(i).Address)
Next
Figure 2 shows the contacts stored in the SIM card:
You can also find out the maximum storage capacity of your SIM card using the code below:
Dim str As String = String.Empty
str += "Max. Phonebook address length: " & _
mySim.MaximumPhonebookAddressLength & vbCrLf
str += "Max. Phonebook index: " & _
mySim.MaximumPhonebookIndex & vbCrLf
str += "Max. Phonebook text length: " & _
mySim.MaximumPhonebookTextLength & vbCrLf
str += "Min. Phonebook index: " & _
mySim.MinimumPhonebookIndex & vbCrLf
MsgBox(str)
Figure 3 shows the output for the SIM card.
 | |
| Figure 3. Output: The storage capacity of a SIM card. |
Retrieving Phone Logs
Every call that you make or receive is logged in your Windows Mobile device. But how do you get all this information out of the device? Well, you simply use the CallLog class, which is in the OpenNETCF.Phone.dll library, like this:
Dim CallLog As New OpenNETCF.Phone.CallLog
For i As Integer = 0 To CallLog.Count - 1
Dim CallInfo As String
If CallLog(i).Outgoing Then
CallInfo = "Outgoing: "
Else
CallInfo = "Incoming: "
End If
CallInfo &= CallLog(i).Name & "(" & CallLog(i).Number & ")"
ListBox1.Items.Add(CallInfo)
Next
Besides retrieving the name of the caller (the phone tries to match the number with the contacts stored in the phone; if it is not found it will then compare with the contacts stored in the SIM card) and its number, you can also find out about the start time (including the date as well), end time, roaming (whether the call is a roaming call), and call type (whether the call was missed, answered or outgoing).
Manipulating Images
The .NET Compact Framework does not provide much functionality for image manipulations, so if you need to perform simple image processing, you are stuck. Fortunately, the OpenNETCF.Drawing.dll library provides some image utilities that you can use.
For example, you have a PictureBox control containing an image:
PictureBox1.Image = New Bitmap( _
"\My Documents\My Pictures\Waterfall.jpg")
If you want to rotate the image 90 degrees clockwise, you can use the
Rotate() method in the
ImageUtils class, as follows:
Dim RotatedBitmap As Bitmap = _
OpenNETCF.Drawing.Imaging.ImageUtils.Rotate(PictureBox1.Image, 90)
PictureBox1.Image = RotatedBitmap
What about image scaling? For example, you want to scale the image down to a quarter of its original size, you can half its width and height, and then use the
CreateThumbnail() method to reduce the image:
Dim fs As New System.IO.FileStream( _
"\My Documents\My Pictures\Waterfall.jpg", IO.FileMode.Open)
Dim NewSize As Size = PictureBox1.Size
With NewSize
.Width /= 2
.Height /= 2
End With
Dim bi As OpenNETCF.Drawing.Imaging.IBitmapImage
bi = OpenNETCF.Drawing.Imaging.ImageUtils.CreateThumbnail( _
fs, NewSize)
PictureBox1.Image = _
OpenNETCF.Drawing.Imaging.ImageUtils.IBitmapImageToBitmap(bi)