Ingo,
> here is the code I implemented at last in my projecct.
many thanks!
> I have to thank you very much for your great work and your helpfulness and
> patience.
Your welcome!
![Very Happy :-D](./images/smilies/icon_e_biggrin.gif)
BTW, I did some little changes to make it even simpler to use. Now all the
calculations are done inside the method and we just need to pass .T. or .F.
to keep the image aspect ratio:
IF nKey == VK_F12
WITH OBJECT TCaptureBitmap():New()
:Capture( Self )
:Hardcopy( .T., "Screenshot "+::cText, .T. )
END
It would be great if you can test it.
CLASS TCaptureBitmap FROM XCaptureBitmap
PUBLIC:
METHOD Hardcopy( lPreview, cTitle, lKeekProportion )
ENDCLASS
METHOD Hardcopy( lPreview, cTitle, lKeepProportion ) CLASS TCaptureBitmap
LOCAL lOk := .F.
LOCAL oPicture
LOCAL nHeight, nWidth
LOCAL aRect, nWndWidth, nWndHeight
LOCAL nProportion := 0
IF !Empty( ::Handle )
DEFAULT lPreview TO .T., ;
cTitle TO "Hardcopy", ;
lKeepProportion TO .T.
IF lKeepProportion
aRect := GetClientRect( ::hWho )
nWndWidth := aRect[3] - aRect[1]
nWndHeight := aRect[4] - aRect[2]
nProportion := nWndHeight / nWndWidth
ENDIF
Application:lBusy := .T.
Printer:lPreview := lPreview
Printer:nPreviewShowMode := smMAXIMIZE
Printer:nPrintQuality := DMRES_HIGH
Printer:cJobTitle := cTitle
Printer:nOrientation := IIF( nProportion < 1, DMORIENT_LANDSCAPE,
DMORIENT_PORTRAIT )
Printer:StartDoc()
Printer:oCanvas:nMapMode := mmPIXELS
Printer:StartPage()
oPicture := TPicture():New()
oPicture:CreateIndirect( IMG_BITMAP, ::Handle )
nWidth := Printer:PaperRes()[1] - 100
nHeight := Printer:PaperRes()[2] - 100
IF nHeight > nWidth
nHeight := nWidth * nProportion
ELSE
nWidth := nHeight / nProportion
ENDIF
Printer:oCanvas:DrawPicture( { 100, 100, nWidth, nHeight }, oPicture )
oPicture:Destroy()
Printer:EndPage()
Printer:EndDoc()
Application:lBusy := .F.
IF lPreview
Printer:Preview()
ENDIF
lOk := .T.
ENDIF
RETURN lOk
Regards,
José Lalín