LB Booster
Programming >> Liberty BASIC language >> Getting printer orientation?
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1441101827

Getting printer orientation?
Post by Monkfish on Sep 1st, 2015, 10:03am

Is there a straightforward way to find the current printer page orientation?

I found an old piece of code by Dennis McKinney, but it seems very long and I don't think it works any more. I also found some code to change the printer orientation, but I just need to know what it is set to.
Re: Getting printer orientation?
Post by Richard Russell on Sep 1st, 2015, 11:53am

on Sep 1st, 2015, 10:03am, Monkfish wrote:
Is there a straightforward way to find the current printer page orientation?.

If the page height is greater than the width then it's portrait, and if the width is greater than the height it's landscape!

Code:
    !hDCprt = @prthdc%
    calldll #gdi32, "GetDeviceCaps", hDCprt as ulong, _HORZRES as long, width as long
    calldll #gdi32, "GetDeviceCaps", hDCprt as ulong, _VERTRES as long, height as long 
    if height > width then
        print "Portrait"
    else
        print "Landscape"
    end if 

If you prefer an LB-compatible version get the printer DC using a call to the PrintDlg API with PD_RETURNDEFAULT and PD_RETURNDC flags.

Richard.

Re: Getting printer orientation?
Post by Monkfish on Sep 1st, 2015, 7:20pm

Thank you. That works perfectly grin
Re: Getting printer orientation?
Post by Richard Russell on Sep 1st, 2015, 9:22pm

on Sep 1st, 2015, 7:20pm, Monkfish wrote:
Thank you. That works perfectly ;D

For completeness, here's the somewhat more complicated LB-compatible version:

Code:
    struct pd, lStructSize as long, hwndOwner as ulong, hDevMode as ulong, hDevNames as ulong, _
      hDC as ulong, Flags as long, nFromPage as short, nToPage as short, nMinPage as short, _
      nMaxPage as short, nCopies as short, hInstance as ulong, lCustData as long, _
      lpfnPrintHook as long, lpfnSetupHook as long, lpPrintTemplateName as ptr, _
      lpSetupTemplateName as ptr, hPrintTemplate as ulong, hSetupTemplate as ulong
    pd.lStructSize.struct = len(pd.struct)
    pd.Flags.struct = _PD_RETURNDEFAULT or _PD_RETURNDC
    calldll #comdlg32, "PrintDlgA", pd as struct, result as long
    hDCprt = pd.hDC.struct
    calldll #gdi32, "GetDeviceCaps", hDCprt as ulong, _HORZRES as long, width as long
    calldll #gdi32, "GetDeviceCaps", hDCprt as ulong, _VERTRES as long, height as long
    if height > width then
        print "Portrait"
    else
        print "Landscape"
    end if 

Richard.