Tablet Fax

 Download CD Content

In the final chapter of the book, we develop an application that allows us to send faxes. We also use factoids, which improve accuracy for specific types of pen-based input. To send the fax, we use the Faxcom.dll, which should be available on all Tablet PCs

  On the CD 

The source code for the projects are located on the CD-ROM in the PROJECTS folder. You can either type them in as you go or you can copy the projects from the CD-ROM to your hard drive for editing.

Beginning the Project

To begin the project, create a new Windows Forms application and add the controls shown in Table 31.1, using Figure 31.1 as a reference.

Table 31.1: Adding controls to the application

Type

Name

Text

TextBox

FaxTo

empty

TextBox

FaxNum

empty

TextBox

FaxSubject

empty

TextBox

FaxNote

empty

CheckBox

CoverPage

Cover Page

CheckBox

CheckBox1

Display as Ink

InkEdit

InkEdit1

InkEdit1

Figure 31.1: The GUI is finished.

We are now set to add a reference to Microsoft.Ink and Microsoft.Ink.15. You also need a reference to the Microsoft Fax Service Extended COM Type Library, which can be found on the COM tab.

The next step is to add the Imports for Microsoft.Ink:

Imports Microsoft.Ink

We use a Pen Input Panel, so we can create this and also handle disposing of it on the Form_Closing event:

Dim thePenInputPanel As New PenInputPanel() Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing thePenInputPanel.Dispose() End Sub

We now deal with the Pen Input Panel and using factoids in the TextBox controls, which includes phone numbers, and so on. Factoids greatly improve recognition (much like our custom grammar for SAPI) by providing the recognizer with a definition of the words, numbers, and punctuation that are expected. Factoids are available for items such as phone numbers and e-mail addresses.

We are able to assign the factoid and the Pen Input Panel in the respective TextBox_Enter events:

Private Sub FaxTo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) thePenInputPanel.AttachedEditControl = FaxTo thePenInputPanel.Factoid = Factoid.Default End Sub Private Sub FaxNum_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) thePenInputPanel.AttachedEditControl = FaxNum thePenInputPanel.Factoid = Factoid.Telephone End Sub Private Sub FaxSubject_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) thePenInputPanel.AttachedEditControl = FaxSubject thePenInputPanel.Factoid = Factoid.Default End Sub Private Sub FaxNote_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) thePenInputPanel.AttachedEditControl = FaxNote thePenInputPanel.Factoid = Factoid.Default End Sub

Let's now handle the changing of the InkEdit control to display the information as ink or as the recognized text. We use CheckBox1 for this. The other Sub procedure that deals with the way the InkEdit control works is the Form_Load event, which empties any text inside the control and sets its Width property to 100.

Here are the two procedures:

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged InkEdit1.SelectAll() If CheckBox1.Checked = True Then InkEdit1.SelInksDisplayMode = InkDisplayMode.Ink Else InkEdit1.SelInksDisplayMode = InkDisplayMode.Text End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load InkEdit1.Text = "" InkEdit1.DrawingAttributes.Width = 100 End Sub

The final Sub procedure is the longest one. It occurs when btnFax is clicked. It begins by creating a new fax document, fax server, sender, and job ID:

Dim objFaxDocument As New FAXCOMEXLib.FaxDocument() Dim objFaxServer As New FAXCOMEXLib.FaxServer() Dim objSender As FAXCOMEXLib.FaxSender Dim JobID As Object

The Sub procedure continues on with the following steps:

  1. Connect to the local fax server.
  2. Set the body of the fax document to the content of InkEdit1.
  3. Use the FaxSubject Text property to set the document name.
  4. Set the priority to high.
  5. Add the recipient name and fax number.
  6. Attach the fax to the fax receipt.
  7. Add a cover page if the CoverPage check box is selected.
  8. Set the Subject equal to the FaxSubject's Text property.
  9. Set the JobID.
  10. Display a message box with the ID.
  11. The entire set of steps have simple error handling and an error is displayed if anything happens.

Here is the code for the entire procedure:

Private Sub btnFax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim objFaxDocument As New FAXCOMEXLib.FaxDocument() Dim objFaxServer As New FAXCOMEXLib.FaxServer() Dim objSender As FAXCOMEXLib.FaxSender Dim JobID As Object On Error GoTo Error_Handler objFaxServer.Connect("") objFaxDocument.Body = InkEdit1.Rtf objFaxDocument.DocumentName = FaxSubject.Text objFaxDocument.Priority = FAXCOMEXLib.FAX_PRIORITY_TYPE_ENUM.fptHIGH objFaxDocument.Recipients.Add(FaxNum.Text, FaxTo.Text) objFaxDocument.AttachFaxToReceipt = True If CoverPage.Checked Then objFaxDocument.CoverPageType = FAXCOMEXLib.FAX_COVERPAGE_TYPE_ENUM.fcptSERVER objFaxDocument.CoverPage = "generic" objFaxDocument.Note = FaxNote.Text objFaxDocument.Sender.LoadDefaultSender() End IF objFaxDocument.Subject = FaxSubject.Text JobID = objFaxDocument.ConnectedSubmit(objFaxServer) MsgBox("The Job ID is :" & JobID(0)) Exit Sub Error_Handler: MsgBox("Error : " & Hex(Err.Number) & ", " & Err.Description) End Sub

That's it for this final program. You can test it out to see if it is working correctly.

Summary

Congratulations on making it through this entire text. You should now have a good understanding of the wide variety of applications that can be created for the Tablet PC. When learning any new programming concepts, you will undoubtedly have many questions. There are several great places to learn online, including the TabletPC Developer Web site at www.tabletpcdeveloper.com and the Tablet PC developer usenet newsgroup: microsoft.public.windows.tabletpc.developer.

Категории