就是当用户选择打印命令时,程序调用通用对话框的ShowPrinter方法显示一打印对话框供用户修改打印机的设置(比如纸张大小,打印方向,打印页码范围等)。如果我在程序代码自动修改Printer对象的copies或Orientation属性后再次显示打印对话框供用户修改上述设置返回后就再也无法检测所做的修改甚至连已选择了其他的打印机也无法检测。在Win2000中代码即使不修改上述属性也无法检测(只能检测到改变了默认打印机),如果修改了上述属性也和Win98一样,其他属性没有测试(ScalMode不会)。盼高手指点。

解决方案 »

  1.   

    您说的是在控制面板中修改打印设置吗?如果是这样的话我们的客户会不满意的。如果不是的话是调用API吗?请问需要那些API函数,我已试过在显示对话框后再调用下列代码,但又有新的问题。在Win98中无法修改打印质量和检测拷贝的份数。盼赐教!
        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
      

  2.   

    二位能否说得详细点,需要那些API。打印前设置怎样设置。我的主要目的是为避免用户在打印对话框中的错误设置带来的误操作影响工作效率谢谢您们的热情参与。