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. This 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:
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.
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 28th, 2020 at 5:16 am
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.
March 29th, 2020 at 11:10 am
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.
March 30th, 2020 at 8:00 pm
Thank you very much!