KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Acquiring a Web Area screen shot
PRODUCT: 4D | VERSION: 15 | PLATFORM: Mac & Win
Published On: February 8, 2016

Taking a screen shot of a Web Area is possible by using the print screen keyboard shortcuts or terminal commands on both plattforms. For simplification, the method webAreaScreenCapture below packages only the viewing area of the Web Area and weeds out the other parts of the screen shot. Both plattforms utilizes LAUNCH EXTERNAL PROCESS to achieve this. In Mac, a terminal command "screencapture" is used to capture the screen. As for, Windows a VBscript is called to take the screen shot and copy it to the clip board. Since Windows has an application window, a method CheckAppWindowFullScreen will take an account if it is in full screen shown below:

The VB script (print_screen_shot.vbs) required for Windows to print the screen and copy to the clipboard:

' Script to generate the keyboard input of print screen
Dim WB
Dim WshShell
Set WB = CreateObject("Word.Basic")
Set WshShell = CreateObject("WScript.Shell")
WB.SendKeys "%{prtsc}"    ' International usage: "%{1068}"
Set WB=Nothing
Set WshShell=Nothing


Note: In order to acquire the "print screen" copy to the clipboard for Windows machines running the VB script, Microsoft Word would need to be installed to execute the operation in the background. The English version of the code sends the keys "%{prtsc}" while international usage is "%{1068}".

A method CheckAppWindowFullScreen used in Windows to check if the application window is in full screen:

// ---------------------------------------------------------------------------
// Name: CheckAppWindowFullScreen
// Description: Method will determine if the 4D application window is in full
// screen either in the main screen or extended screen.
//
// Output:
// $0 (LONGINT) - Status of Application Window is full screen.
// 0 - Window is not full screen.
// 1 - Full screen on main.
// 2 - Full screen on extended.
// ---------------------------------------------------------------------------
C_LONGINT($num_screens;$width)
C_LONGINT($left;$top;$right;$bottom)
C_LONGINT($leftF;$topF;$rightF;$bottomF)
C_LONGINT($0)

$num_screens:=Count screens

GET WINDOW RECT($leftF;$topF;$rightF;$bottomF;-1)
$width:=Screen width

$0:=0 // Not full screen
For ($i;1;$num_screens)
   SCREEN COORDINATES($left;$top;$right;$bottom;$i)

   If (($right=$rightF) & (($bottom=$bottomF) | ($left=$leftF)))
      If ($right=Screen width)
         $0:=1 // Full screen on Main screen
      Else
         $0:=2 // Full screen on Extended screen
      End if
   End if
End for


Here is the complete method webAreaScreenCapture which is integrated for both plattforms:

// -------------------------------------------------------------------------------
// Name: webAreaScreenCapture
// Description: Method will take a screen shot of the Web Area and return as a
// picture.
//
// Parameters:
// $1 (Pointer) - Pointer to Web Area object
//
// Output:
// $0 (Picture) - Picture of the Web Area screen shot specified
// -------------------------------------------------------------------------------
C_POINTER($1;$webAreaPtr)
C_PICTURE($0;$temp_picture)
C_LONGINT($leftM;$topM;$rightM;$bottomM)
C_LONGINT($left;$top;$right;$bottom;$width;$height)

If (Count parameters=1)
   $webAreaPtr:=$1

   GET WINDOW RECT($leftM;$topM;$rightM;$bottomM;Frontmost window) // Coord. of Form
   OBJECT GET COORDINATES($webAreaPtr->;$left;$top;$right;$bottom) // Coord. of Web Area
   $width:=$right-$left
   $height:=$bottom-$top

   If (Folder separator=":") // Mac
    C_TEXT($cmd)

    $cmd:="screencapture -c -x"
    LAUNCH EXTERNAL PROCESS($cmd)
    GET PICTURE FROM PASTEBOARD($temp_picture)

    $width:=$width-15
    $height:=$height-15

    TRANSFORM PICTURE($temp_picture;Crop;$left+$leftM;$top+$topM;$width;$height)

    $0:=$temp_picture

   Else // Windows
    C_TEXT($vb_loc)

    $vb_loc:=Get 4D folder(Database folder)+"print_screen_shot.vbs"
    LAUNCH EXTERNAL PROCESS("wscript "+$vb_loc) // Calling the Print screen and save to clipboard

    DELAY PROCESS(Current process;10)
    GET PICTURE FROM PASTEBOARD($temp_picture)

     If(CheckAppWindowFullScreen=0)
    // When the Application is in Max mode
      TRANSFORM PICTURE($temp_picture;Crop;$leftM+$left+8;$topM+$top+30;$width-16;$height)
     Else
      TRANSFORM PICTURE($temp_picture;Crop;$leftM+$left;$topM+$top+22;$width-16;$height)
     End if
     $0:=$temp_picture
   End if
End If



Here are examples of using the method with three Web Area sizes:

C_Picture(Variable)

Variable:=webAreaScreenCapture(->Web Area)


Example #1


Example #2


Example #3


Commented by Angelo Caroprese on February 8, 2016 at 9:07 AM
If you are using Windows in a language other than English it is important to replace "prtsc" with "1068" in the 6th line of the VB script: WB.SendKeys "068}" Otherwise you will get an error. The reason is that within Windows the Print screen key has different names, for example in German would be druck instead of prtsc. Using the key number instead of the name makes sure the script works.