2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Windows.Forms;
9 using System.Diagnostics;
10 using System.Runtime.InteropServices;
12 namespace SeciControls
23 public partial class ViHost : UserControl
25 Dictionary<string, TitleHandleTuple>
_viNames =
new Dictionary<string, TitleHandleTuple>();
26 Dictionary<string, string>
_formNames =
new Dictionary<string, string>();
27 public List<string>
ViNames {
get {
return _viNames.Keys.ToList<String>(); } }
31 BackgroundWorker
_worker =
new BackgroundWorker();
47 public void AddVI(String filename,
int x,
int y)
51 _viNames.Remove(filename);
54 Seci.Managers.LabViewMgr.ShowVI(filename);
57 Seci.Managers.LabViewMgr.UpdateFrontPanelTitle(filename);
60 System.Threading.Thread.Sleep(500);
68 WinApi.SetParent(viHandle.Handle, this.panel1.Handle);
76 _viNames.Add(filename, viHandle);
82 IntPtr viHandle = IntPtr.Zero;
84 viHandle =
_viNames[filename].Handle;
87 WinApi.SetParent(viHandle, IntPtr.Zero);
89 Seci.Managers.LabViewMgr.SetVisibilityToDefault(filename);
91 _viNames.Remove(filename);
101 foreach (String name
in ViNames)
109 String viTitle = Seci.Managers.LabViewMgr.GetFrontPanelTitle(viName);
121 IntPtr viHandle = WinApi.FindWindow(null, windowTitle);
123 if (viHandle == IntPtr.Zero)
126 windowTitle +=
" Front Panel";
127 viHandle = WinApi.FindWindow(null, windowTitle);
130 if (viHandle == IntPtr.Zero)
133 viHandle = WinApi.FindWindow(null, windowTitle);
136 if (viHandle != IntPtr.Zero)
146 Seci.Managers.LabViewMgr.MinimiseVI(filename);
147 Seci.Managers.LabViewMgr.RestoreVI(filename);
152 Seci.Managers.LabViewMgr.RestoreVI(filename);
153 Seci.Managers.LabViewMgr.SetFrontPanelBounds(filename,
new int[] { x, y });
158 Seci.Managers.LabViewMgr.ShowVI(filename);
166 this.panel1.HorizontalScroll.Value = 0;
167 this.panel1.VerticalScroll.Value = 0;
169 for (
int i = 0; i < ViNames.Count; ++i)
171 if (!Seci.Managers.LabViewMgr.IsVIHidden(
ViNames[i]))
192 foreach (String name
in ViNames)
194 if (Seci.Managers.LabViewMgr.DoesVIExist(name))
196 int[] bounds = Seci.Managers.ConfigurationMgr.GetConfigPanelPosition(name,
false);
198 if (bounds != null && bounds.Length == 2)
210 if (x - 1 == bounds[0] && y - 1 == bounds[1])
break;
225 foreach (String name
in ViNames)
231 if (Seci.Managers.LabViewMgr.DoesVIExist(name) && !Seci.Managers.LabViewMgr.IsVIHidden(name))
233 int length = WinApi.GetWindowTextLength(
_viNames[name].Handle.ToInt32()) + 1;
234 StringBuilder title =
new StringBuilder(length);
235 WinApi.GetWindowText(
_viNames[name].Handle.ToInt32(), title, length);
239 if (title.ToString().Trim() !=
_viNames[name].Title ||
_viNames[name].Handle == IntPtr.Zero)
243 if (viHandle != null)
245 WinApi.SetParent(viHandle.Handle, this.panel1.Handle);
246 _viNames[name].Handle = viHandle.Handle;
247 _viNames[name].Title = viHandle.Title.Trim();
250 int[] bounds = Seci.Managers.ConfigurationMgr.GetConfigPanelPosition(name,
true);
253 positionVi(name, bounds[0] - 1, bounds[1] - 1);
280 if (this.Handle != null)
282 _worker.RunWorkerAsync();
286 catch (Exception err)
295 if (this.InvokeRequired)
318 if (Seci.Managers.LabViewMgr.DoesVIExist(vi))
320 if (!Seci.Managers.LabViewMgr.IsVIHidden(vi))
335 Seci.Managers.ConfigurationMgr.SetConfigPanelPosition(vi, x, y);
338 int adjustedX = x + viRect.Width - viRect.X;
339 int adjustedY = y + viRect.Height - viRect.Y;
341 if (adjustedX > Xmax)
346 if (adjustedY > Ymax)
361 sizeMarker.Location =
new Point(Xmax, Ymax);
367 WinApi.GetWindowRect(
_viNames[vi].Handle, out viRect);
370 WinApi.GetWindowRect(this.Handle, out thisRect);
372 x = viRect.X - thisRect.X;
373 y = viRect.Y - thisRect.Y;
390 timer1.Interval = interval;
411 if (Seci.Managers.LabViewMgr.IsVIHidden(vi))
413 Seci.Managers.LabViewMgr.ShowVI(vi);
void SetVisible(Boolean visible)
void cascadeVIsToolStripMenuItem_Click(object sender, EventArgs e)
void updateHandles()
Unfortunately when a VI is started or stopped its window handle changes, so we have to update the sto...
void timer1_Tick(object sender, EventArgs e)
This method is called when the timer object "ticks."
Dictionary< string, TitleHandleTuple > _viNames
void StartTimer(int interval)
void InitializeComponent()
Required method for Designer support - do not modify the contents of this method with the code editor...
void RemoveVI(String filename)
void _worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
void bringViToFront(String filename)
static TitleHandleTuple getHandle(String windowTitle)
Get the window handle of the VI based on the window's title.
void repaintVi(String filename)
static TitleHandleTuple findViHandle(String viName)
void moveVisToConfigPositions()
When the configuration is loaded it is necessary to move the VIs to the positions saved in the config...
void positionVi(String filename, int x, int y)
void getVIPosition(string vi, out WinApi.Rect viRect, out int x, out int y)
void _worker_DoWork(object sender, DoWorkEventArgs e)
delegate void UpdateGuiDelegate()
void AddVI(String filename, int x, int y)
This method captures the VI and inserts it into the MDI using the WinAPI.
Dictionary< string, string > _formNames
TitleHandleTuple(String title, IntPtr handle)