PDA

View Full Version : PEGetSelectedPrinter and orientation



Sean Bamforth
21-Mar-2005, 06:02 AM
I am trying to work out the orientation of a crystal report.
I'm doing this because we have a customer report that could be landscape or
portrait.

If you just print the report, it works fine.
If you take a landscape report, request a printer then print it, it prints
in portrait.
I can set the orientation of the WinQLSelectPrinter to be portrait or
landscape, but I can't find a way of asking which way the report should
print.

PEGetSelectedPrinter should do the job. It should return a DEVMode block.
However, this devmode block seems to contain incorrect information. See
below for my code.

My questions are -
Has anyone had the same problem and got it to work?
Does PEGetSelectedPrinter even work? Has anyone used it successfully.

My configuration is VDF7 and Crystal 8.

Thanks in advance for any info on this matter.

regards

Sean Bamforth



==========================================


The Code I'm using is as follows ....

Function ReportOrientation Returns String
Local Integer iPrintJob iResult iTextHandle iTextLength
Local String sDriver sPrinter sPort sDEVMODE sReturn
Local Pointer pDriver pPrinter pPort pDEVMODE pReturn
integer iOrientation
integer iFields
string sTmp
integer iTmp

Get PrintJob To iPrintJob
FillType PETextStructure With 0 To sDriver
FillType PETextStructure With 0 To sPrinter
FillType PETextStructure With 0 To sPort
FillType DevMode With 0 To sDEVMODE

GetAddress Of sDriver To pDriver
GetAddress Of sPrinter To pPrinter
GetAddress Of sPort To pPort
GetAddress Of sDevMode To pDEVMODE

Move
(PEGetSelectedPrinter(iPrintJob,pDriver,pDriver+4, pPrinter,pPrinter+4,pPort,
pPort+4,pDEVMODE)) To iResult
GetBuff From sDevMode at DEVMODE.dmFields to iFields
If (iFields iAnd DM_ORIENTATION) move (BytesToShort(sDevMode,45))
to iOrientation

showln "iFields, " iFields
showln iresult ", " (length(sDevMode)) ", " iOrientation ", "
iFields

Send HandlePossibleError
Function_Return iOrientation
End_Function // PrinterDEVMODE




--
===============================
SELECT Computer Systems Ltd.
sean@select-cs.co.uk

Sean Bamforth
21-Mar-2005, 07:32 AM
Got it.
I'm suprised that nobodys asked this before and the answer isn't in here.
Anyway, to get the saved orientation of a crystal report, use the following
....
(Stuff stripped out, so may not work exactly as planned)


Function ReportOrientation Returns String
Local Integer iPrintJob iResult iTextHandle iTextLength
Local String sDriver sPrinter sPort sDEVMODE pDevMode2 sReturn
Local Pointer pDriver pPrinter pPort pDEVMODE pReturn
integer iOrientation
integer iFields

string sDMPointer
pointer pDMPointer

Get PrintJob To iPrintJob
FillType PETextStructure With 0 To sDriver
FillType PETextStructure With 0 To sPrinter
FillType PETextStructure With 0 To sPort
FillType Pointer With 0 To sDMPointer
FillType DevMode With 0 To sDevMode

GetAddress Of sDriver To pDriver
GetAddress Of sPrinter To pPrinter
GetAddress Of sPort To pPort
GetAddress Of sDMPointer To pDMPointer

Move
(PEGetSelectedPrinter(iPrintJob,pDriver,pDriver+4, pPrinter,pPrinter+4,pPort,
pPort+4,pDMPointer)) To iResult
GetBuff From sDMPointer at PEDMPointer.pDevMode to pDEVMODE
GetAddress of sDevMode to pDEVMODE2
Move (CopyMemory(pDevMode2,pDevMode,(length(sDevMode))) ) To
iResult

GetBuff From sDevMode at DEVMODE.dmFields to iFields
If (iFields iAnd DM_ORIENTATION) move
(BytesToByte(sDevMode,45)) to iOrientation

Send HandlePossibleError
Function_Return iOrientation
End_Function // PrinterDEVMODE




--------------



"Sean Bamforth" <sean@select-cs.co.uk> wrote in message
news:yR9e$VgLFHA.1912@dacmail.dataaccess.com...
I am trying to work out the orientation of a crystal report.
I'm doing this because we have a customer report that could be landscape or
portrait.

If you just print the report, it works fine.
If you take a landscape report, request a printer then print it, it prints
in portrait.
I can set the orientation of the WinQLSelectPrinter to be portrait or
landscape, but I can't find a way of asking which way the report should
print.

PEGetSelectedPrinter should do the job. It should return a DEVMode block.
However, this devmode block seems to contain incorrect information. See
below for my code.

My questions are -
Has anyone had the same problem and got it to work?
Does PEGetSelectedPrinter even work? Has anyone used it successfully.

My configuration is VDF7 and Crystal 8.

Thanks in advance for any info on this matter.

regards

Sean Bamforth



==========================================


The Code I'm using is as follows ....

Function ReportOrientation Returns String
Local Integer iPrintJob iResult iTextHandle iTextLength
Local String sDriver sPrinter sPort sDEVMODE sReturn
Local Pointer pDriver pPrinter pPort pDEVMODE pReturn
integer iOrientation
integer iFields
string sTmp
integer iTmp

Get PrintJob To iPrintJob
FillType PETextStructure With 0 To sDriver
FillType PETextStructure With 0 To sPrinter
FillType PETextStructure With 0 To sPort
FillType DevMode With 0 To sDEVMODE

GetAddress Of sDriver To pDriver
GetAddress Of sPrinter To pPrinter
GetAddress Of sPort To pPort
GetAddress Of sDevMode To pDEVMODE

Move
(PEGetSelectedPrinter(iPrintJob,pDriver,pDriver+4, pPrinter,pPrinter+4,pPort,
pPort+4,pDEVMODE)) To iResult
GetBuff From sDevMode at DEVMODE.dmFields to iFields
If (iFields iAnd DM_ORIENTATION) move (BytesToShort(sDevMode,45))
to iOrientation

showln "iFields, " iFields
showln iresult ", " (length(sDevMode)) ", " iOrientation ", "
iFields

Send HandlePossibleError
Function_Return iOrientation
End_Function // PrinterDEVMODE




--
===============================
SELECT Computer Systems Ltd.
sean@select-cs.co.uk