home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 October / PCWorld_2002-10_cd.bin / Software / Topware / fprint / fpdk400.exe / samples / vb6 / FPdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-07-18  |  11.2 KB  |  328 lines

  1. VERSION 5.00
  2. Begin VB.Form FPdemo 
  3.    Caption         =   "FinePrint API Sample Application"
  4.    ClientHeight    =   3090
  5.    ClientLeft      =   45
  6.    ClientTop       =   345
  7.    ClientWidth     =   5865
  8.    Icon            =   "FPdemo.frx":0000
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3090
  11.    ScaleWidth      =   5865
  12.    StartUpPosition =   2  'CenterScreen
  13.    Begin VB.CommandButton btnExit 
  14.       Cancel          =   -1  'True
  15.       Caption         =   "Exit"
  16.       Height          =   400
  17.       Left            =   3600
  18.       TabIndex        =   6
  19.       Top             =   2520
  20.       Width           =   2052
  21.    End
  22.    Begin VB.CommandButton Command1 
  23.       Caption         =   "Set as default"
  24.       Height          =   400
  25.       Left            =   480
  26.       TabIndex        =   4
  27.       Top             =   2520
  28.       Width           =   2052
  29.    End
  30.    Begin VB.ListBox List1 
  31.       Height          =   2010
  32.       Left            =   120
  33.       Sorted          =   -1  'True
  34.       TabIndex        =   3
  35.       Top             =   360
  36.       Width           =   3255
  37.    End
  38.    Begin VB.CommandButton btnPrint 
  39.       Caption         =   "Print FPDK.DOC"
  40.       Height          =   400
  41.       Left            =   3600
  42.       TabIndex        =   2
  43.       Top             =   1320
  44.       Width           =   2052
  45.    End
  46.    Begin VB.CommandButton btnAttr 
  47.       Caption         =   "Show FP layout attributes"
  48.       Height          =   400
  49.       Left            =   3600
  50.       TabIndex        =   1
  51.       Top             =   840
  52.       Width           =   2052
  53.    End
  54.    Begin VB.CommandButton btnOpenDialog 
  55.       Caption         =   "Show FP dialog"
  56.       Height          =   400
  57.       Left            =   3600
  58.       TabIndex        =   0
  59.       Top             =   360
  60.       Width           =   2052
  61.    End
  62.    Begin VB.Label Label1 
  63.       AutoSize        =   -1  'True
  64.       Caption         =   "Printers:"
  65.       Height          =   195
  66.       Left            =   120
  67.       TabIndex        =   5
  68.       Top             =   120
  69.       Width           =   570
  70.    End
  71. Attribute VB_Name = "FPdemo"
  72. Attribute VB_GlobalNameSpace = False
  73. Attribute VB_Creatable = False
  74. Attribute VB_PredeclaredId = True
  75. Attribute VB_Exposed = False
  76. Option Explicit
  77. Dim StartupPrinter As String
  78.       
  79.       Private Sub GetDriverAndPort(ByVal Buffer As String, DriverName As _
  80.           String, PrinterPort As String)
  81.           Dim iDriver As Integer
  82.           Dim iPort As Integer
  83.           DriverName = ""
  84.           PrinterPort = ""
  85.           'The driver name is first in the string terminated by a comma
  86.           iDriver = InStr(Buffer, ",")
  87.           If iDriver > 0 Then
  88.               'Strip out the driver name
  89.               DriverName = Left(Buffer, iDriver - 1)
  90.               'The port name is the second entry after the driver name
  91.               'separated by commas.
  92.               iPort = InStr(iDriver + 1, Buffer, ",")
  93.               If iPort > 0 Then
  94.                   'Strip out the port name
  95.                   PrinterPort = Mid(Buffer, iDriver + 1, _
  96.                   iPort - iDriver - 1)
  97.               End If
  98.           End If
  99.       End Sub
  100.       
  101.       Private Sub ParseList(lstCtl As Control, ByVal Buffer As String)
  102.           Dim i As Integer
  103.           Dim s As String
  104.           Do
  105.               i = InStr(Buffer, Chr(0))
  106.               If i > 0 Then
  107.                   s = Left(Buffer, i - 1)
  108.                   If Len(Trim(s)) Then lstCtl.AddItem s
  109.                   Buffer = Mid(Buffer, i + 1)
  110.                   If Trim(s) = Printer.DeviceName Then lstCtl.Text = Trim(s)
  111.               Else
  112.                   If Len(Trim(Buffer)) Then lstCtl.AddItem Buffer
  113.                   Buffer = ""
  114.               End If
  115.           Loop While i > 0
  116.       End Sub
  117.       Private Sub SetDefaultPrinter()
  118.           
  119.           Dim Buffer As String
  120.           Dim DeviceName As String
  121.           Dim DriverName As String
  122.           Dim PrinterPort As String
  123.           Dim PrinterName As String
  124.           Dim DeviceLine As String
  125.           Dim r As Long
  126.           
  127.           If List1.ListIndex > -1 Then
  128.               'Get the printer information for the currently selected
  129.               'printer in the list. The information is taken from the
  130.               'WIN.INI file.
  131.               Buffer = Space(1024)
  132.               PrinterName = List1.Text
  133.               r = GetProfileString("PrinterPorts", PrinterName, "", _
  134.                   Buffer, Len(Buffer))
  135.               'Parse the driver name and port name out of the buffer
  136.               GetDriverAndPort Buffer, DriverName, PrinterPort
  137.               If DriverName <> "" And PrinterPort <> "" Then
  138.                 DeviceLine = List1.Text & "," & DriverName & "," & PrinterPort
  139.                 
  140.                 ' Store the new printer information in the [WINDOWS] section of
  141.                 ' the WIN.INI file for the DEVICE= item
  142.                 r = WriteProfileString("windows", "Device", DeviceLine)
  143.                 
  144.                 ' Cause all applications to reload the INI file:
  145.                 r = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "windows")
  146.               End If
  147.           End If
  148.       End Sub
  149.       
  150. Private Sub btnExit_Click()
  151.     Unload Me
  152.     End
  153. End Sub
  154. Private Sub Command1_Click()
  155.     Call SetDefaultPrinter
  156. End Sub
  157. Private Sub Form_Load()
  158.         
  159.     Dim r As Long
  160.     Dim Buffer As String
  161.     'Get the list of available printers from WIN.INI
  162.     Buffer = Space(8192)
  163.     r = GetProfileString("PrinterPorts", vbNullString, "", _
  164.        Buffer, Len(Buffer))
  165.     'Display the list of printer in the list box List1
  166.     ParseList List1, Buffer
  167.     StartupPrinter = List1.Text
  168. End Sub
  169. Private Sub btnAttr_Click()
  170.     FPattributes.Show 1, Me
  171. End Sub
  172. Private Sub btnOpenDialog_Click()
  173.     Dim result As Long
  174.     Dim szFinePrinter As String
  175.     Dim hfp As Long
  176.     Dim dwDlg As Long
  177.     szFinePrinter = "FinePrint Driver"
  178.     result = fpOpen(szFinePrinter, hfp)
  179.     If result <> 0 Then
  180.         MsgBox "FinePrint Error: " & ErrorText(result)
  181.         Exit Sub
  182.     End If
  183.     result = fpDisplayDialog(hfp, dwDlg)
  184.     Select Case dwDlg
  185.         Case IDOK
  186.             MsgBox "User pressed 'OK'"
  187.         Case IDCANCEL
  188.             MsgBox "User pressed 'Cancel'"
  189.         Case IDDEFER
  190.             MsgBox "User pressed 'Defer'"
  191.         Case IDDEFERALL
  192.             MsgBox "User pressed 'Defer all'"
  193.         Case Else
  194.             MsgBox "User pressed button value " & dwDlg
  195.     End Select
  196.     result = FpClose(hfp, False)
  197. End Sub
  198. Private Sub btnPrint_Click()
  199.     Dim result As Long
  200.     Dim fpe As Long
  201.     Dim szFinePrinter As String
  202.     Dim hfp As Long
  203.     Dim dwDlg As Long
  204.     Dim intAttr As Integer
  205.     Dim lngAttr As Long
  206.     Dim bAttr As Boolean
  207.     Dim strAttr As String
  208.     Dim lenAttr As Long
  209.     Dim szStat As String
  210.     Dim phStat As Long
  211.     Dim szWatermark As String
  212.     Dim pLogFont As LOGFONT
  213.     Dim oldPrinter As Printer
  214.     Dim P As Printer
  215.     Dim jcOrig As FpJobCount
  216.     Dim lpShellExecuteInfo As SHELLEXECUTEINFO
  217.     Dim hwnd As Long
  218.     Dim lpOperation As String
  219.     Dim lpFile As String
  220.     Dim lpParameters As String
  221.     Dim lpDirectory As String
  222.     Dim nShowCmd As Long
  223.     Dim hProcess As Long
  224.     Dim cSecTimeoutStart As Long
  225.     Dim cSecTimeoutPrint As Long
  226.     Dim pjs As FpJobStatus
  227.     szFinePrinter = vbNullString
  228.     fpe = fpOpen(szFinePrinter, hfp)
  229.     If fpe <> 0 Then
  230.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  231.         Exit Sub
  232.     End If
  233.     'select the N-up, borders, and margins settings
  234.     lngAttr = eLayout4
  235.     fpe = fpSetLayoutAttr(hfp, eliLayout, ByVal lngAttr)
  236.     If fpe <> 0 Then
  237.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  238.         GoTo FpClose
  239.     End If
  240.     lngAttr = eBordersOn
  241.     fpe = fpSetLayoutAttr(hfp, eliBorders, ByVal lngAttr)
  242.     If fpe <> 0 Then
  243.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  244.         GoTo FpClose
  245.     End If
  246.     lngAttr = eMarginMedium
  247.     fpe = fpSetLayoutAttr(hfp, eliMargins, ByVal lngAttr)
  248.     If fpe <> 0 Then
  249.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  250.         GoTo FpClose
  251.     End If
  252.     szStat = "VB6 stationery"
  253.     fpe = fpCreateStationery(hfp, szStat, phStat)
  254.     If fpe <> 0 Then
  255.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  256.         GoTo FpClose
  257.     End If
  258.     szWatermark = "VB6 watermark"
  259.     fpe = fpSetStationeryAttr(hfp, phStat, esiWatermark, esiaText, ByVal szWatermark)
  260.     If fpe <> 0 Then
  261.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  262.         GoTo FpClose
  263.     End If
  264.     lenAttr = Len(pLogFont)
  265.     fpe = fpGetStationeryAttr(hfp, phStat, esiWatermark, esiaFont, pLogFont, lenAttr)
  266.     'szFontname = Left(StrConv(pLogFont.lfFaceName, vbFromUnicode), InStr(StrConv(pLogFont.lfFaceName, vbFromUnicode), Chr$(0)) - 1)
  267.     'pLogFont.lfFaceName = StrConv("Times New Roman", vbUnicode) & Chr$(0)
  268.     pLogFont.lfFaceName = "Times New Roman" & Chr$(0)
  269.     If fpe <> 0 Then
  270.         fpe = fpSetStationeryAttr(hfp, phStat, esiWatermark, esiaFont, pLogFont)
  271.         If fpe <> 0 Then
  272.             MsgBox "FinePrint Error: " & ErrorText(fpe)
  273.             GoTo FpClose
  274.         End If
  275.     End If
  276.     lngAttr = RGB(0, 0, 255)
  277.     fpe = fpSetStationeryAttr(hfp, phStat, esiWatermark, esiaColor, ByVal lngAttr)
  278.     If fpe <> 0 Then
  279.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  280.         GoTo FpClose
  281.     End If
  282.     fpe = fpCloseStationery(hfp, phStat)
  283.     If fpe <> 0 Then
  284.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  285.         GoTo FpClose
  286.     End If
  287.     fpe = fpSetLayoutAttr(hfp, eliStationery, ByVal szStat)
  288.     If fpe <> 0 Then
  289.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  290.         GoTo FpClose
  291.     End If
  292.     fpe = fpGetJobCount(hfp, jcOrig)
  293.     If fpe <> 0 Then
  294.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  295.         GoTo FpClose
  296.     End If
  297.     lpShellExecuteInfo.cbSize = Len(lpShellExecuteInfo)
  298.     lpShellExecuteInfo.hwnd = Me.hwnd
  299.     lpShellExecuteInfo.lpVerb = "print"
  300.     lpShellExecuteInfo.lpFile = "c:\fpdk4\doc\fpdk.doc"
  301.     lpShellExecuteInfo.nShow = SW_SHOWNORMAL
  302.     lpShellExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS
  303.     result = ShellExecuteEx(lpShellExecuteInfo)
  304.     cSecTimeoutStart = 60
  305.     cSecTimeoutPrint = 600
  306.     fpe = fpWaitForJob(hfp, jcOrig, lpShellExecuteInfo.hProcess, cSecTimeoutStart, cSecTimeoutPrint, pjs)
  307.     If lpShellExecuteInfo.hProcess <> 0 Then
  308.         result = CloseHandle(lpShellExecuteInfo.hProcess)
  309.     End If
  310.     If fpe <> 0 Then
  311.         MsgBox "FinePrint Error: " & ErrorText(fpe)
  312.         GoTo FpClose
  313.     End If
  314. '    fpe = fpDisplayDialog(hfp, dwDlg)
  315. '    If dwDlg <> IDCANCEL Then
  316. '        fpe = fpPrintAllJobs(hfp, vbNullString, True, True)
  317. '    End If
  318.     MsgBox "All tests completed successfully!"
  319. FpClose:
  320.     fpe = FpClose(hfp, True)
  321. End Sub
  322. Private Sub Form_Unload(Cancel As Integer)
  323.     If List1.Text <> StartupPrinter Then
  324.         List1.Text = StartupPrinter
  325.         Call SetDefaultPrinter
  326.     End If
  327. End Sub
  328.