home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / pronexus / sys / vbvfax.bas < prev    next >
Encoding:
BASIC Source File  |  1994-04-03  |  9.5 KB  |  297 lines

  1. Option Explicit
  2.  
  3. '   VBVoice WinFax Pro Version 3.0 Interface
  4.  
  5. '   This file contains interface functions to allow VBVoice developers to
  6. '   interface with Delrina's WinFax Pro product using DDE communications.
  7.  
  8. '   The constant VbvFaxPath must be adjusted to suit your system's setup.
  9. '   Please adjust accordingly.  The next two constants are not likely to
  10. '   change from system to system.
  11. Const LINK_NONE = 0
  12. Const LINK_MANUAL = 2
  13.  
  14. Const VbvFaxPath$ = "C:\apps\WINFAX"
  15. Const VbvFaxApplication$ = "FAXMNG"
  16. Const VbvFaxFullPath$ = "C:\apps\WINFAX\FAXMNG.EXE"
  17.  
  18. '       Run-time error codes.
  19. Global Const NoWinFaxResponse = 282
  20.  
  21. '       Function declarations to get and set strings in .INI files.
  22. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedSTRING As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  23. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpSTRING As String, ByVal lplFileName As String) As Integer
  24.  
  25. '**************
  26. '       VbvLinkPoke
  27. '**************
  28. '       Poke some values into a DDE link.
  29.  
  30. '       Parameters:
  31. '               DDELink - a text box (not necessarily visible!) which is used to
  32. '                       link to DDE.  The form containing this text box must be loaded.
  33. '               LinkItem$ - a string identifying which property is being poked.
  34. '               Text$ - a string containing the value being poked.
  35.  
  36. '********************
  37. '       VbvSetDestination
  38. '********************
  39. '       Set the destination name and number in the fax manager.
  40.  
  41. '       Parameters:
  42. '               DDELink - a text box (not necessarily visible!) which is used to
  43. '                       link to DDE.  The form containing this text box must be loaded.
  44. '               DestinationNumber$ - the fax number being dialed.
  45. '               RecipientName$ - the name of the fax's recipient.
  46.  
  47. '****************
  48. '       VbvGetPrinter
  49. '****************
  50. '       Get the current default printer for the system.
  51.  
  52. '       Returns:
  53. '               A string describing the current printer settings in WIN.INI.
  54.  
  55. '********************
  56. '       VbvActivateWinFax
  57. '********************
  58. '       Read WinFax settings from WIN.INI and set it as the default device.
  59.  
  60. '****************
  61. '       VbvSetPrinter
  62. '****************
  63. '       Set a printer description as the default printer.
  64.  
  65. '***************
  66. '       VbvPrintFile
  67. '***************
  68. '       Print off a given file to the WinFax fax manager.  Note that it is assumed
  69. '       by this function that the file is already formatted as expected.  Thus text
  70. '       files are assumed to have been formatted already with page breaks and
  71. '       margins.  If this is not the case, an preprocessing function of some sort
  72. '       should be created to format the text file into a temporary text file
  73. '       first.  This temporary text file should then be printed instead.
  74.  
  75. '*************
  76. '       VbvSendFax
  77. '*************
  78. '       Send a file to the fax manager.  This function is the entry point into the
  79. '       fax transmission portion of the library.
  80.  
  81. '       Parameters:
  82. '               DDELink - a text box (not necessarily visible!) which is used to
  83. '                       link to DDE.  The form containing this text box must be loaded.
  84. '               RecipientName$ - the name of the fax's recipient.
  85. '               DestinationNumber$ - the fax number being dialed.
  86. '               FaxFile$ - the ascii file being transmitted.
  87. '               CoverFile$ - the ascii text file used as a cover sheet.
  88.  
  89. '**************
  90. '       VbvFaxSetup
  91. '**************
  92. '       This function should be called once at the beginning of your program to
  93. '       establish a DDE link with WinFax.  The calling function should check for an
  94. '       error return in case we had a more serious problem than the fax manager
  95. '       not being loaded.
  96.  
  97. '       Parameters:
  98. '               DDELink - a text box (not necessarily visible!) which is used to
  99. '                       link to DDE.  The form containing this text box must be loaded.
  100.  
  101. '*****************
  102. '       VbvFaxShutdown
  103. '*****************
  104. '       This function should be called once at the end of your program to terminate
  105. '       the DDE link to WinFax's manager.
  106.  
  107. '       Parameters:
  108. '               DDELink - a text box (not necessarily visible!) which is used to
  109. '                       link to DDE.  The form containing this text box must be loaded.
  110.  
  111. Sub VbvActivateWinFax ()
  112.  
  113.     Dim WinFaxSettings$     'string containing WinFax's settings
  114.     Dim retStr As String * 255      'buffer for string returned from win.ini
  115.     Dim retStrSize%         'length of returned string
  116.     Dim retCode%
  117.  
  118.     'Get WinFax settings.
  119.     retStrSize% = GetPrivateProfileString("devices", "WINFAX", "", retStr$, 255, "win.ini")
  120.     WinFaxSettings$ = Left$(retStr$, retStrSize%)
  121.     If WinFaxSettings$ = "" Then
  122.         MsgBox "The WinFax device driver is not installed."
  123.         Error 712
  124.         Exit Sub
  125.     Else
  126.         WinFaxSettings$ = "WINFAX," + WinFaxSettings$
  127.     End If
  128.  
  129.     'Set WinFax as the default device.
  130.     retCode% = WritePrivateProfileString("windows", "device", WinFaxSettings$, "win.ini")
  131.     If retCode% = 0 Then
  132.         MsgBox "Error updating system default printer.", 16
  133.         Error 712
  134.     End If
  135.     
  136. End Sub
  137.  
  138. Sub vbvfaxsetup (DDELink As TextBox)
  139.  
  140.     On Error GoTo StartUpWinFax
  141.     DDELink.LinkMode = LINK_NONE
  142.     DDELink.LinkTopic = VbvFaxApplication + "|" + "Transmit"
  143.     DDELink.LinkMode = LINK_MANUAL
  144.  
  145.     'Adjust the following to taste.
  146.     'The alternative resolution value is "LOW".
  147.     Call VbvLinkPoke(DDELink, "SendFax", "resolution(""HIGH"")")
  148.  
  149.     Exit Sub
  150.  
  151. StartUpWinFax:  'Start up the WinFax manager if it isn't already.
  152.  
  153.     Dim retCode
  154.     
  155.     If Err = NoWinFaxResponse Then
  156.         
  157.         On Error Resume Next
  158.         retCode = Shell(VbvFaxFullPath, 6)
  159.         
  160.         If Err = 0 Then Resume  'If we still can't get it, we'll abort.
  161.         
  162.     End If
  163.  
  164. End Sub
  165.  
  166. Sub vbvfaxshutdown (DDELink As TextBox)
  167.  
  168.     DDELink.LinkMode = LINK_NONE
  169.  
  170. End Sub
  171.  
  172. Function VbvGetPrinter () As String
  173.  
  174.     Dim retStr     As String * 255   'buffer for string returned from win.ini
  175.     Dim retStrSize%         'length of returned string
  176.  
  177.     'Get current printer from WIN.INI.
  178.     retStrSize% = GetPrivateProfileString("windows", "device", "", retStr$, 255, "win.ini")
  179.  
  180.     'Return current printer setting.
  181.     VbvGetPrinter = Left$(retStr$, retStrSize%)
  182.  
  183. End Function
  184.  
  185. Sub VbvLinkPoke (DDELink As TextBox, Item$, ByVal Value$)
  186.  
  187.     DDELink.LinkItem = Item$
  188.     DDELink.Text = Value$
  189.     DDELink.LinkMode = LINK_MANUAL
  190.     DDELink.LinkPoke
  191.  
  192. End Sub
  193.  
  194. Sub vbvprintfile (ByVal File$)
  195.  
  196.     Dim TextLine$
  197.     
  198.     'Adjust the following lines to change font features.
  199.     Printer.FontName = "Times New Roman"
  200.     Printer.FontItalic = False
  201.     Printer.FontBold = False
  202.     Printer.FontSize = 12
  203.  
  204.     Open File$ For Input As #1
  205.  
  206.     'Print off one line at a time.
  207.     Do While Not EOF(1)
  208.  
  209.         Input #1, TextLine$
  210.         Printer.Print ; TextLine$
  211.         DoEvents
  212.  
  213.     Loop
  214.  
  215.     Close #1
  216.  
  217.     'Note that, since multiple files may be printed to the fax in a single
  218.     'session, we do not send the Printer.EndDoc statement.  This is the
  219.     'responsibility of the calling function.
  220.     
  221. End Sub
  222.  
  223. Sub VbVRequestItem (DDELink As TextBox, Item$, ByVal Value$)
  224.     DDELink.LinkItem = Item$
  225.     DDELink.LinkRequest
  226.     Value$ = DDELink.Text
  227. End Sub
  228.  
  229. Sub vbvsendfax (DDELink As TextBox, ByVal RecipientName$, ByVal DestinationNumber$, ByVal FaxFile$, ByVal CoverFile$)
  230.  
  231.     Dim Destination$, OldPrinter$
  232.     
  233.     On Error GoTo EndSendFax
  234.     Call VbvSetDestination(DDELink, DestinationNumber$, RecipientName$)
  235.     
  236.     On Error Resume Next
  237.     OldPrinter$ = VbvGetPrinter()
  238.     Call VbvActivateWinFax
  239.     
  240.     'If there's no error, send the fax.
  241.     If Err = 0 Then
  242.         
  243.         On Error GoTo EndSendFax
  244.  
  245.         Call vbvprintfile(CoverFile$)
  246.         Printer.NewPage                                 'don't merge cover with text
  247.         Call vbvprintfile(FaxFile$)
  248.         Printer.EndDoc                                  'make sure that file is sent!
  249.  
  250.         'return default printer to previous setting
  251.         Call vbvsetprinter(OldPrinter$)
  252.  
  253.     End If
  254.     Exit Sub
  255. EndSendFax:
  256.  
  257.     MsgBox Error$
  258. '   VbvWinFaxDisconnect (DDELink)
  259.     Exit Sub
  260.  
  261. End Sub
  262.  
  263. 'this sub allows a fax to be scheduled, sent to multiple recipeints,
  264. 'allows name, company, subkect, keywords and billing code to be
  265. 'specified. Use this instead of vbv
  266. 'IMPORTANT NOTE : this functions not tested yet ....
  267. Sub vbvSetDestDetailed (DDELink As TextBox, ByVal faxnum$, ByVal sendtime As Variant, ByVal toname$, ByVal company$, ByVal subject$, ByVal keywords$, ByVal billingcode$)
  268. Dim sendtimestr$, senddatestr$
  269. sendtimestr = Format(sendtime, "hh:mm:ss")
  270. senddatestr = Format(sendtime, "mm/dd/yy")
  271. Call VbvLinkPoke(DDELink, "SendFax", "recipient(" + faxnum$ + "," + sendtimestr + "," + senddatestr + "," + toname$ + "," + company$ + "," + subject$ + "," + keywords$ + "," + billingcode$)
  272.  
  273. End Sub
  274.  
  275. Sub VbvSetDestination (DDELink As TextBox, ByVal DestinationNumber$, ByVal RecipientName$)
  276.  
  277.     Call VbvLinkPoke(DDELink, "Receiver", RecipientName$)
  278.     Call VbvLinkPoke(DDELink, "Fax Number", DestinationNumber$)
  279.  
  280. End Sub
  281.  
  282. Sub vbvsetprinter (Printer$)
  283.  
  284.     Dim retStr As String * 255
  285.     Dim retCode%
  286.  
  287.     'Update WIN.INI with given device.
  288.     retCode% = WritePrivateProfileString("windows", "device", Printer$, "win.ini")
  289.  
  290.     If retCode% = 0 Then
  291.         MsgBox "Could not reset device'" + Printer$ + "'", 16
  292.         Error 712
  293.     End If
  294.     
  295. End Sub
  296.  
  297.