InfoConnect for Unisys
Attachmate.Reflection.Productivity Namespace / IScreenHistory Interface / GetLiveScreenImage Method

In This Topic
    GetLiveScreenImage Method
    In This Topic
    Returns the live screen as an image.
    Function GetLiveScreenImage() As Byte()
    Dim instance As IScreenHistory
    Dim value() As Byte
    value = instance.GetLiveScreenImage()
    byte[] GetLiveScreenImage()

    Return Value

    The live screen, in image format.
    Returned images are subject to currently enforced privacy filters.

    This method can be used in conjunction with the NewScreenReady event to build a list of screen images.

    The returned image can be used in conjunction with the Productivity.OfficeTools CreateWordProcessingDocumentWithGraphicSet method if the installed Office Suite and Office Tools adapter assembly support the use of graphics in word-processing documents.

    Returns the live screen as an image.
    This samples handles the NewScreenReady event and GetLiveScreenImage to create a list of screen images that include only screens on the Kayak program. Then it uses the CreateWordProcessingDocumentWithGraphicSet method to save the images in a Word document.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Attachmate.Reflection.UserInterface;
    using Attachmate.Reflection.Productivity;
    using Attachmate.Reflection.Emulation.IbmHosts;
    using Attachmate.Reflection.Framework;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using Word = Microsoft.Office.Interop.Word;
    namespace ScreenHistory
        class Program
            static private List<Image> _screenImages = new List<Image>();
            static public List<Image>  ScreenImages
                get { return _screenImages; }
                set { _screenImages = value; }
            static void terminal_BeforeDisconnect(object sender, EventArgs e)
                IIbmTerminal terminal = (IIbmTerminal)sender;
                IScreenHistory history = terminal.Productivity.ScreenHistory;
                if (history.Count > 0)
                    IOfficeTools tools = terminal.Productivity.OfficeTools;
                    tools.CreateWordProcessingDocumentWithGraphicSet(ScreenImages, null, null);
                    string screenLog = Environment.UserName + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".docx";
                    Word.Application word = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
                    word.ActiveDocument.SaveAs(Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\" + screenLog);
                    history.SaveScreenHistoryFile(Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Micro Focus\InfoConnect\myScreens.rshx", true);
            static void Main(string[] args)
                //Start a visible instance of InfoConnect or get the instance running at the given channel name
                Application app = MyReflection.CreateApplication("myWorkspace", true);
                //Create a terminal from the session document file
                string sessionPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Micro Focus\InfoConnect\demoSession.rd3x";
                IIbmTerminal terminal = (IIbmTerminal)app.CreateControl(sessionPath);
                //Make the session visible in the workspace
                IFrame frame = (IFrame)app.GetObject("Frame");
                IScreenHistory history = terminal.Productivity.ScreenHistory;
                history.ManualCaptureOnly = true;
                history.ScreenHistoryPanelVisible = true;
                history.NumberOfScreensToRemember = 25;
                history.ClearHistoryOnDisconnect = false;
                terminal.Screen.NewScreenReady += Screen_NewScreenReady;
                terminal.BeforeDisconnect += terminal_BeforeDisconnect;
            static void Screen_NewScreenReady(object sender, EventArgs e)
                IIbmScreen screen = (IIbmScreen) sender;
                Console.WriteLine(screen.GetText(1, 25, 30));
                if (screen.GetText(1, 25, 30).Contains("KAYAK"))
                    IScreenHistory history = screen.Parent.Productivity.ScreenHistory;
                    //Add to the ScreenImages list
                    byte[] screenImage = history.GetLiveScreenImage();
                    MemoryStream memstr = new MemoryStream(screenImage);
                    Image image = Image.FromStream(memstr);
    See Also