Purpose You want to capture a screenshot of a control that you have created with the "Control" statement. |
Solution
The screenshot is saved as an image file and you can use it in the same
InputScript, for example to build up an MS Word file for or a PDF file.
InputScript // open an invisible HTML control with a webcam URL Control (1,1) (30,200) _ name="mycontrol" _ progID="https://www.foto-webcam.eu/webcam/funtenseetauern/" _ -floating -invisible // wait until HTML page is complete // capture a screenshot // close the control // open a blank HTML control name="mycontrol" _ progID="about:blank" _ -floating -invisible // generate a chart via JavaScript // capture a screenshot // close the control // we now can use the two image files for further actions ...
VB.NET
Imports System Imports System.IO Imports System.Drawing Imports System.Drawing.Imaging Imports System.Windows.Forms Imports SHDocVw Public Class control Public Structure RECT Public left As Integer Public top As Integer Public right As Integer Public bottom As Integer End Structure Public Enum WINDOWSTAT As Integer SW_HIDE = 0 SW_NORMAL = 1 End Enum ' Windows functions Private Declare Function GetWindowRect Lib "user32.dll" _ (ByVal hWnd As IntPtr,_ ByRef lpRect As RECT) As Boolean Private Declare Function PrintWindow Lib "user32.dll" _ (ByVal hwnd As IntPtr, ByVal hDC As IntPtr, _ ByVal nFlags As UInteger) As Boolean Private Declare Function ShowWindow Lib "user32.dll" _ (ByVal hWnd As IntPtr, _ ByVal nCmdShow As Integer) As Boolean Private Declare Function InvalidateRect Lib "user32.dll" _ (ByVal hWnd As IntPtr, ByVal lpRect As IntPtr, _ ByVal bErase As Boolean) As Boolean Private Declare Function MoveWindow Lib "user32.dll" _ (ByVal hWnd As IntPtr, _ ByVal X As Int32, _ ByVal Y As Int32, _ ByVal Width As Int32, _ ByVal Height As Int32, ByVal Repaint As Boolean) As Boolean Private Declare Function IsWindowVisible Lib "user32.dll" _ (ByVal hwnd As Long) As Boolean ' wait until web browser page is fully loaded Public Sub wbComplete(ie As SHDocVw.WebBrowser) Try While ie.Busy OrElse _ ie.ReadyState <> tagREADYSTATE.READYSTATE_COMPLETE System.Threading.Thread.Sleep(10) Application.DoEvents() End While Catch ex As Exception MsgBox(ex.Message) End Try End Sub ' capture window screenshot Public Sub capture(charhwnd As String, filename As String) Try Dim hwnd As Integer = CInt(charhwnd) ' get window size Dim r As New RECT GetWindowRect(hwnd, r) Dim image As Image = _ New Bitmap(r.right - r.left, r.bottom - r.top) Dim screenshot As Graphics = Graphics.FromImage(image) Dim isHidden As Boolean = Not IsWindowVisible(hwnd) If isHidden Then ' move window out of screen to avoid flickering MoveWindow(hwnd, r.left, r.top + 8000, _ r.right - r.left, r.bottom - r.top, True) ' make window visible ShowWindow(hwnd, WINDOWSTAT.SW_NORMAL) End If InvalidateRect(hwnd, IntPtr.Zero, True) Application.DoEvents() ' print client area of window to bitmap Dim PW_CLIENTONLY As Integer = 1 PrintWindow(hwnd, screenshot.GetHdc, PW_CLIENTONLY) screenshot.ReleaseHdc() If isHidden Then ' hide window ShowWindow(hwnd, WINDOWSTAT.SW_HIDE) ' restore window position MoveWindow(hwnd, r.left, r.top, _ r.right - r.left, r.bottom - r.top, True) Application.DoEvents() End If image.Save(filename, _ System.Drawing.Imaging.ImageFormat.Png) Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class |
Components |