DefaultPriority As Long StartTime As Long UntilTime As Long Status As Long cJobs As Long AveragePPM As Long End Type Public Function GetFormName(ByVal PrinterHandle As Long, _ FormSize As SIZEL, FormName As String) As Integer Dim NumForms As Long, I As Long Dim FI1 As FORM_INFO_1 Dim aFI1() As FORM_INFO_1 ' Working FI1 array Dim Temp() As Byte ' Temp FI1 array Dim FormIndex As Integer Dim BytesNeeded As Long Dim RetVal As Long FormName = vbNullString FormIndex = 0 ReDim aFI1(1) ' First call retrieves the BytesNeeded. RetVal = EnumForms(PrinterHandle, 1, aFI1(0), 0&, BytesNeeded, NumForms) ReDim Temp(BytesNeeded) ReDim aFI1(BytesNeeded / Len(FI1)) ' Second call actually enumerates the supported forms. RetVal = EnumForms(PrinterHandle, 1, Temp(0), BytesNeeded, BytesNeeded, _ NumForms) Call CopyMemory(aFI1(0), Temp(0), BytesNeeded) For I = 0 To NumForms - 1 With aFI1(I) If .Size.cx = FormSize.cx And .Size.cy = FormSize.cy Then ' Found the desired form FormName = PtrCtoVbString(.pName) FormIndex = I + 1 Exit For End If End With Next I GetFormName = FormIndex ' Returns non-zero when form is found. End Function Public Function AddNewForm(PrinterHandle As Long, FormSize As SIZEL, _ FormName As String) As String Dim FI1 As sFORM_INFO_1 Dim aFI1() As Byte Dim RetVal As Long With FI1 .Flags = 0 .pName = FormName With .Size .cx = FormSize.cx .cy = FormSize.cy End With With .ImageableArea .Left = 0 .Top = 0 .Right = FI1.Size.cx .Bottom = FI1.Size.cy End With End With ReDim aFI1(Len(FI1)) Call CopyMemory(aFI1(0), FI1, Len(FI1)) RetVal = AddForm(PrinterHandle, 1, aFI1(0)) If RetVal = 0 Then If Err.LastDllError = 5 Then MsgBox "You do not have permissions to add a form to " & _ Printer.DeviceName, vbExclamation, "Access Denied!" Else MsgBox "Error: " & Err.LastDllError, "Error Adding Form" End If AddNewForm = "none" Else AddNewForm = FI1.pName End If End Function Public Function PtrCtoVbString(ByVal Add As Long) As String Dim sTemp As String * 512, x As Long x = lstrcpy(sTemp, ByVal Add) If (InStr(1, sTemp, Chr(0)) = 0) Then PtrCtoVbString = "" Else PtrCtoVbString = Left(sTemp, InStr(1, sTemp, Chr(0)) - 1) End If End Function Public Function SelectForm(FormName As String, ByVal MyhWnd As Long) _ As Integer Dim nSize As Long ' Size of DEVMODE Dim pDevMode As DEVMODE Dim PrinterHandle As Long ' Handle to printer Dim hPrtDC As Long ' Handle to Printer DC Dim PrinterName As String Dim aDevMode() As Byte ' Working DEVMODE Dim FormSize As SIZEL PrinterName = Printer.DeviceName ' Current printer hPrtDC = Printer.hdc ' hDC for current Printer SelectForm = FORM_NOT_SELECTED ' Set for failure unless reset in code. ' Get a handle to the printer. If OpenPrinter(PrinterName, PrinterHandle, 0&) Then ' Retrieve the size of the DEVMODE. nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, 0&, _ 0&, 0&) ' Reserve memory for the actual size of the DEVMODE. ReDim aDevMode(1 To nSize) ' Fill the DEVMODE from the printer. nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, _ aDevMode(1), 0&, DM_OUT_BUFFER) ' Copy the Public (predefined) portion of the DEVMODE. Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode)) ' If FormName is "MyCustomForm", we must make sure it exists ' before using it. Otherwise, it came from our EnumForms list, ' and we do not need to check first. Note that we could have ' passed in a Flag instead of checking for a literal name. If FormName = "MyCustomForm" Then ' Use form "MyCustomForm", adding it if necessary. ' Set the desired size of the form needed. With FormSize ' Given in thousandths of millimeters .cx = 214000 ' width .cy = 216000 ' height End With If GetFormName(PrinterHandle, FormSize, FormName) = 0 Then ' Form not found - Either of the next 2 lines will work. 'FormName = AddNewForm(PrinterHandle, FormSize, "MyCustomForm") AddNewForm PrinterHandle, FormSize, "MyCustomForm" If GetFormName(PrinterHandle, FormSize, FormName) = 0 Then ClosePrinter (PrinterHandle) SelectForm = FORM_NOT_SELECTED ' Selection Failed! Exit Function Else SelectForm = FORM_ADDED ' Form Adde