Results 1 to 3 of 3

Thread: Print Dialog Pointer without Opening? HELP!!!

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Question Print Dialog Pointer without Opening? HELP!!!

    I'm working with another app's API and I need to provide a pointer to the Print Dialog Box.

    It's easy to do once I open it and then a User closes it.

    The problem is that I'd like to provide the pointer without having User interaction.
    I would prefer to never open the PrintDialog window at all, however, if I can open it and then immediately close it (with 'Print') that might work.

    Here's the details -
    1) I'm creating an automated app.
    2) I set all the printing parameters using DEVMODE and a PrintDialog object.
    3) Then, I need to hand over the pointer which apparently doesn't exist until the PrintDialog is opened, then closed (with 'Print').

    Here's some of the code (just for example, may be incomplete):
    Code:
        Private Declare Function PrtDialog Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As PRINTDLG) As Long
    
        Dim pd As PRINTDLG
        Dim ptrpd As Long       'Pointer to a printDlg structure
        Dim whDevMode As DEVMODE
        Dim whDevNames As DEVNAMES
        Dim lpDevMode As Long, lpDevName As Long
        Dim tmpPrinter As Printer
        Dim selectedPrinterName As String
    
        selectedPrinterName = "Adobe PDF"
    
        For Each tmpPrinter In Printers
            If tmpPrinter.DeviceName = selectedPrinterName Then
                Exit For
            End If
        Next tmpPrinter
    
        With whDevMode
            .dmSize = Len(whDevMode)
            .dmFields = DM_ORIENTATION Or DM_DUPLEX Or DM_PAPERSIZE Or DM_COLOR Or DM_SCALE
            .dmDeviceName = tmpPrinter.DeviceName
            .dmOrientation = DMORIENT_LANDSCAPE
            .dmCopies = 1
            .dmPaperSize = DMPAPER_TABLOID
        End With
    
        'Allocate memory for the initialization hDevMode structure
        'and copy the settings gathered above into this memory
        pd.hDevMode = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(whDevMode))
        lpDevMode = GlobalLock(pd.hDevMode)
        If lpDevMode > 0 Then
            CopyMemory ByVal lpDevMode, whDevMode, Len(whDevMode)
            bReturn = GlobalUnlock(pd.hDevMode)
        End If
    
        'Set the current driver, device, and port name strings
        With whDevNames
            .wDriverOffset = 8
            .wDeviceOffset = .wDriverOffset + 1 + Len(tmpPrinter.DriverName)
            .wOutputOffset = .wDeviceOffset + 1 + Len(tmpPrinter.Port)
            .wDefault = 0
            .Extra = tmpPrinter.DriverName & Chr(0) & tmpPrinter.DeviceName & Chr(0) & tmpPrinter.Port & Chr(0)
        End With
    
        'Allocate memory for the initial hDevName structure
        'and copy the settings gathered above into this memory
        pd.hDevNames = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(whDevNames))
        lpDevName = GlobalLock(pd.hDevNames)
        If lpDevName > 0 Then
            CopyMemory ByVal lpDevName, whDevNames, Len(whDevNames)
            bReturn = GlobalUnlock(lpDevName)
        End If
    
            With pd
                .lStructSize = 66
                .hwndOwner = Me.hWnd
                .hDC = 0
                .Flags = PD_RETURNDC Or PD_RETURNIC Or PD_PAGENUMS Or PD_USEDEVMODECOPIES
                .nFromPage = chunks(j)
                .nToPage = chunks(j)
                .nMinPage = 1
                .nMaxPage = 999
                .nCopies = 1
                .hInstance = 0
                .lCustData = 0
                .lpfnPrintHook = 0
                .lpfnSetupHook = 0
                .lpPrintTemplateName = 0
                .lpSetupTemplateName = 0
                .hPrintTemplate = 0
                .hSetupTemplate = 0
            End With
    
    
            '**************************************************
            '     Here's the problem.
            '     I need the pointer to the PrintDialog, which doesn't exist until after the print
            '     dialog is shown and a user clicks 'print'.
            '     I need to be able to print without any user intervention.
            '     So, how can you get the pointer without opening the Printdialog window?
            '
    
           'This opens the Dialog
            If (PrtDialog(pd) = 0) Then
                MsgBox "Error... Unable to initialize printer "
                Exit Sub
            End If
        
            'grab the pointer 
            ptrpd = AnyPtr(pd)
    
           '***************
           'From here the pointer is passed of to the other app's API...
    Thanks.
    Last edited by wayneh; Aug 27th, 2004 at 08:38 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width