Date: 02-16-2022
Return to Index
created by gbSnippets
'When writing print routines, a programmer needs to know which areas of the
'printer cannot be printed to - the unprintable area.
'Primary Code:
'Credit: Lee Furr + MSDN (http://support.microsoft.com/kb/193943)
'The getdevicecaps API is the key:
xlogpix = getdevicecaps(hDC_Printer, %logpixelsx) 'resolution x
ylogpix = getdevicecaps(hDC_Printer, %logpixelsy) 'resolution y
x = getdevicecaps(hDC_Printer, %physicaloffsetx) / xlogpix 'unprintable area
y = getdevicecaps(hDC_Printer, %physicaloffsety) / ylogpix 'unprintable ares
w = getdevicecaps(hDC_Printer, %physicalwidth) / xlogpix 'total paper x
h = getdevicecaps(hDC_Printer, %physicalheight) / ylogpix 'total paper y
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "comdlg32.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
Local x,y,w,h As Single
Local hDCP As Dword
XPrint Attach Default
XPrint Get DC To hDCP
UnprintableArea x,y,w,h,hDCP
MsgBox " x "+Format$(x, "0.00") + " y "+Format$(y, "0.00") + _
" w "+Format$(w, "0.00") + " h "+Format$(h, "0.00")
Local PPIx, PPIy As Long
XPrint Get PPI To PPIx, PPiy
XPrint Get Client To x,y
MsgBox " x "+Format$(x/PPIx, "0.00") + " y "+Format$(y/PPIy, "0.00")
Local nLeft, nTop, nRight, nBottom As Single
XPrint Get Margin To nLeft, nTop, nRight, nBottom
MsgBox " left "+Format$(nLeft/PPIx, "0.00") + " top "+Format$(nTop/PPIy, "0.00") + _
" right "+Format$(nRight/PPIx, "0.00") + " left "+Format$(nBottom/PPIy, "0.00")
End If
End Function
Sub UnprintableArea(x As Single, y As Single, w As Single, h As Single, hDC_Printer As Dword)
Local szthisprinter As Asciiz * 256
Local offsetx, offsety, xlogpix, ylogpix, xsize, ysize As Long
xlogpix = getdevicecaps(hDC_Printer, %logpixelsx) 'resolution x
ylogpix = getdevicecaps(hDC_Printer, %logpixelsy) 'resolution y
x = getdevicecaps(hDC_Printer, %physicaloffsetx) / xlogpix 'unprintable area
y = getdevicecaps(hDC_Printer, %physicaloffsety) / ylogpix 'unprintable ares
w = getdevicecaps(hDC_Printer, %physicalwidth) / xlogpix 'total paper x
h = getdevicecaps(hDC_Printer, %physicalheight) / ylogpix 'total paper y
End Sub
'gbs_00552
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm