Tech Tips
edited by George Frazier

Text-to-Speech in the Windows Applications with Microsoft SAPI
by Boris Eligulashvili


Listing One

<html>
<head>
<meta http-equiv="Refresh" content="60">
<!-- MeadCo ScriptX -->
<object id="factory" viewastext  style="display:none"
  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
  codebase="c:\scriptx\ScriptX.cab#Version=6,1,430,5">
</object>
<script defer>
function onload(){
  if (!factory.object){
    alert("Onload cannot find ScriptX Control.");
    return;
  }
  factory.printing.header = "Test Header";
  factory.printing.footer = "Test Footer";
  PrintThis();
}
function PrintThis(){
  if (!factory.object){
    alert("PrintThis cannot find ScriptX Control.");
    return;
  }
  factory.printing.print(false);
}
</script>
</head>
<frameset name="frameset" rows="*" onload="onload()">
  <frame name="frame_for_web_site" src="http://www.google.com">
</frameset>
</html>

Listing Two
import java.io.*;
import java.net.*;
import java.util.*;

public class AutoPrint{
  public static void main(String arg[]){
    // params for calling printHtml.bat
    String args[] = new String[3];
    args[0] = new String("c:\\autoprint\\printHtml.bat");
    args[1] = new String("c:\\autoprint\\testpage.html");
    args[2] = new String("\\\\printer_server\\a_printer");
    String testSite = "http://www.google.com";
    // the main loop
    while (true) {
      // retrieve the web page
      StringBuffer sb = new StringBuffer(100000);
      try {
        URL url = new URL(testSite);
    InputStream in = url.openStream();
    in = new BufferedInputStream(in);
    Reader reader = new InputStreamReader(in);
    int c;
    while ((c = reader.read()) != -1){
      sb.append((char)c);
    }
    in.close();
      } catch (MalformedURLException e) {
    System.err.println("Malformed: " + e);
      } catch (IOException e) {
    System.err.println("I/O Exception: " + e);
      }
      // save to a file
      File file = new File(args[1]);
      try{
    FileWriter fw = new FileWriter(file);
    fw.write(sb.toString());
    fw.close();
      } catch (Exception e){
    System.out.println(e.toString());
      }
      // is the file readable?
      if (!file.canRead()){
    System.out.println("Cannot read the file.");
    return;
      }
      // call printHtml.bat
      Process p = null;
      try {
    p = Runtime.getRuntime().exec(args);
      } catch (Exception e) {
    System.out.println(e.toString());
      }
      // wait for printHtml.bat to finish
      try {
    p.waitFor();
      } catch (InterruptedException e) {
        // need to do nothing.
      }
      // make a log
      Date date = new Date();
      System.out.println(date.toString() + " printHtml.bat called.");
      // be ready for next iteration
      try {
    Thread.sleep(600000);
    if(!file.delete()) {
      System.out.println("Cannot delete the file.");
      return;
    }
      } catch (Exception e) {
    System.out.println(e.toString());
      }
    }
  }
}


Listing Three

@ECHO OFF
SETLOCAL
SET File="%1"
SET Printer="%2"
IF NOT DEFINED File GOTO End
IF NOT DEFINED Printer GOTO End
:: Create a temporary Kix file to "press" Print button
> %TEMP%.\%~n0.kix ECHO.; Wait a few seconds for the Print dialog to appear
>>%TEMP%.\%~n0.kix ECHO SLEEP 2
>>%TEMP%.\%~n0.kix ECHO.; Press "Print" (Enter) using SendKeys function
>>%TEMP%.\%~n0.kix ECHO IF SETFOCUS("Print") = 0
>>%TEMP%.\%~n0.kix ECHO   $RC = SENDKEYS("{ENTER}")
>>%TEMP%.\%~n0.kix ECHO ENDIF

:: Actual print command
START RUNDLL32.EXE c:\winnt\system32\MSHTML.DLL,PrintHTML %File% 
%Printer%
:: Call the temporary Kix file to "press" Print button, then delete it
START /WAIT KIX32.EXE %TEMP%.\%~n0.kix
DEL %TEMP%.\%~n0.kix
:End
ENDLOCAL


Listing Four
/* StaticLibraryRoutineOne.c */
#include <ntddk.h>
#include "StaticLibraryTemplate.h"

VOID
FirstRoutine()
{
    DbgPrint("First routine entered in Static Library\n");
}
/* StaticLibraryRoutineTwo.c */
#include <ntddk.h>
#include "StaticLibraryTemplate.h"

VOID
SecondRoutine()
{
    DbgPrint("Second routine entered in Static Library\n");
}
/* StaticLibraryTemplate.h */
// Function prototypes for the two routines in the static library.

VOID FirstRoutine();
VOID SecondRoutine();




3


