home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbprnt20 / vbprint.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-05-30  |  9.6 KB  |  295 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "VBPrint Functions"
  5.    ClientHeight    =   4215
  6.    ClientLeft      =   1665
  7.    ClientTop       =   3090
  8.    ClientWidth     =   6195
  9.    Height          =   4650
  10.    Left            =   1605
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4215
  13.    ScaleWidth      =   6195
  14.    Top             =   2715
  15.    Width           =   6315
  16.    Begin Frame Frame1 
  17.       BackColor       =   &H00C0C0C0&
  18.       Caption         =   "Printer Features"
  19.       Height          =   1695
  20.       Left            =   0
  21.       TabIndex        =   11
  22.       Top             =   2460
  23.       Width           =   6180
  24.       Begin ListBox lstRes 
  25.          Height          =   615
  26.          Left            =   5025
  27.          TabIndex        =   17
  28.          Top             =   420
  29.          Width           =   975
  30.       End
  31.       Begin ListBox lstBins 
  32.          Height          =   615
  33.          Left            =   3135
  34.          TabIndex        =   15
  35.          Top             =   420
  36.          Width           =   1785
  37.       End
  38.       Begin ListBox lstPapers 
  39.          Height          =   1200
  40.          Left            =   135
  41.          TabIndex        =   12
  42.          Top             =   420
  43.          Width           =   2940
  44.       End
  45.       Begin Label Label1 
  46.          AutoSize        =   -1  'True
  47.          BackStyle       =   0  'Transparent
  48.          Caption         =   "Resolutions"
  49.          Height          =   195
  50.          Index           =   5
  51.          Left            =   5025
  52.          TabIndex        =   16
  53.          Top             =   195
  54.          Width           =   1005
  55.       End
  56.       Begin Label Label1 
  57.          AutoSize        =   -1  'True
  58.          BackStyle       =   0  'Transparent
  59.          Caption         =   "Paper bins"
  60.          Height          =   195
  61.          Index           =   4
  62.          Left            =   3120
  63.          TabIndex        =   14
  64.          Top             =   195
  65.          Width           =   915
  66.       End
  67.       Begin Label Label1 
  68.          AutoSize        =   -1  'True
  69.          BackStyle       =   0  'Transparent
  70.          Caption         =   "Paper types"
  71.          Height          =   195
  72.          Index           =   3
  73.          Left            =   135
  74.          TabIndex        =   13
  75.          Top             =   195
  76.          Width           =   1020
  77.       End
  78.    End
  79.    Begin CheckBox chkDefault 
  80.       BackColor       =   &H00C0C0C0&
  81.       Caption         =   "Use Windows defaults in dialog"
  82.       Height          =   195
  83.       Left            =   75
  84.       TabIndex        =   5
  85.       Top             =   2175
  86.       Width           =   3270
  87.    End
  88.    Begin CheckBox chkPerm 
  89.       BackColor       =   &H00C0C0C0&
  90.       Caption         =   "Make changes permanent"
  91.       Height          =   195
  92.       Left            =   75
  93.       TabIndex        =   4
  94.       Top             =   1905
  95.       Width           =   2745
  96.    End
  97.    Begin Timer Timer1 
  98.       Interval        =   1000
  99.       Left            =   6015
  100.       Top             =   9670
  101.    End
  102.    Begin CommandButton cmdBtn 
  103.       Caption         =   "E&xit"
  104.       Height          =   330
  105.       Index           =   2
  106.       Left            =   4800
  107.       TabIndex        =   3
  108.       Top             =   1560
  109.       Width           =   1300
  110.    End
  111.    Begin CommandButton cmdBtn 
  112.       Caption         =   "Show &Dialog"
  113.       Height          =   330
  114.       Index           =   1
  115.       Left            =   4800
  116.       TabIndex        =   2
  117.       Top             =   1170
  118.       Width           =   1300
  119.    End
  120.    Begin CommandButton cmdBtn 
  121.       Caption         =   "&Set Default"
  122.       Height          =   330
  123.       Index           =   0
  124.       Left            =   4800
  125.       TabIndex        =   1
  126.       Top             =   780
  127.       Width           =   1300
  128.    End
  129.    Begin ListBox lstPrinters 
  130.       Height          =   1590
  131.       Left            =   60
  132.       TabIndex        =   0
  133.       Top             =   255
  134.       Width           =   3270
  135.    End
  136.    Begin Label lblDefDriver 
  137.       BackColor       =   &H00FFFFFF&
  138.       BackStyle       =   0  'Transparent
  139.       ForeColor       =   &H00FFFFFF&
  140.       Height          =   195
  141.       Left            =   4050
  142.       TabIndex        =   10
  143.       Top             =   510
  144.       Width           =   1410
  145.    End
  146.    Begin Label Label1 
  147.       AutoSize        =   -1  'True
  148.       BackStyle       =   0  'Transparent
  149.       Caption         =   "Driver:"
  150.       Height          =   195
  151.       Index           =   2
  152.       Left            =   3420
  153.       TabIndex        =   9
  154.       Top             =   525
  155.       Width           =   585
  156.    End
  157.    Begin Label lblDefault 
  158.       BackColor       =   &H00FFFFFF&
  159.       BackStyle       =   0  'Transparent
  160.       ForeColor       =   &H00FFFFFF&
  161.       Height          =   195
  162.       Left            =   3420
  163.       TabIndex        =   8
  164.       Top             =   270
  165.       Width           =   2610
  166.    End
  167.    Begin Label Label1 
  168.       AutoSize        =   -1  'True
  169.       BackStyle       =   0  'Transparent
  170.       Caption         =   "Current default printer:"
  171.       Height          =   195
  172.       Index           =   1
  173.       Left            =   3420
  174.       TabIndex        =   7
  175.       Top             =   30
  176.       Width           =   1935
  177.    End
  178.    Begin Label Label1 
  179.       AutoSize        =   -1  'True
  180.       BackStyle       =   0  'Transparent
  181.       Caption         =   "Installed printers"
  182.       Height          =   195
  183.       Index           =   0
  184.       Left            =   60
  185.       TabIndex        =   6
  186.       Top             =   30
  187.       Width           =   1425
  188.    End
  189. DefInt I
  190. DefLng L
  191. DefStr S
  192. Option Explicit
  193. Dim Shared DeviceData() As DEVMODE_TYPE
  194. Sub cmdBtn_Click (Index As Integer)
  195.   Dim iRet As Integer
  196.   Dim inMode As DEVMODE_TYPE
  197.   Dim outMode As DEVMODE_TYPE
  198.   Dim sTemp As String
  199.   Dim iMode As Integer
  200.   Dim sTemp2 As String
  201.   Select Case Index
  202.     Case 0
  203.       If lstPrinters.ListIndex = True Then Exit Sub
  204.       sTemp = lstPrinters.List(lstPrinters.ListIndex)
  205.       iRet = VBSetDefPrinter(sTemp)
  206.       If iRet <> True Then MsgBox "Error setting default printer", 48, "Error"
  207.       Timer1_Timer
  208.     Case 1
  209.       If lstPrinters.ListIndex = True Then Exit Sub
  210.       sTemp = lstPrinters.List(lstPrinters.ListIndex)
  211.       iMode = DM_OUT_BUFFER Or DM_IN_PROMPT
  212.       If chkPerm.Value <> 0 Then iMode = iMode Or DM_OUT_DEFAULT
  213.       If chkDefault.Value = 0 Then iMode = iMode Or DM_IN_BUFFER
  214.       sTemp2 = VBDevModeToStr(DeviceData(lstPrinters.ListIndex))
  215.       iRet = VBStrToDevMode(sTemp2, inMode)
  216.       iRet = VBExtDeviceMode(0, sTemp, inMode, DeviceData(lstPrinters.ListIndex), iMode)
  217.     Case 2
  218.       End
  219.   End Select
  220. End Sub
  221. Sub Form_Load ()
  222.   Dim sTemp As String
  223.   Dim inMode As DEVMODE_TYPE
  224.   Dim iRet As Integer
  225.   Me.Left = screen.Width / 2 - Me.Width / 2
  226.   Me.Top = screen.Height / 2 - Me.Height / 2
  227.   sTemp = VBGetPrinters()
  228.   While sTemp <> ""
  229.     ReDim Preserve DeviceData(lstPrinters.ListCount)
  230.     iRet = VBExtDeviceMode(0, sTemp, inMode, DeviceData(lstPrinters.ListCount), DM_OUT_BUFFER)
  231.     If iRet = 1 Then lstPrinters.AddItem sTemp
  232.     sTemp = VBGetPrinters()
  233.   Wend
  234.   lstPrinters.ListIndex = 0
  235.   lstPrinters_Click
  236.   Timer1_Timer
  237. End Sub
  238. Sub lstPrinters_Click ()
  239.   ShowOptions lstPrinters.List(lstPrinters.ListIndex) + ""
  240. End Sub
  241. Sub ShowOptions (sPrinter As String)
  242.   Dim resList() As ENUMRESOLUTIONS_TYPE
  243.   Dim binNameList() As BINNAMES_TYPE
  244.   Dim binNumList() As Integer
  245.   Dim papNameList() As PAPERNAMES_TYPE
  246.   Dim papSizeList() As PAPERSIZE_TYPE
  247.   Dim lRet As Long
  248.   Dim inDev As DEVMODE_TYPE
  249.   Dim iCounter As Integer
  250.   ' Step 1, find out how many paper sizes/names there are
  251.   lRet = VBDeviceCapabilities(sPrinter, DC_PAPERSIZE, ByVal 0&, inDev)
  252.   If lRet = 0 Then Exit Sub
  253.   ' Size our arrays accordingly
  254.   ReDim papSizeList(lRet - 1) As PAPERSIZE_TYPE
  255.   ReDim papNameList(lRet - 1) As PAPERNAMES_TYPE
  256.   papNameList(0).sName = "Test1"
  257.   papNameList(1).sName = "Test2"
  258.   ' Get the actual names of the available papers and their sizes
  259.   lRet = VBDeviceCapabilities(sPrinter, DC_PAPERNAMES, papNameList(0), inDev)
  260.   lRet = VBDeviceCapabilities(sPrinter, DC_PAPERSIZE, papSizeList(0), inDev)
  261.   ' Display the available paper types in a list
  262.   ' Note the papSizeList() is just for demonstration
  263.   ' purposes, I don't use it here but you may want to use
  264.   ' it for reference purposes.
  265.   lstPapers.Clear
  266.   For iCounter = 0 To lRet - 1
  267.     lstPapers.AddItem Trim$(papNameList(iCounter).sName)
  268.   Next
  269.   ' Same procedure for the available printer bins
  270.   lRet = VBDeviceCapabilities(sPrinter, DC_BINNAMES, ByVal 0&, inDev)
  271.   If lRet = 0 Then Exit Sub
  272.   ReDim binNameList(lRet - 1) As BINNAMES_TYPE
  273.   ReDim binNumList(lRet - 1) As Integer
  274.   lRet = VBDeviceCapabilities(sPrinter, DC_BINS, binNumList(0), inDev)
  275.   lRet = VBDeviceCapabilities(sPrinter, DC_BINNAMES, binNameList(0), inDev)
  276.   lstBins.Clear
  277.   For iCounter = 0 To lRet - 1
  278.     lstBins.AddItem Trim$(binNameList(iCounter).sName)
  279.   Next
  280.   lRet = VBDeviceCapabilities(sPrinter, DC_ENUMRESOLUTIONS, ByVal 0&, inDev)
  281.   If lRet = 0 Then Exit Sub
  282.   ReDim resList(lRet - 1) As ENUMRESOLUTIONS_TYPE
  283.   lRet = VBDeviceCapabilities(sPrinter, DC_ENUMRESOLUTIONS, resList(0), inDev)
  284.   lstRes.Clear
  285.   For iCounter = 0 To lRet - 1
  286.     lstRes.AddItem Format$(resList(iCounter).xdpi, "#") + " x " + Format$(resList(iCounter).ydpi, "#")
  287.   Next
  288. End Sub
  289. Sub Timer1_Timer ()
  290.   Dim sTemp As String
  291.   sTemp = VBGetDefPrinter()
  292.   lblDefault.Caption = sTemp
  293.   lblDefDriver = VBGetDriverFromName(sTemp)
  294. End Sub
  295.