*-------------------------------------------------------------------------------
#include "Gra.ch"
#include "Xbp.ch"
#include "Appevent.ch"

   #include "Appevent.ch" 
   #include "Common.ch" 
   #pragma Library( "XppUi2.lib" ) 
   PROCEDURE AppSys 
    //fSaveScr2Bmp()
   
   RETURN 
   PROCEDURE Main 
      LOCAL nEvent, mp1, mp2, oXbp, oBrowse, cField, i 
      oXbp := GuiStdDialog( "Standard GUI" ) 
      fSaveScr2Bmp(oXbp,oXbp:drawingArea)
      DO WHILE nEvent <> xbeP_Close 
         nEvent := AppEvent( @mp1, @mp2, @oXbp ) 
         oXbp:handleEvent( nEvent, mp1, mp2 ) 
      ENDDO 
   RETURN 
*-----------------------------------
   FUNCTION GuiStdDialog( cTitle ) 
      LOCAL oDlg 
      DEFAULT cTitle TO "Standard Dialog Window" 
      oDlg          := XbpDialog():new( ,,{100,100}, {200,200},, .F. ) 
      oDlg:icon     := 1 
      oDlg:taskList := .T. 
      oDlg:title    := cTitle 
      oDlg:create() 
      oDlg:show() 
      oDlg:drawingArea:setFontCompoundName( "8.Helv" ) 
   RETURN oDlg 
*-----------------------------------------------------------------------
FUNCTION fSaveScr2Bmp(oProg,oPare)
LOCAL oPS,oBitmap,oPS1,oBitmapC
LOCAL nXof:=0,nYof:=0,nCompr:=0 //no compresion
LOCAL aPosBmp,aSizBmp,cNamBmp:='test.jpg',nBits:=1,nTransc:=1
        aPosBmp:={200,200}
        aSizBmp:={1200,800}
        cNamBmp:='test.jpg'
        nBits:=1
        nTransc:=1
      //oProg:=AppDesktop():childFromName(1)
      //oPare:=AppDesktop():childFromName(1):drawingArea
        oPS:= XbpPresSpace():new()
        oPS:create(oPare:winDevice())
        oBitmap := GraSaveScreen(oPS,aPosBmp,aSizBmp,1,nBits,nTransC) 
        Erase(cNamBmp)
        oBitmap:SaveFile(cNamBmp,XBPBMP_FORMAT_JPG,nCompr)
        oBitmap:destroy()
        oPS:destroy()
RETURN NIL
*-------------------------------------------------------------------------------
FUNCTION GraSaveScreen( oSourcePS, aPos, aSize,nPM,nBits,nTransC) 
      LOCAL oBitmap   := XbpBitmap():new():create( oSourcePS ) 
      LOCAL oTargetPS := XbpPresSpace():new():create() 
      LOCAL aSourceRect[4], aTargetRect 
      aSourceRect[1] := aSourceRect[3] := aPos[1] 
      aSourceRect[2] := aSourceRect[4] := aPos[2] 
      aSourceRect[3] += aSize[1] 
      aSourceRect[4] += aSize[2] 
      aTargetRect    := {0, 0, aSize[1]*nPM, aSize[2]*nPM} 
      oBitmap:presSpace( oTargetPS ) 
      oBitmap:make( aSize[1]*nPM, aSize[2]*nPM ) 
      GraBitBlt( oTargetPS, oSourcePS, aTargetRect, aSourceRect ) 
RETURN oBitmap 
*-------------------------------------------------------------------------------
