Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
'press the button to print the image to the default printer
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg, hBMP, hDC_Dialog, hDC_Graphic As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Dialog Capture",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 w,h As Long
Local Xscale, Yscale As Single
Dialog Get Size hDlg To w,h
hDC_Dialog = GetWindowDC (hDlg)
' Dialog Get Client hDlg To w,h 'client area DC only
' hDC_Dialog = GetDC (hDlg) 'client area DC only
Graphic Bitmap New w,h To hBMp
Graphic Attach hBMP, 0
Graphic Get DC To hDC_Graphic
BitBlt hDC_Graphic, 0,0,w,h, hDC_Dialog, 0,0, %SRCCopy
XPrint Attach Default
GetScaleFactors (XScale,YScale)
XPrint Stretch hBMP, 0, (0,0)-(w-1,h-1) To (0,0)-(XScale*w-1,YScale*h-1)
XPrint Close
ReleaseDC hDlg, hDC_Dialog 'PowerBASIC handles release of hDC_Graphic
End If
End Function
Sub GetScaleFactors(XScale As Single, YScale As Single)
Local i, j, r, s As Long
Graphic Get PPI To i,j
XPrint Get PPI To r,s
XScale = r/i
YScale = s/j
End Sub
'gbs_00551
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm