Jimmy, Tom!
I tried to modify the screenshot saving function so that it would cut out some area from the clipboard. But errors are issued. It's not working. In principle, of course, I can specify which window size to use when it is output. But I would like to see them determined automatically. The fact is that they may differ from the set, if there are buttons. Buttons are are other objects than the window, so simultaneously with the window they are difficult to capture (separately from Windows without problems). In addition, the name of the window contains important information that you would not want to lose in the screenshot. In General, while was so-so, slightly better than nothing.
Code: Select all
FUNCTION SaveScreenAsFile(mXSize,mYSize,cFileName) // hand over filename you want to use
LOCAL oClipBoard, oPicture, nResolution := 30
DC_Scrn2Clipboard()
oClipBoard := XbpClipBoard():new():create()
oClipBoard:open()
oPicture := oClipBoard:GetBuffer(XBPCLPBRD_BITMAP)
*IF ::oClipBoard:open()
* aFormats := ::oClipBoard:queryFormats()
* IF ASCAN( aFormats, XBPCLPBRD_BITMAP ) > 0
oBuffer := ::oClipBoard:getBuffer( XBPCLPBRD_BITMAP )
// cut out part of bitmap
oBMP := CutOutBMP( oBuffer, ::aoChild,mXSize,mYSize )
* ENDIF
*ENDIF
oClipBoard:Close()
oPicture:SaveFile(cFileName,XBPBMP_FORMAT_JPG,nResolution)
RETURN File(cFileName)
******************************************************************************************
FUNCTION CutOutBMP( oBuffer, aoChild,nOutSizeX,nOutSizeY ) // Jimmy
LOCAL oOutBMP := XBPBITMAP() :New() :Create()
LOCAL oMain := GetApplication()
LOCAL oTargetPS := XBPPRESSPACE() :new() :create()
*LOCAL nOutSizeX := SP_BMPxSize()
*LOCAL nOutSizeY := SP_BMPySize()
LOCAL aPos := { 0, 0 }
LOCAL aSize := { 0, 0 }
LOCAL aSize1 := { 0, 0 }
nCYCAPTION := GetSystemMetrics( SM_CYCAPTION )
nCXBORDER := GetSystemMetrics( SM_CXBORDER )
nCYBORDER := GetSystemMetrics( SM_CYBORDER )
nCXDLGFRAME := GetSystemMetrics( SM_CXDLGFRAME )
nCYDLGFRAME := GetSystemMetrics( SM_CYDLGFRAME )
nCXPADDEDBORDER := GetSystemMetrics( SM_CXPADDEDBORDER )
// Pos / Size of Windows
aPos := aoChild[ CH_LOGO ] :CurrentPos()
aSize := aoChild[ CH_ANZEIG ] :CurrentSize() // parent of WMP
// need to adjust position "inside" frame
aPos[ 1 ] += 10 // oAnzeig
aPos[ 2 ] += 10
// reduce bottom Size with statusbar
aSize1 := aoChild[ CH_STATBAR ] :CurrentSize()
aPos[ 2 ] += aSize1[ 2 ]
// adjust Border wide
aPos[ 1 ] += SP_CXBORDER()
aPos[ 2 ] += SP_CYBORDER()
// adjust Frame wide
aPos[ 1 ] += SP_CXDLGFRAME()
aPos[ 2 ] += SP_CYDLGFRAME()
// still 1 Pixel missing
aPos[ 1 ] += 1
aPos[ 2 ] += 1
IF OnOSVersion() > 5 // Vista-Win7 DWM Aero
* aPos[1] += SP_CXPADDEDBORDER() // Border Padding ?
* aPos[2] += SP_CXPADDEDBORDER()
ENDIF
* ------------------------------------------------------ *
oOutBMP:presSpace( oTargetPS )
oOutBMP:make( nInSizeX, nInSizeY )
oBuffer:Draw( oTargetPS, ; // oTargetPS
{ 0, 0, nOutSizeX, nOutSizeY }, ; // aTargetRect
{ aPos[1], aPos[2], aPos[1] + aSize[1], aPos[2] + aSize[2] }, ; // aSourceRect
GRA_BLT_ROP_SRCCOPY, ; // nRasterOP GRA_BLT_ROP_*
GRA_BLT_BBO_IGNORE ) // nCompress GRA_BLT_BBO_*
Sleep( 0 )
oTargetPS:destroy()
Sleep( 0 )
oTargetPS := NIL
RETURN oOutBMP
******************************************************************************************
FUNCTION SP_CYCAPTION( nValue ) // Caption height
IF( PCOUNT() > 0, nCYCAPTION := nValue, NIL )
RETURN nCYCAPTION
FUNCTION SP_CXBORDER( nValue ) // Border wide
IF( PCOUNT() > 0, nCXBORDER := nValue, NIL )
RETURN nCXBORDER
FUNCTION SP_CYBORDER( nValue ) // Border height
IF( PCOUNT() > 0, nCYBORDER := nValue, NIL )
RETURN nCYBORDER
FUNCTION SP_CXDLGFRAME( nValue ) // Dialog X-Frame
IF( PCOUNT() > 0, nCXDLGFRAME := nValue, NIL )
RETURN nCXDLGFRAME
FUNCTION SP_CYDLGFRAME( nValue ) // Dialog Y-Frame
IF( PCOUNT() > 0, nCYDLGFRAME := nValue, NIL )
RETURN nCYDLGFRAME
FUNCTION SP_CXPADDEDBORDER( nValue ) // Border Padding
IF( PCOUNT() > 0, nCXPADDEDBORDER := nValue, NIL )
RETURN nCXPADDEDBORDER
FUNCTION OnOSVersion()
LOCAL cVersion := OS( OS_VERSION )
LOCAL nVersion := 0
LOCAL nPosi
nPosi := AT( ".", cVersion )
IF nPosi > 0
nVersion := VAL( SUBSTR( cVersion, 1, nPosi - 1 ) )
ENDIF
RETURN nVersion
[/size]