| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| 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 |

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.
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:
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.
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:
Private Sub mnuAbout_Click() frmAbout.Show vbModal End Sub Private Sub TXTextControl1_Change() PropertyChanged "TextData" End Sub Private Sub UserDocument_Initialize() TXTextControl1.ButtonBarHandle = TXButtonBar1.hWnd TXTextControl1.StatusBarHandle = TXStatusBar1.hWnd TXTextControl1.RulerHandle = TXRuler1.hWnd End Sub Private Sub UserDocument_Resize() TXTextControl1.Height = ScaleHeight - TXButtonBar1.Height - TXStatusBar1.Height - TXRuler1.Height End Sub Private Sub UserDocument_ReadProperties(PropBag As PropertyBag) Dim TextData() As Byte TextData = PropBag.ReadProperty("TextData", "") TXTextControl1.LoadFromMemory TextData, 9 UserDocument_Resize End Sub Private Sub UserDocument_WriteProperties(PropBag As PropertyBag) Dim TextData() As Byte TextData = TXTextControl1.SaveToMemory(9) PropBag.WriteProperty "TextData", TextData 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.
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:
<OBJECT classid="clsid:3D6D5D2F-B9F2-101C-AED5-00608CF525A5" id=objTX width=600 height=400 > <PARAM NAME="ViewMode" VALUE="2"> <PARAM NAME="ScrollBars" VALUE="3"> <PARAM NAME="PageWidth" VALUE="12240"> <PARAM NAME="PageHeight" VALUE="15840"> </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.
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:
<HTML> <HEAD> <TITLE>A Simple First Page</TITLE> </HEAD> <BODY> <OBJECT classid="clsid:3D6D5D2F-B9F2-101C-AED5-00608CF525A5" id=objTX width=600 height=400 > <PARAM NAME="ViewMode" VALUE="2"> <PARAM NAME="ScrollBars" VALUE="3"> <PARAM NAME="PageWidth" VALUE="12240"> <PARAM NAME="PageHeight" VALUE="15840"> <PARAM NAME="Text" VALUE="TX Text Control running in Internet Explorer"> </OBJECT> </BODY> </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.
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:
<FORM> <INPUT NAME="Button1" TYPE="BUTTON" VALUE="Click me!"> </FORM>
In the HEADER part, we add some VBScript code to process the button's OnClick event:
<SCRIPT LANGUAGE="VBScript"> <!-- Sub Button1_OnClick objTX.Text = "Thanks for clicking me!" End Sub --> </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.
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:
<OBJECT classid="clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB" id=objComDlg > </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.
Sub Button1_OnClick on error resume next objComDlg.Filename = "" objComDlg.Filter = "Microsoft Word Format " & _ "(*.doc)|*.doc|" & _ "Rich Text Format (*.rtf)|*.rtf|" & _ "Hypertext Markup Language " & _ "(*.htm, *.html)|*.htm;*html|" & _ "Text Documents (*.txt)|*.txt" objComDlg.ShowOpen if err.number = 0 then If UCase(Right(objComDlg.FileName, 3)) = "DOC" Then objTX.Load objComDlg.Filename,0,9,0 elseIf UCase(Right(objComDlg.FileName, 3)) = "RTF" _ Then objTX.Load objComDlg.Filename,0,5,0 elseIf UCase(Right(objComDlg.FileName, 3)) = "HTM" _ or UCase(Right(objComDlg.FileName, 4)) = "HTML" Then objTX.Load objComDlg.Filename,0,4,0 else objTX.Load objComDlg.Filename,0,1,0 end if end if End Sub
The code shown here is contained in Step3.htm in the \IE\HTML sample source directory.
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.
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.
<OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331" VIEWASTEXT> <PARAM NAME="LPKPath" VALUE="tx.lpk"> </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.
<OBJECT classid="clsid:3D6D5D2F-B9F2-101C-AED5-00608CF525A5" codebase="/path/to/your/tx.cab" id=objTX > <PARAM NAME="ViewMode" VALUE="2"> <PARAM NAME="ScrollBars" VALUE="3"> <PARAM NAME="PageWidth" VALUE="12240"> <PARAM NAME="PageHeight" VALUE="15840"> </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").
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.