ludy
asked on
Determine when User cancels printing from the FilePrint dialog box
I'm implementing the Word object in a class to print a document. Instead of printing outright, I show the FilePrint dialog box by the code, "objWord.Dialogs(wdDialogF ilePrint). Show", and let the use decided whether to cancel or continue printing.
Now here lies the problem. I want to be able to catch the event (or whatever it is that I could catch) when the user clicks on the cancel button. I couldn't find a way to do this.
I figured the use of Common Dialog box might solve the problem BUT as I am coding a class, I needed to reference commdlg32.dll - and I can't. "Can't add a reference to the specified file" error shows up. I had to drop this.
Is there anyone who can provide me a solution so I'd know when the printing is cancelled?
Now here lies the problem. I want to be able to catch the event (or whatever it is that I could catch) when the user clicks on the cancel button. I couldn't find a way to do this.
I figured the use of Common Dialog box might solve the problem BUT as I am coding a class, I needed to reference commdlg32.dll - and I can't. "Can't add a reference to the specified file" error shows up. I had to drop this.
Is there anyone who can provide me a solution so I'd know when the printing is cancelled?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just curious: why not using forms in a dll??
Ludy,
Paste the following into your project and give it a try. Will work in a .cls no prob :)
-------------------------- ---------- ---------- ---------- ---------- -------
Option Explicit
Private Declare Function PrinterProperties Lib "winspool.drv" _
(ByVal hwnd As Long, ByVal hPrinter As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" _
Alias "OpenPrinterA" (ByVal pPrinterName As String, _
phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Type PRINTER_DEFAULTS
pDatatype As Long ' String
pDevMode As Long
pDesiredAccess As Long
End Type
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8
Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
Public Function DisplayPrinterProperties(D eviceName As String) _
As Boolean
'PURPOSE: Displays the property sheet for the printer
'Specified by Device Name
'PARAMETER: DeviceName: DeviceName of Printer to
'Display Properties of
'EXAMPLE USAGE: DisplayPrinterProperties Printer.DeviceName
'NOTES: As Written, you must put this function into a form
'module. To put into a .bas or .cls module, add a parameter for
'the form or the form's hwnd.
On Error GoTo ErrorHandler
Dim lAns As Long, hPrinter As Long
Dim typPD As PRINTER_DEFAULTS
typPD.pDatatype = 0
typPD.pDesiredAccess = PRINTER_ALL_ACCESS
typPD.pDevMode = 0
lAns = OpenPrinter(Printer.Device Name, hPrinter, typPD)
If lAns <> 0 Then
lAns = PrinterProperties(Me.hwnd, hPrinter)
DisplayPrinterProperties = lAns <> 0
End If
ErrorHandler:
If hPrinter <> 0 Then ClosePrinter hPrinter
End Function
-------------------------- ---------- ---------- ---------- ---------- -------
Snippet by Intelligent Solutions Inc.
Paste the following into your project and give it a try. Will work in a .cls no prob :)
--------------------------
Option Explicit
Private Declare Function PrinterProperties Lib "winspool.drv" _
(ByVal hwnd As Long, ByVal hPrinter As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" _
Alias "OpenPrinterA" (ByVal pPrinterName As String, _
phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Type PRINTER_DEFAULTS
pDatatype As Long ' String
pDevMode As Long
pDesiredAccess As Long
End Type
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8
Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
Public Function DisplayPrinterProperties(D
As Boolean
'PURPOSE: Displays the property sheet for the printer
'Specified by Device Name
'PARAMETER: DeviceName: DeviceName of Printer to
'Display Properties of
'EXAMPLE USAGE: DisplayPrinterProperties Printer.DeviceName
'NOTES: As Written, you must put this function into a form
'module. To put into a .bas or .cls module, add a parameter for
'the form or the form's hwnd.
On Error GoTo ErrorHandler
Dim lAns As Long, hPrinter As Long
Dim typPD As PRINTER_DEFAULTS
typPD.pDatatype = 0
typPD.pDesiredAccess = PRINTER_ALL_ACCESS
typPD.pDevMode = 0
lAns = OpenPrinter(Printer.Device
If lAns <> 0 Then
lAns = PrinterProperties(Me.hwnd,
DisplayPrinterProperties = lAns <> 0
End If
ErrorHandler:
If hPrinter <> 0 Then ClosePrinter hPrinter
End Function
--------------------------
Snippet by Intelligent Solutions Inc.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
No response from ludy from 12/12/2003 comment
Award points to Ficus is recommend.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
planocz
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
No response from ludy from 12/12/2003 comment
Award points to Ficus is recommend.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
planocz
EE Cleanup Volunteer
ASKER
I really need to have the Print dialog box show up even the project's formless and do the necessary actions when the User continues printing or cancel it.