Page 1 of 1

Vista Printing issue

PostPosted: Tue Oct 06, 2009 6:26 pm
by don lowenstein
I am trying to print to a printer other than the windows default printer - in vista.

The technique used works fine in xp and before - however in vista - the Message Stop dialog appears as follows:
There are no printers installed!
Please exit this application and install a printer.
This message is coming from the TPRINTERS:NEW method
- and, in this particular scenario, there are several printers installed.

The following is the call to the Tprinter:new Method:
ODEVICE := TPRINTER():NEW( 'Report Name', .F., NIL, PRINTERNAME )
where PRINTERNAME is the name of the printer to use as acquired from the PRINTERSETUP() function as follows:
PRINTERSETUP()
hDC := GetPrintDefault( GetActiveWindow() )
PRINTERNAME := PRNGETNAME()

If, however in the vista environment,
I call Tprinter:new with the 2cnd parameter to force the printer selection dialog - all seems to work fine.
ODEVICE := TPRINTER():NEW( 'Report Name', .T.)

This is undesireable due to the additional interaction (Printer selection dialog) with the user which should not be required,
as we know what printer to use.

Any help with this issue is GREATLY appreciated.

Re: Vista Printing issue

PostPosted: Tue Oct 06, 2009 7:10 pm
by Richard Chidiak
Don

You need more than just prngetname() for this

This is the function i use, it works on both Vista and Xp

This is a sample of what is needed to print

// HP Deskjet F300 Series,winspool,Ne01:

HTH

Richard


AIMPRI := GETIMPRI(@AIMPRI)

OPRN := TPrinter():New(" Impression", .F. , .T. , AIMPRI[1] , .T. )


FUNCTION GETIMPRI(ADEVICES)
*----------------------------------------
LOCAl cAllEntries, cEntry, I, cName, cPrn, cPort, J

cAllEntries := STRTRAN( GetProfString( "Devices" ), Chr( 0 ), CRLF )
FOR I:= 1 TO MlCount( cAllEntries )
cName := MemoLine( cAllEntries,,I)
cEntry := GetProfString( "Devices",cName,"")
J := 2
WHILE ! EMPTY(cPort := StrToken(cEntry,J++,","))
// AADD(aDevices,TRIM(cName))
AADD(aDevices,TRIM(cName) + "," + CENTRY) // CHIDIAK
ENDDO
NEXT
RETURN aDevices

Re: Vista Printing issue

PostPosted: Wed Oct 07, 2009 6:58 pm
by don lowenstein
Thank you Richard - This appears to be working now.

I guess XP and before are forgiving about the name passed to TPrinter object.

Thanks again for your assistance.