Using the InTouch Script Toolkit to get design time window offsets

Well that title is quite a mouth full, so perhaps I should explain what is going on here.  During the course of a previous post I created an InTouch application that worked on multiple monitors.  An improvement on that application was to create a Quick Function MMPopup(WindowName as Message) such that it shows a popup window using the offsets specified at design time, but on the correct monitor. itstk6This seems like a trivial problem at first glance, but on closer inspection it is not so straightforward.  There is no way to get the design time window offset, without showing the window and getting it from GetWindowPosition().  This is a truly abominable approach, and I found it worked poorly at best.  I decided that this information could surely be obtained from the *.win file, and so set about reverse engineering the file format to a point where I could get this data.  It proved to be a fairly straightforward task, but as it involves reading and converting binary data it can't be done inside a simple QF.  Hence I set about obtaining the script toolkit (part of the FSK2000 toolkit) which my local Wonderware distributor kindly supplied.

The script toolkit was developed sometime last century, probably with VC6 in mind and as far as I know has not been updated since.  Thankfully everything still works rather well using the more modern tooling of Visual Studio 2015, where I proceeded to create a project for my new script library.  There are a few important notes when setting up a project for this:

  • You will almost certainly be using a different C runtime than the other script function libraries, and possibly InTouch.  Try to match the runtime for your version of InTouch if possible.  This can be important!itstk5
  • Disable SafeSEHitstk3
  • Set the code to be compiled as C (not C++)itstk2
  • Consider using static linking if your script function library is basic, to save redistributing the c runtime librariesitstk1

Once you have compiled the library, you need to create the .idf and .wdf files so that window maker/viewer know about the library.  Awesomely the CRYPT program that creates the .wdf file is 16bit, so as you are of course running a modern 64 bit OS you will probably need to get a copy of WindowsXPMode, spin up a Hyper-V  VM and run it there.
itstk4
I considered reverse engineering the encryption algorithm but I'll save it for another day.  See the Wonderware FactorySuite 2000 InTouch Extensibility Toolkit documentation (fs2ktoolkit.pdf) for details on the file format for the .idf file.  The CRYPT tool is quite fussy about the format of the idf file and will give you no feedback as to what is wrong, it will simply not produce any output.  In particular I suspect that the library name must be under 8 characters.  I found it was easiest to start with the template file from the toolkit and change one parameter at a time to debug problems.

See the script function library that I created here as an example, it provides one function ReadWindowLocation that reads the window offsets as mentioned and writes them into the tags provided.

DIM result as INTEGER;
result = ReadWindowLocation(InfoInTouchAppDir(), "MyWindow", XTag.Name, YTag.Name);

This can be used to create a MMPopup(WindowName AS Message) QF

DIM WinState AS INTEGER;
DIM Result AS INTEGER;
DIM X AS REAL;
DIM Y AS REAL;
WinState = WindowState(WindowName);
IF WinState == 2 THEN
  RETURN 0;
ENDIF;
result = ReadWindowLocation(InfoInTouchAppDir(), WindowName, SysWinLeft.Name, SysWinTop.Name);
IF result == 0 THEN
  X = SysWinLeft;
  Y = SysWinTop;
  {Need to check that we are running at the native resolution, and if not then scale the offsets as necessary}
  IF SysMonitorWidth <> SysNativeResolutionX THEN
    X = X / SysNativeResolutionX * SysMonitorWidth;
    Y = Y / SysNativeResolutionY * SysMonitorHeight;
  ENDIF;
  IF $ObjHor > SysMonitorWidth THEN
    ShowTopLeftAt(WindowName, X + SysMonitorWidth, Y);
  ELSE
    ShowTopLeftAt(WindowName, X, Y);
  ENDIF;
ELSE
  {ReadWindowLocation failed, so just show the window}
  Show WindowName;
ENDIF;

 

 

| March 11th, 2016 | Posted in SCADA |

3 Responses to “Using the InTouch Script Toolkit to get design time window offsets”

  1. Michele Says:

    Hello Raggles,
    Congratulations for this website and for this article!!!
    I write to you because I will develop an Intouch standalone Application with 2014 R2 SP1 version and i would add some custom function to intouch script.
    Some of your article's link seems don't work anymore, anyway have you some document or example to share? and where i can find the factory suite toolkit installer?
    Thank you very much!
    best regards
    Michele.

  2. Raggles Says:

    Hi, you can find the source for an example script function library at https://github.com/Raggles/mmInTouchSFL, the toolkits you can probably get from the AVEVA software support portal.

  3. Michele Says:

    Thank you very much!

Leave a Reply