PDA

View Full Version : Please Clarify...



Michael Mullan
1-Mar-2010, 03:34 PM
from the Integration code in cVisualReport.PKG



// Prints the report
// If the optional hPrinterDc is not passed or when it is zero Visual Report Writer will
// popup a print dialog to choose a printer from. When you do not want a printer dialog
// (for example because the information is stored in a record or file) you need to pass
// the handle to the printer DC.
Procedure PrintReport Handle hPrinterDc
How do I get the handle for the default printer?

I want to add a button to a view which prints a single page report with no further clicks or dialogs.

I've hacked it down to this,
Use cVisualReport.pkg
Object oInstantReport is a cVisualReport
End_Object

Procedure PrintInstantReport
Integer iReportID
String sFilterFunction
String sFromMemberMemid
Move 3445 to sFromMemberMemid // hard coded for testing.
Move (sFormat('Return ({MEMBER.Memid} = "%1")',sFromMemberMemid)) to sFilterFunction
Set psReportName of oInstantReport to "memberCard.vrw"
Set peOutputDestination of oInstantReport to PRINT_TO_PRINTER
Set psFilterFunction of oInstantReport to sFilterFunction
Get OpenReport of oInstantReport to iReportId
Set piReportId of oInstantReport to iReportID
Send PrintReport of oInstantReport
Send Request_Cancel
End_Procedure

So, how do I get the handle for the default printer to make this work?

Ulbe Stellema
1-Mar-2010, 10:13 PM
Michael,

For RC II you need to pass the handle to the print DC, this handle can be obtained by using the VDF PrintDialog class. Set the 'Flags' property of the PrintDialog class to something like (PD_RETURNDEFAULT ior PD_RETURNDC) and call the 'PrintDialog' function. After the functions returns (without displaying the dialog if the PD_RETURNDEFAULT flags is used), the 'DeviceContext' property contains the handle you need to pass. See VDF docs for further information.

Note that the way this works may change, passing the printer DC doesn't allow you to specify the range of pages that need to be printed.

Michael Mullan
1-Mar-2010, 10:28 PM
Thanks Ulbe.

If this changes, that's fine, I'll change too, but I do need the ability to quietly send a report (or several) to the printer with no user interaction.

I've got several VRW reports set up as replacements for the "Print Screen" habit that my CM customers have.

I added a button to the toolbar that if enabled will call the appropriate report, to print out the same information that they used to get from a screen print. The button works if the View has the PrintImmediate report property set.

I imagine that if I ever do another invoicing, or Sales Receipt program I'd want to use this technique.

Michael Mullan
2-Mar-2010, 01:37 PM
Ulbe, and Co,

I added this code to my view:

Object oInstantReport is a cVisualReport
End_Object

Object oPrintDialog is a PrintDialog


Function DefaultPrinter Returns Integer

Integer iResult iRc
Pointer pHeap
Set Flags of oPrintDialog to (PD_RETURNDC + PD_RETURNDEFAULT)
Get PrintDialog of oPrintDialog to iResult

If (iResult ) Function_Return 0
Get DeviceContext of oPrintDialog to iRc
Move (GlobalUnlock(DevModeHandle(oPrintDialog))) to iResult
Move (GlobalFree(DevModeHandle(oPrintDialog))) to iResult
Move (GlobalFree(DevNamesHandle(oPrintDialog))) to iResult
Function_Return iRc
End_Function
End_Object

Procedure PrintInstantReport
Integer iReportID PrinterDC


String sFilterFunction
String sFromMemberMemid
Get Field_Current_Value of oMember_dd Field MEMBER.memid to sFromMemberMemid
Get DefaultPrinter of oPrintDialog to PrinterDC
Move (sFormat('Return ({MEMBER.Memid} = "%1")',sFromMemberMemid)) to sFilterFunction

Set psReportName of oInstantReport to "memberCard.vrw"
Set peOutputDestination of oInstantReport to PRINT_TO_PRINTER

Set psFilterFunction of oInstantReport to sFilterFunction
Get OpenReport of oInstantReport to iReportId
Set piReportId of oInstantReport to iReportID
If (PrinterDC = 0) Begin
Send PrintReport of oInstantReport
End
Else Begin
Send PrintReport of oInstantReport PrinterDC
End

Send CloseReport of oInstantReport iReportID
End_Procedure
After getting the Printer Dialog to return a Device Context for the default printer, I added the code in Bold. Now when I run the report, I get no printer dialogs, but the printer just prints a blank page.

Any Idea what gives?

Ulbe Stellema
5-Mar-2010, 03:02 PM
Fixed in RC III