Date: 02-16-2022
Return to Index
created by gbSnippets
'Primary Code:
'Credit: PowerBASIC Help file
XPrint Get Client TO ncWidth!, ncHeight! 'Retrieve the client size (printable area) of the printer page
XPrint Get PPI TO x&, y& 'Retrieve the resolution (points per inch) of the attached printer
ncWidth! = ncWidth!/x& 'Width in inches of the printable area
ncHeight! = ncHeight!/y& 'Height in inches of the printable area
XPrint Scale (0,0)-(ncWidth!,ncHeight!) 'Set scale to inches
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
#Include "CommCtrl.inc"
Global hDlg as DWord, hRichEdit as DWord
%ID_RichEdit = 500
Function PBMain() As Long
Local style&, buf$
buf$ = "This is sample" + $CrLf + "text for the" + $CrLf + "edit control."
style& = %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _
Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop
Dialog New Pixels, 0, "Test Code",300,300,200,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 30,10,140,20
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, %ID_RichEdit, buf$,20,40,160,100, style&, %WS_EX_ClientEdge
Control Handle hDlg, %ID_RichEdit To hRichEdit
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 w as Single, h as Single
SetPrinterScaleToInches (w,h) 'w,h are return values
MsgBox Str$(w) + " " + Str$(h)
End If
End Function
Sub SetPrinterScaleToInches (ncWidth!, ncHeight!)
Local x&, y&
XPrint Attach Default 'Attach the default Windows printer
XPrint Get Client TO ncWidth!, ncHeight! 'Retrieve the client size (printable area) of the printer page
XPrint Get PPI TO x&, y& 'Retrieve the resolution (points per inch) of the attached printer
ncWidth! = ncWidth!/x& 'Width in inches of the printable area
ncHeight! = ncHeight!/y& 'Height in inches of the printable area
XPrint Scale (0,0)-(ncWidth!,ncHeight!) 'Set scale to inches
End Sub
'gbs_00300
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm