sp; .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" ''''MsgBox "Error: " & Err.LastDllError, "Error Adding Form" End If AddNewForm = "none" Else AddNewForm = FI1.pName End If End Function Public Sub PrintTest() '''' Print two test pages to confirm the page size. Printer.Print "Top of Page 1." Printer.NewPage '''' Spacing between lines should reflect the chosen page height. Printer.Print "Top of Page 2. - Check the page Height (Length.)" Printer.EndDoc MsgBox "Check Printer " & Printer.DeviceName, vbInformation, "Done!" End Sub 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 IsNtOs() As Boolean Dim ver As OSVERSIONINFO ver.dwOSVersionInfoSize = 148 GetVersionEx ver With ver Select Case .dwPlatformId Case 0, 1 IsNtOs = False Case 2 IsNtOs = True End Select End With End Function Public Function UseForm(FormName As String, sHwnd As Long) As Integer Dim RetVal As Integer Dim FormSize As SIZEL '''' Size of desired form RetVal = SelectForm(FormName, sHwnd) ''''选择纸张类型 UseForm = RetVal Select Case RetVal Case FORM_NOT_SELECTED '''' 0 '''' 选择纸张失败! ''''MsgBox "Unable to retrieve From name", vbExclamation, _ ''''"Operation halted!" Case FORM_SELECTED '''' 1 '''' 选择成功! ''''PrintTest '''' Comment this line to avoid printing Case FORM_ADDED '''' 2 '''' 添加并选择成功. ''''PrintTest '''' Comment this line to avoid printing End Select End Function''''调用,在Form1上放置Command1、Command2,复制下列代码: Option Explicit Private Sub Command1_Click() Dim FormName As String, RetValue As Integer ''''自定义打印纸张 FormName = "广东省发票" RetValue = UseForm(FormName, Me.hwnd) ''''If RetValue = 0 Then GoTo errPrint PrintTest End Sub Private Sub Command2_Click() Dim FormName As String, RetValue As Integer ''''自定义打印纸张 FormName = "80列报表" RetValue = UseForm(FormName, Me.hwnd) ''''If RetValue = 0 Then GoTo errPrint PrintTest End Sub Private Sub Form_Load() Command1.Caption = "打印发票" Command2.Caption = "打印报表" End Sub
上一页 [1] [2] [3] |