如何在vb程序中设置纸张来源

Tadpole0510 2004-08-23 06:15:18
在win2000中 打印机-》属性-》常规-》打印首选项-》纸张/质量--纸张来源
...全文
120 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Tadpole0510 2004-08-24
没有实现啊,怎么样才能解决?
回复
Tadpole0510 2004-08-23
Public Const DMBIN_MANUAL = 4
Public Const DMBIN_LOWER = 2
Public Const DMBIN_MIDDLE = 3
Public Const DMBIN_ONLYONE = 1
Public Const DMBIN_SMALLFMT = 9
Public Const DMBIN_TRACTOR = 8
其中 DMBIN_TRACTOR 是我需要的,
但是运行后打开 打印机-》属性-》常规-》打印首选项-》纸张/质量--纸张来源,
纸张来源设置还是没有变!!!
回复
Tadpole0510 2004-08-23
to :rainstormmaster(暴风雨 v2.0)
你的纸张来源和我的纸张来源意义不一样
你选择的是纸张型号来源比如A4
我要求的是自动,手动,牵引送纸

设置后就不要变了
回复
RUKYO 2004-08-23
关注
回复
Tadpole0510 2004-08-23
我先看看,感谢先
回复
rainstormmaster 2004-08-23
上面的代码封装了一个函数:
Function ResetPrinterDC(PrinterName As String, hPrtDc As Long, _
PaperSource As Long, PaperOrient As Long) As Boolean

其中PaperSource 即为纸张来源
回复
rainstormmaster 2004-08-23
用以下代码看看:(源自MSDN)
Example to Change Page Settings During a Print Job
Create a Standard EXE Project. Form1 is created by default.

Add a CommandButton to Form1, and paste the following code into the form's Declaration section:
Option Explicit
' Constants for DEVMODE.
Private Const CCHDEVICENAME = 32
Private Const CCHFORMNAME = 32
' Constants for DocumentProperties() call.
Private Const DM_MODIFY = 8
Private Const DM_IN_BUFFER = DM_MODIFY
Private Const DM_COPY = 2
Private Const DM_OUT_BUFFER = DM_COPY
' Constants for Orientation.
Private Const DMORIENT_PORTRAIT = 1
Private Const DMORIENT_LANDSCAPE = 2
' Constants for printer bin.
Private Const DMBIN_UPPER = 1
Private Const DMBIN_LOWER = 2
' Constants for DMFIELDS (which fields did you change?).
Private Const DM_ORIENTATION = &H1
Private Const DM_DEFAULTSOURCE = &H200
Private Type DOCINFO
cbSize As Long
lpszDocName As String
lpszOutput As String
End Type
Private Type DEVMODE
dmDeviceName(1 To CCHDEVICENAME) As Byte
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName(1 To CCHFORMNAME) As Byte
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As _
Long, ByVal pDefault As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Declare Function DocumentProperties Lib "winspool.drv" _
Alias "DocumentPropertiesA" (ByVal hwnd As Long, _
ByVal hPrinter As Long, ByVal pDeviceName As String, _
pDevModeOutput As Any, pDevModeInput As Any, _
ByVal fMode As Long) As Long
Private Declare Function ResetDC Lib "gdi32" Alias "ResetDCA" _
(ByVal hdc As Long, lpInitData As Any) As Long
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" _
(ByVal lpDriverName As String, ByVal lpDeviceName As String, _
ByVal lpOutput As Long, ByVal lpInitData As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) _
As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" _
(ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, _
ByVal lpString As String, ByVal nCount As Long) As Boolean
Private Declare Function StartDoc Lib "gdi32" Alias "StartDocA" _
(ByVal hdc As Long, lpdi As DOCINFO) As Long
Private Declare Function StartPage Lib "gdi32" (ByVal hdc As Long) _
As Long
Private Declare Function EndDoc Lib "gdi32" (ByVal hdc As Long) _
As Long
Private Declare Function EndPage Lib "gdi32" (ByVal hdc As Long) _
As Long
Private Declare Function GetLastError Lib "KERNEL32" () As Long
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" _
(hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Function ResetPrinterDC(PrinterName As String, hPrtDc As Long, _
PaperSource As Long, PaperOrient As Long) As Boolean
Dim nSize As Long ' Size of DEVMODE
Dim pDevMode As DEVMODE
Dim PrinterHandle As Long ' handle to printer
Dim LastError As Long ' return value for GetLastError
Dim aDevMode() As Byte ' working DEVMODE
' Get a handle to the printer.
If OpenPrinter(PrinterName, PrinterHandle, 0&) Then
nSize = DocumentProperties(Me.hwnd, 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(Me.hwnd, PrinterHandle, _
PrinterName, aDevMode(1), 0&, DM_OUT_BUFFER)
' Copy the predefined portion of the DEVMODE.
Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode))
' Change the appropriate member in the DevMode.
' In this case, you want to change the paper bin and
' orientation.
pDevMode.dmDefaultSource = PaperSource
pDevMode.dmOrientation = PaperOrient
' Set the dmFields bit flag to indicate what you're changing.
pDevMode.dmFields = pDevMode.dmFields Or DM_DEFAULTSOURCE _
Or DM_ORIENTATION
' Copy your changes back, then update DEVMODE.
Call CopyMemory(aDevMode(1), pDevMode, Len(pDevMode))
nSize = DocumentProperties(Me.hwnd, PrinterHandle, _
PrinterName, aDevMode(1), aDevMode(1), _
DM_IN_BUFFER Or DM_OUT_BUFFER)
nSize = ResetDC(hPrtDc, aDevMode(1)) ' Reset the DEVMODE
' Close the handle when you're done with it.
ClosePrinter (PrinterHandle)
ResetPrinterDC = True ' Reset succeeded!
Else
ResetPrinterDC = False ' Reset failed!
LastError = GetLastError()
MsgBox "Error changing Page settings. Error Code: " _
& LastError, vbExclamation, "Print Error"
End If
End Function
Private Sub Command1_Click()
Dim di As DOCINFO
Dim hPrintDc As Long
Dim Ret As Long
Dim LastError As Long
Dim tx$
tx$ = "Hello World!"
hPrintDc = CreateDC(Printer.DriverName, Printer.DeviceName, 0, 0)
di.cbSize = Len(di) ' 20
di.lpszDocName = "VB Test Document" ' Optional
' Initialize page settings.
Ret = ResetPrinterDC(Printer.DeviceName, hPrintDc, _
DMBIN_UPPER, DMORIENT_PORTRAIT)
Ret = StartDoc(hPrintDc, di)
Ret = StartPage(hPrintDc)
Ret = TextOut(hPrintDc, 1000, 1000, tx$, Len(tx$))
Ret = EndPage(hPrintDc)
' Change page settings.
Ret = ResetPrinterDC(Printer.DeviceName, hPrintDc, _
DMBIN_LOWER, DMORIENT_LANDSCAPE)
Ret = StartPage(hPrintDc)
Ret = TextOut(hPrintDc, 1000, 1000, tx$, Len(tx$))
Ret = EndPage(hPrintDc)
Ret = EndDoc(hPrintDc)
Ret = DeleteDC(hPrintDc)
End Sub
Make sure that the printer orientation is set to Portrait and the paper source is set to Upper Tray or AutoSelect. Then run the Project and click on Command1.
If your printer has both an upper and a lower paper tray and supports both orientations, this will print the first page to the upper tray in Portrait and then a second page from the lower tray in Landscape.
回复
tmkwind 2004-08-23
up
回复
Tadpole0510 2004-08-23
大家给鼎鼎啊
回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2004-08-23 06:15
社区公告
暂无公告