4D currently can take a screen shot of a form using FORM SCREENSHOT. But how about taking the whole screen shot of the monitor(s)? This would be effective if there is an error in the database and using ON ERR CALL would be a nice location to take such a screen shot for diagnostic analysis. This can be accomplished by using LAUNCH EXTERNAL PROCESS. The mac has a built in command to generate a screen shot and save it as a file. For Windows, typically a screen shot can be copied through a clip board using the print screen key and then pasted to a program like MS Paint where it can be saved. A way to automate that process would be to use a Visual Basic script to mimic a print screen keyboard input and paste to MS Paint to save it to a file. The limitation is that the script will open MS Paint and see the process of pasting and saving. A sample method below can be used for the automation on both platforms:
// ------------------------------------------------------------------ // Name: print_save_screen_shot // Description: Takes a path to save the screen shot image which will // be in JPEG format. The Mac uses a single command via LEP while // Windows uses two LEP calls for the screen shot keyboard input // and MS Paint to save the image. Image is saved with the date and // time. E.g. 2014-09-18T14_34_41.jpg // // Input Parameter: // $1 (TEXT) - Path location for the image file // ------------------------------------------------------------------ C_TIME(vhDoc) C_TEXT($1;$file_loc;$vb_loc1;$vb_loc2) // File location appending the date and time $file_loc:=String(Current date;ISO date;Current time) $file_loc:=Replace string($file_loc;":";"_") $file_loc:=$1+$file_loc+".jpg" If (Count parameters=1) If (Folder separator=":") // Mac $file_loc:=Convert path system to POSIX($file_loc) LAUNCH EXTERNAL PROCESS("screencapture "+$file_loc) Else // Windows $vb_loc1:=Get 4D folder(Database folder)+"print_screen_shot.vbs" $vb_loc2:=Get 4D folder(Database folder)+"save_screen_shot.vbs" LAUNCH EXTERNAL PROCESS("wscript "+$vb_loc1) // Calling the Print screen DELAY PROCESS(Current process;10) LAUNCH EXTERNAL PROCESS("wscript "+$vb_loc2+" "+$file_loc) // Saving the file End if End if |
VBscript for printing the screen "print_screen_shot_vbs":
' 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}" Set WB=Nothing Set WshShell=Nothing |
VBscript for printing the screen "save_screen_shot_vbs":
' Script for Saving the Screen shot in Paint Dim WshShell set Wshshell = WScript.CreateObject("WScript.Shell") Wshshell.Run "mspaint" WshShell.AppActivate"untitled - Paint" WScript.Sleep 500 WshShell.sendkeys"^(v)" WScript.Sleep 1000 WshShell.sendkeys"^(s)" WScript.Sleep 500 WshShell.sendkeys Wscript.Arguments.Item(0) WScript.Sleep 500 WshShell.sendkeys"%(s)" WScript.Sleep 500 WshShell.sendkeys"y {ENTER}" WScript.Sleep 500 WshShell.sendkeys"%{F4}" Set WshShell=Nothing WScript.Quit |
Example of running the method:
C_TEXT($loc) $loc:=GET 4D FOLDER(Database folder) print_save_screen_shot($loc) |