I am trying to write a basic program for printing in landscape mode and I think I am setting everything correctly but it still prints in portrait mode
This is what I have so far
#COMPILE EXE
$INCLUDE "WIN32API.INC"
#INCLUDE "comdlg32.inc"
' Lines per page
%LPP = 66
'The Following GLOBAL(s) Specify Controls for OUTPUT Patches!
GLOBAL FontMetrix AS LONG
GLOBAL LineCtr AS LONG
GLOBAL PrinterOpen AS LONG
GLOBAL hDC AS LONG 'hDC of printer
GLOBAL szText AS ASCIIZ * 256
GLOBAL tm AS TEXTMETRIC
GLOBAL di AS docinfo
GLOBAL hFont AS LONG, hFontOld AS LONG
GLOBAL Lf AS LOGFONT
GLOBAL dm AS DEVMODE
'Global variable that point to the print position
GLOBAL PositionX AS INTEGER
GLOBAL PositionY AS INTEGER
'
'
FUNCTION SetFont(LPFont AS STRING,LPSize AS INTEGER, Bold AS INTEGER, _
Italic AS INTEGER, Underline AS INTEGER, Strikeout AS INTEGER ) AS INTEGER
' Create the font using device point sizes
' create a %PointSize font, or...
'
Lf.lfHeight = LPSize * GetDeviceCaps(hDC, %LOGPIXELSY) / 72
' create a scaled font FOR 60 lines/PAGE
' Lf.lfHeight = INT(GetDeviceCaps(hDC, %LOGPIXELSY) / 6)
' create a scaled font for %LPP lines/PAGE
' Lf.lfHeight = GetDeviceCaps(hDC, %VERTRES) \ %LPP
'
Lf.lfFaceName = LPFont
IF Bold THEN lf.lfWeight=700 ELSE lf.lfWeight=400
Lf.lfItalic=Italic
lf.lfUnderline=Underline
lf.lfStrikeOut=Strikeout
hFont = CreateFontIndirect(LF)
hFontOld = SelectObject(hDC, hFont)
' Get the font metrics in logical point sizes
GetTextMetrics hDC, tm
FontMetrix = tm.tmHeight + tm.tmExternalLeading
FontMetrix = LF.lfHeight
END FUNCTION
FUNCTION Locate(Xcord AS INTEGER,Ycord AS INTEGER) AS INTEGER
PositionX = Xcord
PositionY = Ycord
END FUNCTION
FUNCTION WPrint(szText AS ASCIIZ) AS INTEGER
textOut hDC, PositionX,PositionY, szText, LEN(szText)
END FUNCTION
FUNCTION CloseAPrinter () AS LONG
' clean up the GDI object to prevent a memory leak
SelectObject hDC, hFontOld
DeleteObject hFont
EndPage hDC 'Ends the CURRENT PAGE ONLY!
EndDoc hDC 'Ends the CURRENT DOCUMENT!
' delete the DC to prevent a memory leak
DeleteDC hDC
END FUNCTION
FUNCTION PBMAIN()
LOCAL Var AS WORD
'
' Open a Printer
'
LOCAL DvModePtr AS DEVMODE PTR
LOCAL pDevMode AS STRING
'
' create DEVMODE for printer
'
pDevMode = SPACE$(LEN(DEVMODE)) ' allocate string space for the DEVMODE
DvModePtr = STRPTR(pDevMode) ' setup a pointer the allocated space for DEVMODE
'
' set device mode properties
'
@DvModePtr.dmSize = LEN(DEVMODE)
@DvModePtr.dmFields = %DM_ORIENTATION
@DvModePtr.dmOrientation = %DMORIENT_LANDSCAPE
'
' Buffer to receive the Default Printer info
'
LOCAL PInfo5() AS PRINTER_INFO_5
' Now allocate the space to get the Default Printer data
DIM PInfo5(0:2) AS PRINTER_INFO_5, dwNeeded&, dwReturned&
EnumPrinters %PRINTER_ENUM_DEFAULT, _ 'printer object types
BYVAL %NULL,_ 'name of printer object
5,_ 'information level
BYVAL VARPTR(PInfo5(0)), _ 'printer information buffer
SIZEOF(PInfo5(0)) * 3,_ 'size of printer information buffer
dwNeeded&,_ 'bytes received or required
dwReturned& 'number of printers enumerated
'
' Create the printer context
'
hDC = CreateDC(BYVAL %Null, _ 'driver name it can be either the null-terminated string DISPLAY or the device name
BYVAL PInfo5(0).pPrinterName, _ 'device name Pointer to a null-terminated character string that specifies the name of the specific output
BYVAL %Null, _ 'This parameter is ignored for Win32-based applications
BYVAL DvModePtr) 'optional Pointer to a DEVMODE structure
IF ISFALSE hDC THEN EXIT FUNCTION
'
' This section sets up the document info for the printing
' di is document info
'
di.cbsize = SIZEOF(di)
szText = "Cypher Output"
di.lpszDocName = VARPTR(szText)
'
' start the process the document info to the handle for the printer
'
StartDoc hDC, di
StartPage hDC
'
'
SetTextAlign hDC, %TA_BASELINE OR %TA_NOUPDATECP OR %TA_LEFT
SetBkMode hDC, %TRANSPARENT
'
PrinterOpen =1
FUNCTION = 1
'
SetFont "Courier New",14,1,0,0,1
locate 100,100
WPRINT (" This is a test of the printer ")
SetFont "Arial", 24,0,1,1,0
locate 100,200
wprint (" This is another test of the printer ")
locate 100,300
wprint ("dmSize = " + HEX$(DvModePtr))
locate 100,400
wprint ("dmSize = " + HEX$(@DvModePtr.dmSize))
locate 100,500
wprint ("dmFields = " + HEX$(@DvModePtr.dmFields))
CLoseAPrinter
' PrintTest
END FUNCTION
This is what I have so far
#COMPILE EXE
$INCLUDE "WIN32API.INC"
#INCLUDE "comdlg32.inc"
' Lines per page
%LPP = 66
'The Following GLOBAL(s) Specify Controls for OUTPUT Patches!
GLOBAL FontMetrix AS LONG
GLOBAL LineCtr AS LONG
GLOBAL PrinterOpen AS LONG
GLOBAL hDC AS LONG 'hDC of printer
GLOBAL szText AS ASCIIZ * 256
GLOBAL tm AS TEXTMETRIC
GLOBAL di AS docinfo
GLOBAL hFont AS LONG, hFontOld AS LONG
GLOBAL Lf AS LOGFONT
GLOBAL dm AS DEVMODE
'Global variable that point to the print position
GLOBAL PositionX AS INTEGER
GLOBAL PositionY AS INTEGER
'
'
FUNCTION SetFont(LPFont AS STRING,LPSize AS INTEGER, Bold AS INTEGER, _
Italic AS INTEGER, Underline AS INTEGER, Strikeout AS INTEGER ) AS INTEGER
' Create the font using device point sizes
' create a %PointSize font, or...
'
Lf.lfHeight = LPSize * GetDeviceCaps(hDC, %LOGPIXELSY) / 72
' create a scaled font FOR 60 lines/PAGE
' Lf.lfHeight = INT(GetDeviceCaps(hDC, %LOGPIXELSY) / 6)
' create a scaled font for %LPP lines/PAGE
' Lf.lfHeight = GetDeviceCaps(hDC, %VERTRES) \ %LPP
'
Lf.lfFaceName = LPFont
IF Bold THEN lf.lfWeight=700 ELSE lf.lfWeight=400
Lf.lfItalic=Italic
lf.lfUnderline=Underline
lf.lfStrikeOut=Strikeout
hFont = CreateFontIndirect(LF)
hFontOld = SelectObject(hDC, hFont)
' Get the font metrics in logical point sizes
GetTextMetrics hDC, tm
FontMetrix = tm.tmHeight + tm.tmExternalLeading
FontMetrix = LF.lfHeight
END FUNCTION
FUNCTION Locate(Xcord AS INTEGER,Ycord AS INTEGER) AS INTEGER
PositionX = Xcord
PositionY = Ycord
END FUNCTION
FUNCTION WPrint(szText AS ASCIIZ) AS INTEGER
textOut hDC, PositionX,PositionY, szText, LEN(szText)
END FUNCTION
FUNCTION CloseAPrinter () AS LONG
' clean up the GDI object to prevent a memory leak
SelectObject hDC, hFontOld
DeleteObject hFont
EndPage hDC 'Ends the CURRENT PAGE ONLY!
EndDoc hDC 'Ends the CURRENT DOCUMENT!
' delete the DC to prevent a memory leak
DeleteDC hDC
END FUNCTION
FUNCTION PBMAIN()
LOCAL Var AS WORD
'
' Open a Printer
'
LOCAL DvModePtr AS DEVMODE PTR
LOCAL pDevMode AS STRING
'
' create DEVMODE for printer
'
pDevMode = SPACE$(LEN(DEVMODE)) ' allocate string space for the DEVMODE
DvModePtr = STRPTR(pDevMode) ' setup a pointer the allocated space for DEVMODE
'
' set device mode properties
'
@DvModePtr.dmSize = LEN(DEVMODE)
@DvModePtr.dmFields = %DM_ORIENTATION
@DvModePtr.dmOrientation = %DMORIENT_LANDSCAPE
'
' Buffer to receive the Default Printer info
'
LOCAL PInfo5() AS PRINTER_INFO_5
' Now allocate the space to get the Default Printer data
DIM PInfo5(0:2) AS PRINTER_INFO_5, dwNeeded&, dwReturned&
EnumPrinters %PRINTER_ENUM_DEFAULT, _ 'printer object types
BYVAL %NULL,_ 'name of printer object
5,_ 'information level
BYVAL VARPTR(PInfo5(0)), _ 'printer information buffer
SIZEOF(PInfo5(0)) * 3,_ 'size of printer information buffer
dwNeeded&,_ 'bytes received or required
dwReturned& 'number of printers enumerated
'
' Create the printer context
'
hDC = CreateDC(BYVAL %Null, _ 'driver name it can be either the null-terminated string DISPLAY or the device name
BYVAL PInfo5(0).pPrinterName, _ 'device name Pointer to a null-terminated character string that specifies the name of the specific output
BYVAL %Null, _ 'This parameter is ignored for Win32-based applications
BYVAL DvModePtr) 'optional Pointer to a DEVMODE structure
IF ISFALSE hDC THEN EXIT FUNCTION
'
' This section sets up the document info for the printing
' di is document info
'
di.cbsize = SIZEOF(di)
szText = "Cypher Output"
di.lpszDocName = VARPTR(szText)
'
' start the process the document info to the handle for the printer
'
StartDoc hDC, di
StartPage hDC
'
'
SetTextAlign hDC, %TA_BASELINE OR %TA_NOUPDATECP OR %TA_LEFT
SetBkMode hDC, %TRANSPARENT
'
PrinterOpen =1
FUNCTION = 1
'
SetFont "Courier New",14,1,0,0,1
locate 100,100
WPRINT (" This is a test of the printer ")
SetFont "Arial", 24,0,1,1,0
locate 100,200
wprint (" This is another test of the printer ")
locate 100,300
wprint ("dmSize = " + HEX$(DvModePtr))
locate 100,400
wprint ("dmSize = " + HEX$(@DvModePtr.dmSize))
locate 100,500
wprint ("dmFields = " + HEX$(@DvModePtr.dmFields))
CLoseAPrinter
' PrintTest
END FUNCTION
Comment