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

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "PSETUP.DLL DEMO"
  4.    ClientHeight    =   1575
  5.    ClientLeft      =   345
  6.    ClientTop       =   1935
  7.    ClientWidth     =   7140
  8.    Height          =   2265
  9.    Left            =   285
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   1575
  13.    ScaleWidth      =   7140
  14.    Top             =   1305
  15.    Width           =   7260
  16.    Begin Menu FileMNU 
  17.       Caption         =   "&File"
  18.       Begin Menu PSetupMNU 
  19.          Caption         =   "Printer &Setup"
  20.       End
  21.       Begin Menu ExitMNU 
  22.          Caption         =   "E&xit"
  23.       End
  24.    End
  25. ' We use GetProfileString to retrieve the current Printer Driver's Name and output port (e.g. LPT1:)
  26. Declare Function GetProfileString Lib "KERNEL" (ByVal App$, ByVal Keyname$, ByVal DefaultVal$, ByVal RetBuf$, ByVal Size%) As Integer
  27. ' PSETUP.DLL has only one function: DoPrinterSetup which invokes the Windows 3.0 standard
  28. ' Printer Setup Dialog.  It expects three parameters: the calling form's hWnd handle,
  29. ' the name of the printer driver, and the ouptut port. The function returns true if the
  30. ' Printer Setup dialog was implemented and false if it wasn't, but in most cases you won't
  31. ' need to check the return value.
  32. Declare Function DoPrinterSetup Lib "PSETUP.DLL" (ByVal hwnd%, ByVal DriverName$, ByVal PortName$) As Integer
  33. Const true = -1
  34. Const false = 0
  35. Sub ExitMNU_Click ()
  36.  ' Bye
  37. End Sub
  38. Sub PSetupMNU_Click ()
  39.  ' Prepare a long enough ASCIIZ Return Buffer
  40.  RetStr$ = String$(256, 0)
  41.  RetStrSize% = Len(RetStr$)
  42.  ' The info we need is in the [windows] section, under "device"
  43.  x% = GetProfileString("windows", "device", "", RetStr$, RetStrSize%)
  44.  ' Parse the RetStr$ to the components that interest us.
  45.  i% = InStr(RetStr$, ",")
  46.  If i% > 0 Then
  47.     a$ = Left$(RetStr$, i% - 1)
  48.     b$ = Right$(RetStr$, Len(RetStr$) - i%)
  49.     j% = InStr(b$, ",")
  50.     If j% > 0 Then
  51.         DriverName$ = Left$(b$, j% - 1)
  52.         PortName$ = Right$(b$, Len(b$) - j%)
  53.     End If
  54.  End If
  55.  ' Call DoPrinterSetup sending it the Form's handle, the printer driver name, and port.
  56.  ' Note: Do not add the extension "drv" to DriverName$. PSETUP.DLL does it for you.
  57.  r% = DoPrinterSetup(Form1.hwnd, DriverName$, PortName$)
  58.  If Not r% Then MsgBox "Can't run Printer Setup" + Chr$(13) + Chr$(10) + "Please check your installation", 64, "Printer Setup"
  59. End Sub
  60.