Results 1 to 25 of 25

Thread: Very complex issue...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263

    Very complex issue...

    Hi guys, here is one that I have been slamming my head against the wall over for way too long:

    I have a .dll which sets the default printer for the server that it is running on. It then opens an instance of IE and navigates to a page which builds an xml file and saves it. That .asp page then redirects to another .asp page which applies a stylesheet to the aforementioned xml file and finally prints it out to the printer which the user selected.

    When I set the .dll up on COM+, it alters the default printer, instantiates IE, creates the XML, and then hangs.

    When I don't run the .dll in COM+, but instead register the .dll and reference it in my .asp project, it doesn't even get the printer changed.

    Thoughts are appreciated.

  2. #2
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    User intervention isn't always a bad thing, especially when it comes to things like printing. Why change the printer? Maybe the already selected default printer is what the user wants.

    Just my opinion.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263
    Long story made short...the requirement on this product is that the user will not interact with the Printer Settings dialog box. They will simply choose what and where on the web page.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263

    Revisited...

    Well, this has taken a change, and I am lost. I basically have everything wrapped up into a COM+ component. The component builds and saves an html file (which is the output of applying an XSL to the XML).

    The problem, which has to have an answer, is that I need to be able to say where I want the html file to be printed at. Think about this -- we can have a window with .html files in it, and our printer window open at the same time...grab an .html file and drag and drop on the printer we want and windows knows what to do. This leads one to believe that we should be able to accomplish the same thing through API calls. Does anyone have a clue?

    Thanks again for all of your input.

  5. #5
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    How about setting the default printer?

    http://support.microsoft.com/default...;en-us;q266767

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263
    Good thought, but too unstable for our production environment. This application is going to run at the server, so changing the default printer is not an option. I already explored that route.

    Again though, good thought, if it was running from the client's PC, that would work.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263

    I found what I was looking for, but it wasn't what I was looking for...

    I figured out how to emulate a drag and drop of an .html file onto a printer. However, the real problem remains...I don't want the printer settings message box to pop-up. I've seen people post, saying that this can't be done; however, it can.

    You can use the ExecWB function and pass it parameters of (6,6) and it will print with out prompting. I need the best of both worlds, I need to be able to print in automation (without being prompted), to a location which can change on the fly.

    Seems to me that it sucks that I can do A or B, but not A & B.

  8. #8
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    j - quick question for you: If I could show you how to show the printer dialog box, and change anything you want (programatically, of course) would this be an option for you?

    Let me know. If it is I'll go ahead and make a sample project for you.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263
    Could I close out the dialog box when I was finished with it?

  10. #10
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Yea, of course.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263

    THAT WOULD BE AWESOME!!!!!

    See subject line.

  12. #12
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Working on the project. Gimme a little time.

  13. #13
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631

    Couple of questions.

    Is the printer always the same name?

    Do all the servers have the same # of printers installed?

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263
    No, the printer will vary. I will always have the printer name. This will be running in a COM+ object on a server, so, it will not necessarily always have the same number of printers installed. The number might change

  15. #15
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Hope this works for you. Just change the printer name in the module.
    Attached Files Attached Files
    Please rate my post.

  16. #16
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    I'm guessing this didn't help. I have another option for you if not.
    Please rate my post.

  17. #17
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Try installing this control:

    http://support.microsoft.com/default...b;en-us;322710

    Run this code with the module from the other posted project.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub cmdShowPrinter_Click()
    4.  
    5.    
    6.     'Means our changes won't be set as default system-wide
    7.     'cmnPrinter.PrinterDefault = False
    8.    
    9.     'set an API timer - this will allow an event to be raised even though
    10.     'the printer dialog box will have complete control over our thread
    11.     'Call timeSetEvent(500, 100, AddressOf TimerProc, 0, TIME_ONESHOT)
    12.     'Wait half a second, with a resolution of 100.
    13.     'Call functin TimerProc, no user-data being
    14.     'passed, and call it only once.
    15.            
    16.     'show our printer selection dialog box
    17.     'cmnPrinter.ShowPrinter
    18.    
    19.    
    20.     Dim printDlg As PrinterDlg
    21.     Set printDlg = New PrinterDlg
    22.     ' Set the starting information for the dialog box based on the current
    23.     ' printer settings.
    24.     printDlg.PrinterName = Printer.DeviceName
    25.     printDlg.DriverName = Printer.DriverName
    26.     printDlg.Port = Printer.Port
    27.    
    28.     ' Set the default PaperBin so that a valid value is returned even
    29.     ' in the Cancel case.
    30.     printDlg.PaperBin = Printer.PaperBin
    31.    
    32.     ' Set the flags for the PrinterDlg object using the same flags as in the
    33.     ' common dialog control. The structure starts with VBPrinterConstants.
    34.     printDlg.Flags = VBPrinterConstants.cdlPDNoSelection _
    35.                      Or VBPrinterConstants.cdlPDNoPageNums _
    36.                      Or VBPrinterConstants.cdlPDReturnDC
    37.     Printer.TrackDefault = False
    38.    
    39.     ' When CancelError is set to True the ShowPrinterDlg will return error
    40.     ' 32755. You can handle the error to know when the Cancel button was
    41.     ' clicked. Enable this by uncommenting the lines prefixed with "'**".
    42.     '**printDlg.CancelError = True
    43.    
    44.     ' Add error handling for Cancel.
    45.     '**On Error GoTo Cancel
    46.    
    47.     Call timeSetEvent(500, 100, AddressOf TimerProc, 0, TIME_ONESHOT)
    48.     If Not printDlg.ShowPrinter(Me.hwnd) Then
    49.         Debug.Print "Cancel Selected"
    50.         Exit Sub
    51.     End If
    52.    
    53.     'Turn off Error Handling for Cancel.
    54.     '**On Error GoTo 0
    55.     Dim NewPrinterName As String
    56.     Dim objPrinter As Printer
    57.     Dim strsetting As String
    58.    
    59.     ' Locate the printer that the user selected in the Printers collection.
    60.     NewPrinterName = UCase$(printDlg.PrinterName)
    61.     If Printer.DeviceName <> NewPrinterName Then
    62.         For Each objPrinter In Printers
    63.            If UCase$(objPrinter.DeviceName) = NewPrinterName Then
    64.                 Set Printer = objPrinter
    65.                 Set objPrinter = Nothing
    66.            End If
    67.         Next
    68.     End If
    69.    
    70.     Debug.Print Printer.DeviceName
    71.     Debug.Print Printer.hDC
    72.    
    73. End Sub
    Please rate my post.

  18. #18
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Never thought about going about it like this. After you set the printer object you can reference the printer as you normally would.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  
    5.     Dim objPrinter As Printer
    6.     For Each objPrinter In Printers
    7.         With objPrinter
    8.             If .DeviceName = "Your Printer's Name" Then
    9.                
    10.                 Set Printer = objPrinter
    11.                 Debug.Print Printer.DeviceName
    12.                 Debug.Print "     " & Printer.hDC
    13.                
    14.             End If
    15.         End With
    16.     Next objPrinter
    17.    
    18.     Unload Me
    19.    
    20. End Sub
    Please rate my post.

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263

    The missing link...

    O.K, I think we are getting somewhere, and I hope we don't dead-end now. So, when I go to print my document, the system produces a print dialog box (I don't). How do I get a handle on it?

    Something I tried:

    dim prnDialog as PrinterDlg
    dim sws as new ShellWindows

    for each prnDialog in sws 'there should only be one

    next

    I registered the prndialog.dll and setup a project reference, then in code right after the print dialog box is raised by the system, the code that runs is the for loop above. The problem now, is that I can't even get into the for loop, I get a "Type Mismatch" error pointing to the for line.

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263

    Hokey - Pokey...

    O.K., we're getting somewhere...I think. I can get a handle on the printer dialog box with the GetForegroundWindow() call. Does anyone know how I can set my printer dialog reference equal to the returned handle?

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263

    Please redirect...

    I have been building off of this post onto a different post which seems to address the direction I was going here. Please read this post to continue to assist.

    Thanks!

  22. #22
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    jewell I thought you were trying to print a document with a specific printer that you'd have the name of. I thought I'd answered your question but I guess not - what exactly are you trying to do now?
    Please rate my post.

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263
    If you read my post (which is two above yours on this thread), you will understand what I was trying to do.

  24. #24
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    That's not going to be possible jewell.
    Please rate my post.

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263

    If it's not possible then how...

    ...does Crystal expose the properties of the printer settings to us programatically to manipulate? The report is going to run in a web browser, in order to render the report, and then the print is kicked off from ie -- but Crystal can alter the print settings at that point in time.

    Why can't we do the same?

    [Pseudocode]

    dim prnDlg as PrinterDlg

    set prnDlg = the printer dialog that ie opened
    [/Pseudocode]

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