VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

How To Print Using Custom Page Sizes on Windows NT and Windows 2000

Rishi Pandey  (1 Submission)   Miscellaneous   Visual Basic 3.0   Unknown Difficulty   Sat 10th December 2005   Mon 8th February 2021

How To Print Using Custom Page Sizes on Windows NT and Windows 2000

API Declarations


'1. Set a local printer as the default printer. To do this, follow these 'steps:a. On the Start menu, point to Settings, and then click Printers.
'b. Right-click the icon for a local printer, and then click Set as default.

'2. Start a new Standard EXE project in Visual Basic. Form1 is created by 'default.
'3. Add three CommandButtons and a ListBox control to Form1.

Private Sub Command1_Click()
Dim FormName As String

FormName = "MyCustomForm" ' Use special, user-defined form.
UseForm FormName
End Sub

Private Sub Command2_Click()
Dim FormName As String

' Get FormName from the ListBox.
On Error GoTo ListBoxERR ' Trap for no selection.
FormName = Mid(List1.Text, 1, InStr(1, List1.Text, " -") - 1)
On Error GoTo 0 ' Turn off Error trap.

UseForm FormName

Exit Sub
ListBoxERR:
MsgBox "Select a printer from the ListBox before using this option.", _
vbExclamation
End Sub

Private Sub Command3_Click()
Dim RetVal As Long
Dim PrinterHandle As Long ' Handle to printer
Dim PrinterName As String
Dim FormName As String
Dim Continue As Long

' Delete form that is selected in ListBox.
PrinterName = Printer.DeviceName ' Current printer
If OpenPrinter(PrinterName, PrinterHandle, 0&) Then

On Error GoTo ListBoxERR ' Trap for no selection.
FormName = Mid(List1.Text, 1, InStr(1, List1.Text, " -") - 1)
On Error GoTo 0 ' Turn off Error trap.

Continue = MsgBox("Are you sure you want to permanently remove " & _
FormName & " from " & PrinterName & "?", vbYesNo)
If Continue = vbYes Then
RetVal = DeleteForm(PrinterHandle, FormName & Chr(0))
If RetVal <> 0 Then ' DeleteForm succeeded.
List1.Clear ' Reflect the deletion in the ListBox.
Form_Load ' Rebuild the list.
MsgBox FormName & " deleted!", vbInformation, "Success!"
Else
MsgBox FormName & " not deleted!" & vbCrLf & vbCrLf & _
"Error code: " & Err.LastDllError, vbInformation, "Failure!"
End If
End If
ClosePrinter (PrinterHandle)
End If

Exit Sub
ListBoxERR:
MsgBox "Select a printer from the ListBox before using this option.", _
vbExclamation
ClosePrinter (PrinterHandle)
End Sub

Private Sub Form_Load()
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 BytesNeeded As Long
Dim PrinterName As String ' Current printer
Dim PrinterHandle As Long ' Handle to printer
Dim FormItem As String ' For ListBox
Dim RetVal As Long
Dim FormSize As SIZEL ' Size of desired form

PrinterName = Printer.DeviceName ' Current printer
If OpenPrinter(PrinterName, PrinterHandle, 0&) Then
With FormSize ' Desired page size
.cx = 214000
.cy = 216000
End With
ReDim aFI1(1)
RetVal = EnumForms(PrinterHandle, 1, aFI1(0), 0&, BytesNeeded, _
NumForms)
ReDim Temp(BytesNeeded)
ReDim aFI1(BytesNeeded / Len(FI1))
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)
' List name and size including the count (index).
FormItem = PtrCtoVbString(.pName) & " - " & .Size.cx / 1000 & _
" mm X " & .Size.cy / 1000 & " mm (" & I + 1 & ")"
List1.AddItem FormItem
End With
Next I
ClosePrinter (PrinterHandle)
End If
End Sub

Private Sub UseForm(FormName As String)
Dim RetVal As Integer

RetVal = SelectForm(FormName, Me.hwnd)
Select Case RetVal
Case FORM_NOT_SELECTED ' 0
' Selection failed!
MsgBox "Unable to retrieve From name", vbExclamation, _
"Operation halted!"
Case FORM_SELECTED ' 1
' Selection succeeded!
PrintTest ' Comment this line to avoid printing
Case FORM_ADDED ' 2
' Form added and selected.
List1.Clear ' Reflect the addition in the ListBox
Form_Load ' by rebuilding the list.
End Select
End Sub



Rate How To Print Using Custom Page Sizes on Windows NT and Windows 2000 (1(1 Vote))
How To Print Using Custom Page Sizes on Windows NT and Windows 2000.bas

How To Print Using Custom Page Sizes on Windows NT and Windows 2000 Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters