home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / prset / prsetup.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  8.3 KB  |  265 lines

  1. VERSION 2.00
  2. Begin Form PrintSetup 
  3.    BackColor       =   &H00FFFF00&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Printer Setup"
  6.    ClientHeight    =   4200
  7.    ClientLeft      =   3465
  8.    ClientTop       =   2430
  9.    ClientWidth     =   6495
  10.    Height          =   4605
  11.    Left            =   3405
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   4200
  17.    ScaleWidth      =   6495
  18.    Top             =   2085
  19.    Width           =   6615
  20.    Begin CommandButton Command3 
  21.       Caption         =   "Setup ..."
  22.       FontBold        =   -1  'True
  23.       FontItalic      =   0   'False
  24.       FontName        =   "MS Sans Serif"
  25.       FontSize        =   9.75
  26.       FontStrikethru  =   0   'False
  27.       FontUnderline   =   0   'False
  28.       Height          =   495
  29.       Left            =   4800
  30.       TabIndex        =   3
  31.       Top             =   3120
  32.       Width           =   1575
  33.    End
  34.    Begin CommandButton Command2 
  35.       Caption         =   "Cancel"
  36.       FontBold        =   -1  'True
  37.       FontItalic      =   0   'False
  38.       FontName        =   "MS Sans Serif"
  39.       FontSize        =   9.75
  40.       FontStrikethru  =   0   'False
  41.       FontUnderline   =   0   'False
  42.       Height          =   495
  43.       Left            =   4800
  44.       TabIndex        =   2
  45.       Top             =   1440
  46.       Width           =   1575
  47.    End
  48.    Begin CommandButton Command1 
  49.       Caption         =   "OK"
  50.       Default         =   -1  'True
  51.       FontBold        =   -1  'True
  52.       FontItalic      =   0   'False
  53.       FontName        =   "MS Sans Serif"
  54.       FontSize        =   9.75
  55.       FontStrikethru  =   0   'False
  56.       FontUnderline   =   0   'False
  57.       Height          =   495
  58.       Left            =   4800
  59.       TabIndex        =   1
  60.       Top             =   480
  61.       Width           =   1575
  62.    End
  63.    Begin ListBox List1 
  64.       FontBold        =   -1  'True
  65.       FontItalic      =   0   'False
  66.       FontName        =   "MS Sans Serif"
  67.       FontSize        =   9.75
  68.       FontStrikethru  =   0   'False
  69.       FontUnderline   =   0   'False
  70.       Height          =   3150
  71.       Left            =   120
  72.       TabIndex        =   0
  73.       Top             =   480
  74.       Width           =   4455
  75.    End
  76.    Begin Label Label2 
  77.       BackColor       =   &H00FFFF00&
  78.       Caption         =   "Copyright (c) 1991 Corey Schwartz, Programmer's Warehouse 602-443-0580, 73240,2734 All Rights Reserved"
  79.       Height          =   375
  80.       Left            =   120
  81.       TabIndex        =   5
  82.       Top             =   3720
  83.       Width           =   6375
  84.    End
  85.    Begin Label Label1 
  86.       BackColor       =   &H00FFFF00&
  87.       Caption         =   "&Printer"
  88.       FontBold        =   -1  'True
  89.       FontItalic      =   0   'False
  90.       FontName        =   "MS Sans Serif"
  91.       FontSize        =   9.75
  92.       FontStrikethru  =   0   'False
  93.       FontUnderline   =   0   'False
  94.       Height          =   255
  95.       Left            =   120
  96.       TabIndex        =   4
  97.       Top             =   120
  98.       Width           =   1695
  99.    End
  100. Const DM_UPDATE = 1
  101. Const DM_COPY = 2
  102. Const DM_PROMPT = 4
  103. Const DM_MODIFY = 8
  104. Const SIZETEMPBUFF = 80
  105. Const MAXKEYBUFFER = 300
  106. Declare Function CallProc Lib "CallAddr.DLL" (ByVal fnc&, ByVal hWnd%, ByVal hDrv%, ByVal dmOut&, ByVal lpName$, ByVal lpPort$, ByVal dmIn&, ByVal lpPro As Any, ByVal wMode%) As Integer
  107. Declare Function GetProcAddress Lib "Kernel" (ByVal hDrv%, ByVal Esc As String) As Long
  108. Sub AccessPrinter (UpdatePrt As Integer)
  109.     Dim lpName As String
  110.     Dim lpPort As String
  111.     Dim lpDriver As String
  112.     Dim TempStr As String
  113.     Dim hMem As Integer
  114.     Dim lpfnMode As Long
  115.     Dim hDriver As Integer
  116.     Dim Flags As Integer
  117.     If List1.ListIndex = -1 Then
  118.     Exit Sub
  119.     End If
  120.     Screen.MousePointer = 11
  121.     TempStr = List1.list(List1.ListIndex)
  122.     x = lbParse(TempStr, lpName, lpPort, lpDriver)
  123.     hDriver = LoadLibrary(lpDriver)
  124.     If (hDriver >= 32) Then
  125.     lpfnMode = GetProcAddress(hDriver, "EXTDEVICEMODE")
  126.     If (lpfnMode <> 0) Then
  127.        wSizeDM = CallProc(lpfnMode, 0&, hDriver, 0&, lpName, lpPort, 0&, 0&, 0)
  128.        If (wSizeDM <> 0) Then
  129.            hMem = GlobalAlloc(GHND, wSizeDM)
  130.            If (hMem <> 0) Then
  131.             pDM = GlobalLock(hMem)
  132.             dummy = CallProc(lpfnMode, 0&, hDriver, pDM, lpName, lpPort, 0&, "WIN.INI", DM_COPY)
  133.             wFlags = DM_UPDATE Or DM_MODIFY
  134.             If UpdatePrt Then
  135.                wFlags = wFlags Or DM_PROMPT
  136.             End If
  137.             dummy = CallProc(lpfnMode, 0&, hDriver, 0&, lpName, lpPort, pDM, "WIN.INI", wFlags)
  138.             dummy = GlobalUnlock(hMem)
  139.            End If
  140.        End If
  141.     End If
  142.     FreeLibrary (hDriver)
  143.     End If
  144.     Screen.MousePointer = 0
  145. End Sub
  146. Sub Command1_Click ()
  147.     If List1.ListIndex >= 0 Then
  148.     AccessPrinter (False)
  149.     End If
  150.     Unload PrintSetup
  151. End Sub
  152. Sub Command1_KeyPress (KeyAscii As Integer)
  153.     kbDaemon (KeyAscii)
  154. End Sub
  155. Sub Command2_Click ()
  156.     Unload PrintSetup
  157. End Sub
  158. Sub Command2_KeyPress (KeyAscii As Integer)
  159.     kbDaemon (KeyAscii)
  160. End Sub
  161. Sub Command3_Click ()
  162.     AccessPrinter (True)
  163. End Sub
  164. Sub Command3_KeyPress (KeyAscii As Integer)
  165.     kbDaemon (KeyAscii)
  166. End Sub
  167. Sub Form_KeyPress (KeyAscii As Integer)
  168.     kbDaemon (KeyAscii)
  169. End Sub
  170. Sub Form_Load ()
  171.     lbsetup List1
  172. End Sub
  173. Sub kbDaemon (KeyAscii As Integer)
  174.     If KeyAscii = Asc("P") Or KeyAscii = Asc("p") Then
  175.     List1.GotFocus = True
  176.     End If
  177. End Sub
  178. Function lbLookup (c As Control, Key As String)
  179.     x% = c.ListCount - 1
  180.     For i% = 0 To x%
  181.     If (c.list(i%) = Key) Then
  182.         lbLookup = i%
  183.         Exit Function
  184.     End If
  185.     Next
  186.     lbLookup = -1
  187. End Function
  188. Function lbParse (SrcString As String, lpPrinter As String, lpPort As String, lpDriver As String) As Integer
  189.     'We assume that the input string is
  190.     'in the form: <Printer> on <Port>
  191.     Dim cBuff1 As String * SIZETEMPBUFF
  192.     Dim fstru As OFSTRUCT
  193.     i = Len(SrcString)
  194.     strlen = i
  195.     While (i > 0 And Mid$(SrcString, i, 1) <> " ")
  196.     i = i - 1
  197.     Wend
  198.     lpPort = Trim(Mid$(SrcString, i + 1, strlen - i))
  199.     lpPrinter = Trim$(Mid$(SrcString, 1, i - 3))
  200.     x = GetProfileString("devices", ByVal lpPrinter, ByVal 0&, cBuff1, SIZETEMPBUFF)
  201.     lpDriver = Trim(Mid$(cBuff1, 1, InStr(cBuff1, ",") - 1))
  202.     x = InStr(lpDriver, ".")
  203.     If x = 0 Then
  204.     lpDriver = lpDriver + ".Drv"
  205.     End If
  206.     x = OpenFile(lpDriver, fstru, OF_EXIST Or OF_READ)
  207.     If (x = -1) Then
  208.     lbParse = -1
  209.     Exit Function
  210.     End If
  211.     lbParse = 1
  212. End Function
  213. Sub lbsetup (lb As Control)
  214. Dim cBuff1 As String * SIZETEMPBUFF
  215. Dim lpKeyList As String * MAXKEYBUFFER
  216. Dim Str1 As String
  217. Dim i As Integer
  218. Dim j As Integer
  219. Dim lpKeyName As String
  220. Dim DeviceName As String
  221.     StrIndex = 1
  222.     j = GetProfileString("Devices", ByVal 0&, "No Devices Available", lpKeyList, MAXKEYBUFFER)
  223.     While (StrIndex <= j)
  224.     NullPos = InStr(StrIndex, lpKeyList, Chr$(0))
  225.     lpKeyName = Mid$(lpKeyList, StrIndex, NullPos - StrIndex)
  226.     cBuff1 = String$(SIZETEMPBUFF, Chr$(0))
  227.     i = GetProfileString("Devices", ByVal lpKeyName, ByVal 0&, cBuff1, SIZETEMPBUFF)
  228.     'The string Returned should be in the form:
  229.     '   PCL / HP LaserJet,HPPCL,LPT1:,LPT2:
  230.     'Get the device Name
  231.     x = InStr(1, cBuff1, ",") + 1
  232.     'Loop Through the devices adding a string to the listbox Control
  233.     Done = 0
  234.     While (Not Done)
  235.         NextComma = InStr(x, cBuff1, ",")
  236.         If NextComma = 0 Then
  237.         NextComma = i + 1
  238.         Done = -1
  239.         End If
  240.         Str1 = lpKeyName + " on " + Mid$(cBuff1, x, NextComma - x)
  241.         lb.AddItem Str1
  242.         x = NextComma + 1
  243.     Wend
  244.     StrIndex = NullPos + 1
  245.     Wend
  246.     '-------------------
  247.     'Get Default Printer
  248.     cBuff1 = String$(SIZETEMPBUFF, Chr$(0))
  249.     i = GetProfileString("Windows", "Device", ByVal 0&, cBuff1, SIZETEMPBUFF)
  250.     x = InStr(1, cBuff1, ",") + 1
  251.     NextComma = InStr(x, cBuff1, ",")
  252.     If NextComma = 0 Then
  253.        NextComma = i + 1
  254.     End If
  255.     Str1 = lpKeyName + " on " + Mid$(cBuff1, x, NextComma - x)
  256.     lb.ListIndex = lbLookup(lb, Str1)
  257. End Sub
  258. Sub List1_DblClick ()
  259.     AccessPrinter (False)
  260.     Unload PrintSetup
  261. End Sub
  262. Function Trim (Str1 As String) As String
  263.     Trim = LTrim$(RTrim$(Str1))
  264. End Function
  265.