就是当用户选择打印命令时,程序调用通用对话框的ShowPrinter方法显示一打印对话框供用户修改打印机的设置(比如纸张大小,打印方向,打印页码范围等)。如果我在程序代码自动修改Printer对象的copies或Orientation属性后再次显示打印对话框供用户修改上述设置返回后就再也无法检测所做的修改甚至连已选择了其他的打印机也无法检测。在Win2000中代码即使不修改上述属性也无法检测(只能检测到改变了默认打印机),如果修改了上述属性也和Win98一样,其他属性没有测试(ScalMode不会)。盼高手指点。
解决方案 »
- 自己写的ActiveX控件在窗体中使用时,经常出现“对象"XXX"的方法"_YYY"失败”的错误,怎么回事?
- 应用ADO的问题:SSTAB与fpSpread的关系
- 请问:使用ADODB对象编程后,如何使用DataGrid控件与ADODB数据库连接呢?
- 子程序写在哪里?
- 如何使窗口的最大化按钮灰化
- 这个程序为什么没有效果?
- 请问我的listview为何只显示一列呢?
- 谁能给出一个VB实现的给一段数据数字签名的代码?
- 我的应用程序中为什么一个简单的对话框,在关闭的时候就会有一片空白的显现?
- !!!急死了!!!关于vb6中打印的问题!望各位高手不吝赐教!
- 谁知道安装ado25都需要那些支持文件
- 关于播放AVI的问题...
Dim PrinterHandle As Long
Dim PrinterName As String
Dim pd As PRINTER_DEFAULTS
Dim MyDevMode As DEVMODE_TYPE
Dim Result As Long
Dim Needed As Long
Dim pFullDevMode As Long
Dim pi2_buffer() As Long 'This is a block of memory for the Printer_Info_2 structure
'If you need to use the Printer_Info_2 User Defined Type, the
' definition of Printer_Info_2 in the API viewer is incorrect.
' pDevMode and pSecurityDescriptor should be defined As Long.
PrinterName = Printer.DeviceName
If PrinterName = "" Then
Exit Sub
End If
pd.pDatatype = vbNullString
pd.pDevMode = 0&
'Printer_Access_All is required for NT security
pd.DesiredAccess = PRINTER_ALL_ACCESS
Result = OpenPrinter(PrinterName, PrinterHandle, pd)
'The first call to GetPrinter gets the size, in bytes, of the buffer needed.
'This value is divided by 4 since each element of pi2_buffer is a long.
Result = GetPrinter(PrinterHandle, 2, ByVal 0&, 0, Needed)
ReDim pi2_buffer((Needed \ 4))
Result = GetPrinter(PrinterHandle, 2, pi2_buffer(0), Needed, Needed)
'The seventh element of pi2_buffer is a Pointer to a block of memory
' which contains the full DevMode (including the PRIVATE portion).
pFullDevMode = pi2_buffer(7)
'Copy the Public portion of FullDevMode into our DevMode structure
Call CopyMemory(MyDevMode, ByVal pFullDevMode, Len(MyDevMode))
'Make desired changes
'On Error Resume Next
With MyDevMode
.dmFields = DM_COLOR Or DM_COPIES Or DM_DUPLEX Or DM_ORIENTATION Or DM_PAPERSIZE Or DM_PRINTQUALITY
.dmColor = Printer.ColorMode
.dmCopies = Printer.Copies
.dmDuplex = Printer.Duplex
.dmOrientation = Printer.Orientation
.dmPaperSize = Printer.PaperSize
.dmPrintQuality = Printer.PrintQuality
End With
On Error GoTo 0
' MyDevMode.dmDuplex = NewSetting
' MyDevMode.dmFields = DM_DUPLEX Or DM_ORIENTATION
' MyDevMode.dmOrientation = chng
'Copy our DevMode structure back into FullDevMode
Call CopyMemory(ByVal pFullDevMode, MyDevMode, Len(MyDevMode))
'Copy our changes to "the PUBLIC portion of the DevMode" into "the PRIVATE portion of the DevMode"
Result = DocumentProperties(frmOwner.hwnd, PrinterHandle, PrinterName, ByVal pFullDevMode, ByVal pFullDevMode, DM_IN_BUFFER Or DM_OUT_BUFFER)
'Update the printer's default properties (to verify, go to the Printer folder
' and check the properties for the printer)
Result = SetPrinter(PrinterHandle, 2, pi2_buffer(0), 0&)
Call ClosePrinter(PrinterHandle)
'Note: Once "Set Printer = " is executed, anywhere in the code, after that point
' changes made with SetPrinter will ONLY affect the system-wide printer --
' -- the changes will NOT affect the VB printer object.
' Therefore, it may be necessary to reset the printer object's parameters to
' those chosen in the devmode.
Dim p As Printer
For Each p In Printers
If p.DeviceName = PrinterName Then
Set Printer = p
Exit For
End If
Next p
End sub