Page 1 of 3

Screen grabber in Alaska

Posted: Wed Jul 19, 2017 1:39 am
by Eugene Lutsenko
Is there in Alaska a function or program that provides a Screen grabber is the active window and allows to save the image as a file?

Re: Screen grabber in Alaska

Posted: Wed Jul 19, 2017 12:03 pm
by rdonnay
No, there is not a function. I had to write my own function:

Code: Select all

FUNCTION GraSaveScreen( oSourcePS, aPos, aSize )

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], aSize[2]}

oBitmap:presSpace( oTargetPS )
oBitmap:make( aSize[1], aSize[2] )

GraBitBlt( oTargetPS, oSourcePS, aTargetRect, aSourceRect )

RETURN oBitmap

Re: Screen grabber in Alaska

Posted: Wed Jul 19, 2017 2:20 pm
by Cliff Wiernik
There are some additional samples under xbpbitmap in the alaska help file.

Re: Screen grabber in Alaska

Posted: Wed Jul 19, 2017 3:03 pm
by Eugene Lutsenko
Hello, everyone!!!

The function apply like this:

oBitmap := GraSaveScreen( oPS, oStatic1:CurrentPos() , oStatic1:CurrentSize() )
oBitmap:SaveFile(cFileName)

Sorry again, black screen. I don't know what to do... While I display charts one by one and do Alt+PrnScreen

Re: Screen grabber in Alaska

Posted: Wed Jul 19, 2017 3:21 pm
by Auge_Ohr
Eugene Lutsenko wrote: oBitmap := GraSaveScreen( oPS, oStatic1:CurrentPos() , oStatic1:CurrentSize() )
oBitmap:SaveFile(cFileName)
hm ... what is your oPS ?

Re: Screen grabber in Alaska

Posted: Wed Jul 19, 2017 4:44 pm
by Cliff Wiernik
This is what I use to capture the current dialog from the screen.


*+±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± // PC CAW 12-30-05 modified to not do winapi printscreen if object passed
*+
*+ Function LB_Scrn2ClipBoard( oXbp )
*+
*+ Copies the specified object (oXbp) to clipboard or the application
*+ Application desktop if not specified
*+
*+±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
*+
FUNCTION LB_Scrn2ClipBoard( oXbp )

LOCAL oSourcePS, oBitmap, oClipBoard, aPos

oSourcePS := oXbp:lockPS()

IF oXbp:isDerivedFrom('XbpDialog')
IF left(OS(OS_VERSION),3)>='06.'
aPos := { -8, -8 }
ELSE
aPos := { -4, -4 }
ENDIF
ELSE
aPos := { 0, 0 }
ENDIF

oBitmap := GraSaveScreen( oSourcePS, aPos, oXbp:currentSize() )


RETURN oBitmap

Re: Screen grabber in Alaska

Posted: Wed Jul 19, 2017 9:22 pm
by Auge_Ohr
Cliff Wiernik wrote:

Code: Select all

    oSourcePS := oXbp:lockPS()
...
    oBitmap := GraSaveScreen( oSourcePS, aPos, oXbp:currentSize() )

// unlock before return
    oSourcePS:unlockPS() 

  RETURN oBitmap

Re: Screen grabber in Alaska

Posted: Wed Jul 19, 2017 10:19 pm
by Eugene Lutsenko
Greetings to all!

Tried all suggested options and a few of its own, but is in the form of file is saved in the black screen. And this despite the fact that the screen eyes all is perfectly visible that everything is correct. An error occurred with the line:

GraBitBlt( oTargetPS, oSourcePS, aTargetRect, aSourceRect )

function by Roger:

Code: Select all

*************************************************
******** Сохранение экрана (Screen grabber) Roger
*************************************************
FUNCTION GraSaveScreen( oSourcePS, aPos, aSize )

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], aSize[2]}

oBitmap:presSpace( oTargetPS )
oBitmap:make( aSize[1], aSize[2] )

GraBitBlt( oTargetPS, oSourcePS, aTargetRect, aSourceRect )

RETURN oBitmap

Re: Screen grabber in Alaska

Posted: Wed Jul 19, 2017 10:22 pm
by Eugene Lutsenko
I think I guessed it! In function:

oBitmap := GraSaveScreen( oStatic1, oStatic1:CurrentPos() , oStatic1:CurrentSize() )

after rotation is incorrectly determined position and size. I'll check it

Re: Screen grabber in Alaska

Posted: Wed Jul 19, 2017 11:55 pm
by Eugene Lutsenko
Can be anyone who is interested, you can rewrite this program to write two images: 1) before rotating the image; 2) after image rotation:

Code: Select all

//////////////////////////////////////////////////////////////////////
//
//  FANCYFNT.PRG
//
//  Copyright:
//      Alaska Software, (c) 1997-2009. All rights reserved.         
//  
//  Contents:
//      This sample program renders some text strings demonstrating the GRA
//      engine's GraStringAt() primitive.
//   
//////////////////////////////////////////////////////////////////////
#include "appevent.ch"
#include "xbp.ch"
#include "gra.ch"


******************************************************************************
* Main() procedure and event loop
******************************************************************************
PROCEDURE Main

   LOCAL nEvent, mp1, mp2, oObj
   LOCAL oPS
   LOCAL oFont
   LOCAL aLineAttrs
   LOCAL aStringAttrs
   LOCAL aMatrix
   LOCAL i


   /*
    * Setup XbpCrt object created by the AppSys()
    * procedure
    */
   SetAppWindow():useShortCuts := .T.
   SetColor( "N/W+" )
   CLS

   /* Get presentation space for rendering   */
   oPS := SetAppWindow():presSpace()

   oFont := XbpFont():new():create("20.Arial Bold")
   GraSetFont(oPS , oFont)
   aAttrF := ARRAY( GRA_AS_COUNT ) 
   aAttrF [ GRA_AS_COLOR      ] := GRA_CLR_BLACK 
   aAttrF [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_LEFT
   aAttrF [ GRA_AS_VERTALIGN  ] := GRA_VALIGN_HALF
   GraSetAttrString( oPS, aAttrF ) 
   GraStringAt( oPS, { 20,350 }, 'The text before the rotation' )

   *********************************************
   ******** Save before rotating the image *****
   *********************************************

   /*
    * Rotate text strings to show transforms via
    * SetGraTransform()
    */
   oFont := XbpFont():new():create("10.Arial Bold")
   GraSetFont(oPS , oFont)
   aAttrF := ARRAY( GRA_AS_COUNT ) 
   aAttrF [ GRA_AS_COLOR      ] := GRA_CLR_BLACK 
   aAttrF [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_CENTER
   aAttrF [ GRA_AS_VERTALIGN  ] := GRA_VALIGN_HALF
   GraSetAttrString( oPS, aAttrF ) 

   nAngle = 10

   aMatrix := GraInitMatrix()
   FOR i:=1 TO nAngle
      GraRotate( oPS, aMatrix, 360/nAngle, {200, 200}, GRA_TRANSFORM_ADD )
      oPS:setGraTransform( aMatrix, GRA_TRANSFORM_REPLACE )
      GraStringAt( oPS, {100,100}, ALLTRIM(STR(i))+"-Rotated text..." )
   NEXT

   ***** Rotate the image (360) for proper rendering

   GraRotate( oPS, aMatrix, 360, {200, 200}, GRA_TRANSFORM_ADD )
   oPS:setGraTransform( aMatrix, GRA_TRANSFORM_REPLACE )
   
   oFont := XbpFont():new():create("20.Arial Bold")
   GraSetFont(oPS , oFont)                        
   aAttrF := ARRAY( GRA_AS_COUNT ) 
   aAttrF [ GRA_AS_COLOR      ] := GRA_CLR_BLACK 
   aAttrF [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_LEFT
   aAttrF [ GRA_AS_VERTALIGN  ] := GRA_VALIGN_HALF
   GraSetAttrString( oPS, aAttrF ) 
   GraStringAt( oPS, { 20,50 }, 'The text after the label at an angle' )

   *********************************************
   **** Save after image rotation **************
   *********************************************

   INKEY(0)

RETURN

// EOF
[/size]

I have failed