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, hBMP, hBMPDC As Dword
'put dialog image onto clipboard
Dialog Get Size hDlg To w,h
keybd_event(%VK_SnapShot, 1, 0, 0) 'place active dialog on clipboard
Clipboard Get Bitmap To hBMP
Graphic Attach hBMP, 0
Graphic Get DC To hBMPDC
'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
XPrint Get Size To pw,ph
XPrint Get Margin To nLeft, nTop, nRight, nBottom
pw = 0.9 * (pw-nLeft-nRight) '0.9 is arbitrary shrinkage to fall well within border of printer
ph = 0.9 * (ph-nTop-nBottom)
wNew = w/Max(w/pw, h/ph)
hNew = h/Max(w/pw, h/ph)
'copy screen to printer
StretchBlt hPrinterDC, 0,0,wNew,hNew,hBMPDC,0,0,w,h, %SRCCopy
'print the page of paper
XPrint Close
End Sub
'gbs_00892
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm