You may have noticed that Skype seems to embed itself into Internet Explorer, Firefox and Chrome. It recognises contacts and phone numbers in the page and provides the ability to call them.
I believe people will expect this kind of functionality in conventional windows applications also. To assist with this I created a little class that will not only allow calls, but allows a check for the existence of a skype and give the ability to extract the calling applications icon.
Sample Project
The sample winforms project includes the CallTo class and a simple Winforms test form:
The form has a textbox and button. One load, the call button is enabled and give an image. The button makes the call.
Public Class Form1 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Class
Dim loCallTo As New CallTo
cmdCall.Image = loCallTo.Image
cmdCall.Enabled = loCallTo.Enabled
End Sub
Private Sub cmdCall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCall.Click
Dim loCallTo As New CallTo
loCallTo.DoCall(txtPhoneNumber.Text)
End Sub
Heres the source of CallTo.vb:
Imports Microsoft.Win32 ''' <summary> ''' <summary> Dim lsValue As String If lsValue.Contains(",") Then End Get loBitmap.Dispose() End Function ''' <summary> If Not Enabled Then Throw New ApplicationException("Callto is not enabled") End Sub End Class
Imports System.Runtime
Imports System.Runtime.InteropServices
''' This class allows for making callto calls
''' </summary>
Public Class CallTo
''' Gets the image.
''' </summary>
''' <value>The image.</value>
Public ReadOnly Property Image() As Image
Get
If Not Enabled Then Return Nothing
With Registry.ClassesRoot.OpenSubKey("callto\DefaultIcon")
lsValue = .GetValue("")
End With
Dim lsBits() As String = lsValue.Split(","c)
Dim lsFilename As String = lsBits(0).Trim(New Char() {""""c})
Dim liPosition As Integer = Val(lsBits(1))
Return moGetIconFromExeOrDll(lsFilename, liPosition)
Else
Return Nothing
End If
End Property
Private Declare Auto Function ExtractIcon Lib "shell32" ( _
ByVal hInstance As IntPtr, ByVal lpszExeFileName As String, _
ByVal nIconIndex As Integer) As IntPtr
Private Function moGetIconFromExeOrDll(ByVal filename As String, ByVal position As Integer) As Image
Dim hInstance As IntPtr = Marshal.GetHINSTANCE( _
System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0))
Dim hIcon As IntPtr = ExtractIcon(hInstance, filename, position)
Dim loBitmap As Bitmap = Bitmap.FromHicon(hIcon)
Dim loReturn As Image = loBitmap.GetThumbnailImage(16, 16, Nothing, Nothing)
Return loReturn
''' Gets a value indicating whether this CallTo is enabled.
''' </summar
''' <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
Public ReadOnly Property Enabled() As Boolean
Get
Try
Dim loReg As RegistryKey = Registry.ClassesRoot.OpenSubKey("callto", False)
loReg.Close()
Catch
Return False
End Try
Return True
End Get
End Property
''' <summary>
''' Does the call.
''' </summary>
''' <param name="destination">The destination.</param>
Public Sub DoCall(ByVal destination As String)
Process.Start("callto://" & destination)

