home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / vbprnt20.zip / VB4 / VBPRNT32.FRM < prev   
Text File  |  1996-05-31  |  12KB  |  369 lines

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