I'm trying to resize an open window and as there seems to be no way to do this in Wonderware Application Server I thought maybe a .Net function may work. I've used the System.Windows.Forms.MessageBox.Show script below in the Wonderware Application Server with a button activation script. Is there a similar function to simple change the Hight and Width of the currently active window?
The message box is just an example that the Wonderware Application Server application can access some System.Windows.Forms functions in it's QuickScript.NET scripting. The Windows Forms library (system.windows.forms.dll) was imported into the Wonderware Application Server application. The script would be running on an open window and I'd like to resize it but I can't get the .Net size function to work in QuickScript.NET.
Found this System Platform DLL example http://www.plctalk.net/qanda/showthread.php?t=114301 but Visual Studio has like 20 different Class Library templates. If I try the Class Library (.Net Framework) - C# template I get a dll and can import it into System Platform, I can then find the function in the Function Browser but nothing happens in runtime when the script is run and I get this error in the SMC log: Script execution exception.Message: Non-static method requires a target..
Demo - Visual Studio 2019 and the Class Library (.Net Framework) - C# template code:
namespace ClassLibraryDemo
{
public class DemoClass
{
public int GetAdd(int a, int b)
{
return a + b;
}
}
}
Demo - System Platform Button Script - For this demo code it now works with the cls = new line added.
dim cls as ClassLibraryDemo.DemoClass;
cls = new ClassLibraryDemo.DemoClass();
Me.°Test = cls.GetAdd(Me.°Test,3);
Unfortunately, the resize code that I need still has the Non-static error and it already has the object equals new line.
ResizableForm - Visual Studio 2019 and the Class Library (.Net Framework) - C# template code:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ClassLibraryROB4
{
public class ResizableForm
{
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
public Form GetCurrentWindow()
{
IntPtr activeWindowHandle = GetForegroundWindow();
Form f = Control.FromHandle(activeWindowHandle) as Form;
return f;
}
}
}
ResizableForm - System Platform Button Script. Now with Try-Catch
Try
Dim myLib As ClassLibraryROB4.ResizableForm;
Dim myGfc As System.Windows.Forms.Form;
myLib = new ClassLibraryROB4.ResizableForm();
myGfc = myLib.GetCurrentWindow();
myGfc.Width = 10;
myGfc.Height = 10;
catch LogError(error); endtry;
SMC Error - Try-Catch
A900.Faceplate1_Control.BUTTON2: System.Reflection.TargetException: Non-static method requires a target.
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at ArchestrA.QuickScript.EvaluateFunction.Evaluate(IReferenceManagerRuntime rmr)
at ArchestrA.QuickScript.RunExpressionStatement.Run(RuntimeContext context)
at ArchestrA.QuickScript.RunStatements.Run(RuntimeContext context)
at ArchestrA.QuickScript.RunTryCatch.Run(RuntimeContext context)
If you're willing to dabble in using Script Function libraries you can write a utility to make graphics expandable.
I got the original tutorial from this site if you search for "Expandable Popups in Wonderware ArchestrA" but it looks like they're moving their tutorials behind a signup page.
#1 - Create your Script Function library.
I wrote very basic Class library in Visual Studio using C# which looks like this:
#2 - Import to ArchestrA
From the IDE main window:
Galaxy -> Import -> Script Function Library...
Then select the .dll that you built from #1
#3 - ArchestrA Graphic Script
When calling the graphic you want to resize, make sure you're setting an explicit Width/Height on it, then you can dynamically resize it by putting something to trigger a script like this:
...and I think that's it. Hopefully that gets you far enough along that you can toy with the rest. I do recommend going through the EverDyn site's tutorial for better examples/details.
EDIT: I guess I should just mention that the
GetCurrentWindow()
call is super powerful to have in ArchestrA graphics. I use another Script to get a handle of the current graphic and call some .NET functions to print the current window to a dynamically chosen printer so my clients can create labels to stick to things. Basically if you can get the Form handle from this function you can use most .NET libraries to manipulate it how you're wanting. Good luck!CODE EDIT AS PER COMMENT: