home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / appshell / appprset.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  5.6 KB  |  184 lines

  1. VERSION 2.00
  2. Begin Form AppPrSetup 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Printer Setup"
  5.    ClientHeight    =   2010
  6.    ClientLeft      =   360
  7.    ClientTop       =   2310
  8.    ClientWidth     =   5100
  9.    Height          =   2415
  10.    Left            =   300
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   2010
  16.    ScaleWidth      =   5100
  17.    Top             =   1965
  18.    Width           =   5220
  19.    Begin CommandButton SetupCmd 
  20.       Caption         =   "&Setup..."
  21.       Height          =   315
  22.       Left            =   3900
  23.       TabIndex        =   3
  24.       Top             =   1440
  25.       Width           =   1035
  26.    End
  27.    Begin CommandButton CancelCmd 
  28.       Cancel          =   -1  'True
  29.       Caption         =   "Cancel"
  30.       Height          =   315
  31.       Left            =   3900
  32.       TabIndex        =   2
  33.       Top             =   540
  34.       Width           =   1035
  35.    End
  36.    Begin ListBox PrinterList 
  37.       Height          =   1395
  38.       Left            =   120
  39.       Sorted          =   -1  'True
  40.       TabIndex        =   4
  41.       Top             =   420
  42.       Width           =   3615
  43.    End
  44.    Begin CommandButton OKCmd 
  45.       Caption         =   "OK"
  46.       Default         =   -1  'True
  47.       Height          =   315
  48.       Left            =   3900
  49.       TabIndex        =   1
  50.       Top             =   120
  51.       Width           =   1035
  52.    End
  53.    Begin Label PrinterLabel 
  54.       Caption         =   "&Printer:"
  55.       Height          =   255
  56.       Left            =   120
  57.       TabIndex        =   0
  58.       Top             =   120
  59.       Width           =   735
  60.    End
  61. Dim PrinterName(10) As String
  62. Dim DriverName(10)  As String
  63. Dim PortName(10)    As String
  64. Sub CancelCmd_Click ()
  65.   Unload AppPrSetup
  66. End Sub
  67. Sub Form_Load ()
  68.   Dim SelPrName As String
  69.   Remove_Items_From_SysMenu AppPrSetup
  70.   Place_DialogBox_in_Form AppPrSetup, AppMain
  71.   If App_PrSetupTitle = "" Then
  72.     App_PrSetupTitle = "Printer Setup"
  73.   End If
  74.   AppPrSetup.Caption = App_PrSetupTitle
  75.   ' empty the printer list box
  76.   Do While PrinterList.ListCount
  77.     PrinterList.RemoveItem 0
  78.   Loop
  79.   ' if no currently selected printer, use the default
  80.   If App_PrinterName = "" Then
  81.     buf$ = String$(2048, 0)
  82.     BufSize% = Len(buf$)
  83.     y% = GetProfileString("windows", ByVal "device", "Error", buf$, BufSize%)
  84.     If buf$ <> "Error" Then
  85.       SelPrName = Left$(buf$, InStr(buf$, ",") - 1)
  86.     End If
  87.   Else
  88.     SelPrName = App_PrinterName
  89.   End If
  90.   ' get the new list of printers
  91.   buf$ = String$(2048, 0)
  92.   y% = GetProfileString("devices", ByVal 0&, "Error", buf$, BufSize%)
  93.   ' parse list and load list box
  94.   i% = -1  ' number of printers loaded
  95.   j% = 1
  96.   k% = InStr(j%, buf$, Chr$(0))     ' end index into buffer
  97.   While (k% <> 0 And j% < k%)
  98.     LoadPrinterList Mid$(buf$, j%, k% - j%), i%
  99.     j% = k% + 1
  100.     k% = InStr(j%, buf$, Chr$(0))
  101.   Wend
  102.   If i% < 0 Then
  103.     MsgBox "No Printers Found", MB_ICONSTOP, AppPrSetup.Caption
  104.   Else
  105.     '
  106.     ' highlight currently selected printer in list box
  107.     '
  108.     For j% = 0 To i%
  109.       If Left$(PrinterList.List(j%), Len(SelPrName)) = SelPrName Then
  110.         PrinterList.ListIndex = j%
  111.         Exit For
  112.       End If
  113.     Next
  114.   End If
  115. End Sub
  116. Sub LoadPrinterList (PrName As String, PrNum As Integer)
  117.     buf$ = String$(80, 0)
  118.     BufSize% = Len(buf$)
  119.     key$ = PrName
  120.     '
  121.     ' find out the driver name and port name
  122.     '
  123.     y% = GetProfileString("devices", ByVal key$, "Error", buf$, BufSize%)
  124.     buf$ = Left$(buf$, InStr(buf$, Chr$(0)) - 1)
  125.     i% = InStr(buf$, ",")
  126.     If i% > 0 Then
  127.       a$ = Left$(buf$, i% - 1)
  128.       b$ = Right$(buf$, Len(buf$) - i%)
  129.       If b$ <> "None" Then
  130.         PrinterList.AddItem key$ + " on " + b$
  131.         PrNum = PrNum + 1
  132.         PrinterName(PrNum) = PrName
  133.         DriverName(PrNum) = a$
  134.         PortName(PrNum) = b$
  135.       End If
  136.     End If
  137. End Sub
  138. Sub OKCmd_Click ()
  139.   x% = PrinterList.ListIndex
  140.   If x% < 0 Then
  141.     MsgBox "Must select a printer", MB_ICONINFORMATION, AppPrSetup.Caption
  142.   Else
  143.     For x% = 0 To 10
  144.       If Left$(PrinterList.Text, Len(PrinterName(x%))) = PrinterName(x%) Then Exit For
  145.     Next
  146.     App_PrinterName = PrinterName(x%)
  147.     App_PrinterDriver = DriverName(x%)
  148.     App_PrinterPort = PortName(x%)
  149.     Unload AppPrSetup
  150.   End If
  151. End Sub
  152. Sub PrinterList_DblClick ()
  153.   OKCmd_Click
  154. End Sub
  155. Sub SetupCmd_Click ()
  156.   x% = PrinterList.ListIndex
  157.   If x% < 0 Then
  158.     MsgBox "Must select a printer", MB_ICONINFORMATION, AppPrSetup.Caption
  159.   Else
  160.     '
  161.     ' determine printer to setup
  162.     '
  163.     For x% = 0 To 10
  164.       If Left$(PrinterList.Text, Len(PrinterName(x%))) = PrinterName(x%) Then Exit For
  165.     Next
  166.     '
  167.     ' call app shell dll routine to display printer setup dialog box
  168.     '
  169.     prn$ = PrinterName(x%)
  170.     dn$ = DriverName(x%) + ".drv"
  171.     pn$ = PortName(x%)
  172.     handle% = LoadLibrary("APPSHELL.DLL")
  173.     If handle% >= 32 Then
  174.       r% = AppShellPrSetup(AppPrSetup.hwnd, prn$, dn$, pn$)
  175.       If Not r% Then
  176.         MsgBox "Can't run printer setup;" + CRLF + "please check your installation", MB_ICONEXCLAMATION, APP_NAME
  177.       End If
  178.       FreeLibrary handle%
  179.     Else
  180.       MsgBox "Can't find printer setup program;" + CRLF + "reason code =" + Str$(handle%) + ";" + CRLF + "please check your software installation", MB_ICONEXCLAMATION, APP_NAME
  181.     End If
  182.   End If
  183. End Sub
  184.