InfoConnect API Guide
Programming Concepts / Getting Terminal Controls and Views
In This Topic
    Getting Terminal Controls and Views
    In This Topic

    You'll need to create or get handles to InfoConnect  terminal controls and views for most of your applications:

    Refer to the following tables for ways to get and create terminal (control) and view objects.

    Getting Terminal Controls

    Getting Views

    Getting Terminal Controls

    The following methods can be used to get a handle to an existing control or to create a new control.

    Use this API call

    To get

    GetControlsByFilePath()

    A collection of open terminal emulation sessions. This method requires the path to a saved session document and returns a collection of all open emulation sessions that were created from that file.

    GetControlByInstanceId()

    An open terminal emulation session. This method requires the session's instance ID. A unique instance ID is created for a session each time you open the session document.

    CreateControl(filePath)

    A new terminal emulation session by specifying the file path for an existing session document.

    CreateControl(Guid controlType)

     

    A new terminal emulation session.

    Each session type requires a different GUID controlType.

    3270 (IBM): Guid("{09E5A1B4-0BA6-4546-A27D-FE4762B7ACE1}")

    5250 (IBM): Guid("{AF03A446-F278-4624-B9EF-C896DF2CA1CA}")

    UNIX and OpenVMS (OpenSystems): Guid("{BE835A80-CAB2-40d2-AFC0-6848E486BF58}")

    ReGIS Graphics (OpenSystems): Guid("{C62BA7E4-5A20-4681-931B-07BF7C971D13}")

     

     

     

     

    Getting Views

    Each of the following methods gets the View object associated with a control.

    When using this method

    Provide this parameter

    GetViewByTitleText()

    The Name property from the Tab Properties dialog box of the session document view. For example, GetViewByTitleText(MySession.rd3x).

    Note: To open the Tab Properties dialog box, right-click the session tab in the InfoConnect Workspace and choose Properties.

    GetViewByInstanceID()

    The API tab identifier number in the Tab Properties dialog box of the open session document. Each time you create a session document view, a new number is generated.

    (The API tab identifier of a View is different from that of the embedded control.)

    GetViewsByFilePath()

    The path to which the session or Web page document has been saved.

    Note: To re-create a View object after closing it, you must first re-create the control that will be associated with the View.

    Getting the View that has Focus

    This sample gets the host session document that has focus in the InfoConnect workspace by getting the view object for that session.

    Note: This program works only with host session documents; not Web page documents.

    1. In InfoConnect, create an IBM session and an Open Systems session and save these sessions as mySession.rd3x and mySession.rdox in the default folder. (...\myDocuments\Micro Focus\InfoConnect.)
    2. In Visual Studio, create a new Console Application project and add references for the following InfoConnect assemblies. (Depending on your version of Visual Studio, these can be found either on the .NET tab or under Assemblies | Extensions.)
      Attachmate.Reflection
      Attachmate.Reflection.Framework
      Attachmate.Reflection.Emulation.IbmHosts
      Attachmate.Reflection.Emulation.OpenSystems
    3. Paste the following code to the Program.cs file, replacing all existing code.
             
      Get the selected view
      Copy Code
      //This sample gets the selected view in a running InfoConnect workspace that has two running sessions.
      //If more than one instance of InfoConnect is running, the sessions must be running in the first instance that was started.
      
      using System;
      using System.Collections.Generic;
      using System.Text;
      using Attachmate.Reflection.Framework;
      using Attachmate.Reflection.Emulation.IbmHosts;
      using Attachmate.Reflection.Emulation.OpenSystems;
      using Attachmate.Reflection.UserInterface;
      namespace GetViewsByTitleText
      {
          class Program
          {
              static void Main(string[] args)
              {
                  //Get a handle to an application that represents the first instance of InfoConnect started manually.
                  //For production code, use a try catch block here to handle a System Application Exception thrown
                  //if the app isn't running.
                  Application app = MyReflection.CreateApplication();
      
                  //Get the frame and the selected view
                  IFrame frame = (IFrame)app.GetObject("Frame");
                  IView view = frame.SelectedView;
      
                  //If the IBM view is selected, get some text from its screen
                  if (view.TitleText == "mySession.rd3x")
                  {
                      IIbmTerminal terminalIBM = (IIbmTerminal)view.Control;
                      IIbmScreen screenIBM = terminalIBM.Screen;
                      Console.WriteLine(screenIBM.GetTextEx(1, 1, screenIBM.Rows, screenIBM.Columns, GetTextArea.Block, GetTextWrap.Off, GetTextAttr.Any, GetTextFlags.None));
                  }
                  //If the Open Systems view is selected, get some text from its screen
                  if (view.TitleText == "mySession.rdox")
                  {
                      ITerminal terminalOS = (ITerminal)view.Control;
                      IScreen screenOS = terminalOS.Screen;
                      Console.WriteLine(screenOS.GetText(1, 1, screenOS.DisplayRows, screenOS.DisplayColumns));
                  }
              }
          }
      }
      
      

    To test this project

    1. Close all instances of InfoConnect.
    2. Open InfoConnect and then open the mySession.rd3x and mySession.rdox sessions and select the IBM mySession.rd3x session.
    3. Run the project and verify that the text from the IBM session screen is written to the Console.
    4. Close your project application.
    5. Select the Open Systems mySession.rdox session
    6. Run the project again and verify that the text from the Open Systems session screen is written to the Console.

    Getting a View Using Title Text

    This sample gets both the Views and Controls for two sessions by referencing the title text of the Views.

    1. In InfoConnect, create an IBM session and an Open Systems session and save these sessions as mySession.rd3x and mySession.rdox in the default folder. (...\myDocuments\Micro Focus\InfoConnect.)
    2. In Visual Studio, create a new Console Application project and add references for the following InfoConnect assemblies. (Depending on your version of Visual Studio, these can be found either on the .NET tab or under Assemblies | Extensions.)
      Attachmate.Reflection
      Attachmate.Reflection.Framework
      Attachmate.Reflection.Emulation.IbmHosts
      Attachmate.Reflection.Emulation.OpenSystems
    3. Paste the following code to the Program.cs file, replacing all existing code.
         
      Get views by title text
      Copy Code
      //This sample gets the views of two sessions running in a  workspace.
      //If more than one instance of is running, the sessions must be running in the first instance that was started.
      
      using System;
      using System.Collections.Generic;
      using System.Text;
      using Attachmate.Reflection.Framework;
      using Attachmate.Reflection.Emulation.IbmHosts;
      using Attachmate.Reflection.Emulation.OpenSystems;
      using Attachmate.Reflection.UserInterface;
      namespace GetViewsByTitleText
      {
          class Program
          {
              static void Main(string[] args)
              {
                  //Get a handle to an application that represents the first instance of started manually.
                  //For production code, use a try catch block here to handle a System Application Exception thrown
                  //if the app isn't running.
                  Application app = MyReflection.CreateApplication();
                  IFrame frame = (IFrame)app.GetObject("Frame");
                  //Get the IBM view and then get some text from its screen
                  IView viewIBM = frame.GetViewByTitleText("mySession.rd3x");
                  if (viewIBM != null)
                  {
                      IIbmTerminal terminalIBM = (IIbmTerminal)viewIBM.Control;
                      IIbmScreen screenIBM = terminalIBM.Screen;
                      Console.WriteLine(screenIBM.GetTextEx(1, 1, screenIBM.Rows, screenIBM.Columns, GetTextArea.Block, GetTextWrap.Off, GetTextAttr.Any, GetTextFlags.None));
                  }
                  //Get the Open Systems view and then get some text from its screen
                  IView viewOS = frame.GetViewByTitleText("mySession.rdox");
                  if (viewOS != null)
                  {
                      ITerminal terminalOS = (ITerminal)viewOS.Control;
                      IScreen screenOS = terminalOS.Screen;
                      Console.WriteLine(screenOS.GetText(1, 1, screenOS.DisplayRows, screenOS.DisplayColumns));
                  }
              }
          }
      }
      
      

     

    To test this project

    1. Close all instances of InfoConnect.
    2. Open InfoConnect and then open the mySession.rd3x and mySession.rdox sessions
    3. Run the project and verify that the text from the IBM session screen and the Open Systems session screen is written to the Console.