Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

How to run TX Text Control in Internet Explorer

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.1
Released:April 04, 2001
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic 6.0
Download code:msie_cab.zip Download [13.93 KB, ZIP]

Browser Based vs. Traditional Applications

Traditional applications need to be installed on every single computer on a network. Each time a new computer is added, or a hard disk has crashed or was toasted by a virus, the system administrator has to go to that machine, insert all the CDs, and re-install all the programs. This makes up a major part of what IT managers call "total cost of ownership" - the manpower required to keep a network of computers up and running. One of the most promising ways to solve this problem is to run all software in a browser.

Programs are no longer created as stand-alone .exe files, but as ActiveX components, which are automatically downloaded and installed on first use. The process works pretty much like with the browser plugins for audio files or PDF documents: When you click one of these files for the first time, the appropriate plugin is downloaded and installed, and the file can be processed instantly.

ActiveX Documents

For an ActiveX control like TX Text Control, the easiest way to create a browser based application is to use Visual Basic's ActiveX Documents. With a few exceptions, creating ActiveX documents works the same as creating conventional stand-alone programs, and you can even use VB's Package and Deployment Wizard to create a CAB file that is automatically downloaded and installed from the network.

If you cannot wait to get started, have a look at this screenshot showing sample a word processing app, built on TX Text Control, in MSIE. Nothing has been installed, all we have done it to click on a link to the ActiveX:

In this first installment of a series about browser-based TX Text Control applications, we will create a little word processor which is automatically downloaded and installed from a web server. If you click on the link to the demo file, the program will be downloaded to your browser and will show the familiar TX Text Control window and toolbars.

There are some aspects we have not yet taken care of in this first demo, and therefore there are some things to adjust before you can run the sample:

  1. This first demo is not yet code signed (we will explain that later), so you need to set your browser's security to 'Low'.
  2. The demo requires Internet Explorer version 4.01 or newer.
  3. The demo requires VB6 runtime files.

ActiveX documents will not run in Netscape, they require Internet Explorer. This would be a problem if you create an application that is to be used on the Internet. However, the purpose of this series of sample programs is to show how to create and deploy business applications in an Intranet, and that is something completely different.

Now the fun part! Download and run the sample program.

To later remove the sample program, go to the Windows\Downloaded Program Files folder, right-click Project1.UserDocument1 and select Remove in the context menu.

Disclaimer: Although we have tested this sample program on various computers, you download and run it at your own risk. The Imaging Source Europe cannot be held liable for any damage it may cause. If you don't have a test computer with no important files on it, please download the sample source code instead of the executable.

How it works

The code (below) is the complete source code for our first sample program. It does about the same as the Simple sample program on the TX Text Control CD. If you compare the source code of the 2, you will notice 2 differences:

  1. The toolbars are connected in the UserDocument_Initialize Event, instead of the Form_Load event
  2. Loading and saving files is done through the Property Bag. For detailed information about Property Bags and ActiveX document programming in general, refer to the VB documentation, and search http://www.msdn.microsoft.com and for ActiveX Document.
  1. Private Sub mnuAbout_Click()
  2. frmAbout.Show vbModal
  3. End Sub
  4.  
  5. Private Sub TXTextControl1_Change()
  6. PropertyChanged "TextData"
  7. End Sub
  8.  
  9. Private Sub UserDocument_Initialize()
  10. TXTextControl1.ButtonBarHandle = TXButtonBar1.hWnd
  11. TXTextControl1.StatusBarHandle = TXStatusBar1.hWnd
  12. TXTextControl1.RulerHandle = TXRuler1.hWnd
  13. End Sub
  14.  
  15. Private Sub UserDocument_Resize()
  16. TXTextControl1.Height = ScaleHeight - TXButtonBar1.Height -
  17. TXStatusBar1.Height - TXRuler1.Height
  18. End Sub
  19.  
  20. Private Sub UserDocument_ReadProperties(PropBag As PropertyBag)
  21. Dim TextData() As Byte
  22. TextData = PropBag.ReadProperty("TextData", "")
  23. TXTextControl1.LoadFromMemory TextData, 9
  24. UserDocument_Resize
  25. End Sub
  26.  
  27. Private Sub UserDocument_WriteProperties(PropBag As PropertyBag)
  28. Dim TextData() As Byte
  29. TextData = TXTextControl1.SaveToMemory(9)
  30. PropBag.WriteProperty "TextData", TextData
  31. End Sub

The CAB file has been created with Visual Basic's Package and Deployment Wizard. Having started it, click on "Package", and then select "Internet Package". It will create a CAB file, a document file, and a HTML file. The HTML file is only needed for versions of Internet Explorer older than v4.01, which cannot load ActiveX Document files directly.

Using TX Text Control with HTML and VBScript

As an alternative to creating ActiveX Documents with Visual Basic, TX Text Control can also be used directly as an ActiveX object in HTML code. To include a TX Text Control in HTML code, it is declared as an object:

  1. <OBJECT
  2. classid="clsid:3D6D5D2F-B9F2-101C-AED5-00608CF525A5"
  3. id=objTX
  4. width=600
  5. height=400
  6. >
  7. <PARAM NAME="ViewMode" VALUE="2">
  8. <PARAM NAME="ScrollBars" VALUE="3">
  9. <PARAM NAME="PageWidth" VALUE="12240">
  10. <PARAM NAME="PageHeight" VALUE="15840">
  11. </OBJECT>

The classid= statement specifies TX Text Control's class ID, which Internet Explorer can use to locate it. (Note that this declaration requires that a TX Text Control has already been installed on your computer. We will later add a CAB file reference so that it can automatically be loaded and installed from a file server or the Internet.) The id=objTX statement assigns a name to the object which is used to access it from program code. The remaining lines set the width and height, and assign some initial values to some of TX Text Control's properties.

Step 1 - Displaying a TX Text Control on a HTML page

Little more than the HTML's object tag is required in order to display a TX Text Control on a HTML page. Only the minimum HTML declarations need to be added:

  1. <HTML>
  2. <HEAD>
  3. <TITLE>A Simple First Page</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <OBJECT
  7. classid="clsid:3D6D5D2F-B9F2-101C-AED5-00608CF525A5"
  8. id=objTX
  9. width=600
  10. height=400
  11. >
  12. <PARAM NAME="ViewMode" VALUE="2">
  13. <PARAM NAME="ScrollBars" VALUE="3">
  14. <PARAM NAME="PageWidth" VALUE="12240">
  15. <PARAM NAME="PageHeight" VALUE="15840">
  16. <PARAM NAME="Text" VALUE="TX Text Control running in Internet Explorer">
  17. </OBJECT>
  18. </BODY>
  19. </HTML>

The code shown here is contained in Step1.htm in the \IE\HTML sample source directory. Open the file in Internet Explorer to run the sample program.

Step 2 - Programming with VBScript

Having created a TX Text Control object on our HTML page, we now need a way to access its methods and properties. Internet Explorer supports VBScript, which is a subset of the Visual Basic programming language. All you need to create a VBScript program is a text editor, and the VBScript Language Reference which is available for download on Microsoft's web site.

As a simple example on how VBScript works, we add a button to our sample program from Step 1, and let it write some text in the TX Text Control window when you click on it.

A button is created in the BODY section of our HTML page like this:

  1. <FORM>
  2. <INPUT NAME="Button1" TYPE="BUTTON" VALUE="Click me!">
  3. </FORM>

In the HEADER part, we add some VBScript code to process the button's OnClick event:

  1. <SCRIPT LANGUAGE="VBScript">
  2. <!--
  3. Sub Button1_OnClick
  4. objTX.Text = "Thanks for clicking me!"
  5. End Sub
  6. -->
  7. </SCRIPT>

When the button is clicked on, the script code is executed and assigns some text to TX Text Control's Text property. All of TX Text Control's properties and methods can be used like this.

The code shown here is contained in Step2.htm in the \IE\HTML sample source directory.

Step 3 - Loading a file

Now that we know how to display a TX Text Control and access its properties, we can take care of some of the functions required in most word processing applications, which are file handling and printing.

To load a file, we first need to display a Common Dialog box which lets the user select the file to be opened. The common dialog box is added to the HTML page as an ActiveX object, just like the TX Text Control in Step 1:

  1. <OBJECT
  2. classid="clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB"
  3. id=objComDlg
  4. >
  5. </OBJECT>

In our button's OnClick event, we call objComDlg.ShowOpen to show the dialog box, and then, after the user has selected a filename, open the file in TX Text Control.

  1. Sub Button1_OnClick
  2. on error resume next
  3. objComDlg.Filename = ""
  4. objComDlg.Filter = "Microsoft Word Format " & _
  5. "(*.doc)|*.doc|" & _
  6. "Rich Text Format (*.rtf)|*.rtf|" & _
  7. "Hypertext Markup Language " & _
  8. "(*.htm, *.html)|*.htm;*html|" & _
  9. "Text Documents (*.txt)|*.txt"
  10. objComDlg.ShowOpen
  11. if err.number = 0 then
  12. If UCase(Right(objComDlg.FileName, 3)) = "DOC" Then
  13. objTX.Load objComDlg.Filename,0,9,0
  14. elseIf UCase(Right(objComDlg.FileName, 3)) = "RTF" _
  15. Then
  16. objTX.Load objComDlg.Filename,0,5,0
  17. elseIf UCase(Right(objComDlg.FileName, 3)) = "HTM" _
  18. or UCase(Right(objComDlg.FileName, 4)) = "HTML" Then
  19. objTX.Load objComDlg.Filename,0,4,0
  20. else
  21. objTX.Load objComDlg.Filename,0,1,0
  22. end if
  23. end if
  24. End Sub

The code shown here is contained in Step3.htm in the \IE\HTML sample source directory.

Step 4 - Printing

Printing works pretty much like loading a file: We first open a Common Dialog box (this time with objComDlg.ShowPrint instead of objComDlg.ShowOpen), and then pass the selected settings on to TX Text Control's PrintDoc method.

The code shown here is contained in Step4.htm in the \IE\HTML sample source directory.

Step 5 - Working with CAB files

One of the advantages of letting your application run in a web browser (instead of as a stand-alone .exe) is that there is no need to install it on each of the client's computers. This would be, of course, of little use if you still need to install TX Text Control. For this reason, TX Text Control is also available as a CAB file, which is automatically downloaded and installed when needed. Two changes are required to our sample program of Step 4 in order to make use of the CAB file.

An additional OBJECT tag is inserted for a .lpk file. This file is not TX Text Control specific, but includes license information for all ActiveX controls you use on a HTML page in encrypted form. It must be in the same directory as the .html file.

  1. <OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331" VIEWASTEXT>
  2. <PARAM NAME="LPKPath" VALUE="tx.lpk">
  3. </OBJECT>

The .lpk file can be created by using a program called Lpk_tool.exe, which is included in the Microsoft ActiveX SDK that is available for download from http://www.microsoft.com.

TX Text Control's OBJECT tag is extended by a reference to the CAB file. You can put the CAB file anywhere on a file server or on a web server. The codebase = statement (below) needs to be updated with the respective path.

  1. <OBJECT
  2. classid="clsid:3D6D5D2F-B9F2-101C-AED5-00608CF525A5"
  3. codebase="/path/to/your/tx.cab"
  4. id=objTX
  5. >
  6. <PARAM NAME="ViewMode" VALUE="2">
  7. <PARAM NAME="ScrollBars" VALUE="3">
  8. <PARAM NAME="PageWidth" VALUE="12240">
  9. <PARAM NAME="PageHeight" VALUE="15840">
  10. </OBJECT>

The code shown here is contained in Step5.htm in the \IE\HTML sample source directory. (Unless you have a fast Internet connection, you may want to edit the codebase="/path/to/your/tx.cab" line in step5.htm and let it point to the TX Text Control CAB file on your local hard disk instead of the one on www.textcontrol.com. Depending on where you have installed TX Text Control, it should read something like codebase="file:c:\program files\TX Text Control\Cab\Tx.cab").

How to obtain a code signed CAB file

TX Text Control's setup program has copied a CAB file to your Program Files\...\TX Text Control\cab folder. This CAB file includes all required TX Text Control files, and is suited for most applications, including a distribution in an intranet or from a file server. However, it has not been code signed, and therefore Internet Explorer will issue a security warning when you install it from the Internet. A code-signed CAB file which can be installed without generating such warnings is available free of charge from The Imaging Source - just ask and we will e-mail it to you.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place