Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
%IDC_Button = 500
Function PBMain() As Long
Dialog New Pixels, 0, "Print Screen",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button, "Print", 10,10,50,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button : PrintScreenImage
End Select
End Select
End Function
Sub PrintScreenImage
Local w,h,pw,ph,hnew,wnew,nLeft,nRight,nTop,nBottom As Long, hPrinterDC, hDeskTopDC As Dword
'get DC of printer and screen
XPrint Attach Default
XPrint Get DC To hPrinterDC
'get image dimensions that will fit into the printer, keeping aspect ratio
Desktop Get Size To w,h
XPrint Get Size To pw,ph
XPrint Get Margin To nLeft, nTop, nRight, nBottom
pw = pw-nLeft-nRight
ph = ph-nTop-nBottom
wNew = w/Max(w/pw, h/ph)
hNew = h/Max(w/pw, h/ph)
'copy screen to printer
hDeskTopDC = GetDC(%Null)
StretchBlt hPrinterDC, 0,0,wNew,hNew,hDeskTopDC,0,0,w,h, %SRCCopy
ReleaseDC(%Null,hDeskTopDC) 'clean up
'print the page of paper
XPrint Close
End Sub
'gbs_00893
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm