SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
DaeHost.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 
10 namespace SeciControls
11 {
12  public partial class DaeHost : UserControl
13  {
14  private string _filename;
15  private bool _firstChange = true;
16  private int _firstXmax = 0;
17  private int _firstYmax = 0;
18  private Point _sensiblePt;
19  private bool _useScrollbars = false;
20  private IntPtr _viHandle;
21  private string _winTitle;
22 
23  public DaeHost()
24  {
26  _sensiblePt = this.PointToScreen(this.Location);
27  }
28 
29  public void AddDaeVi()
30  {
31  Seci.Standard.Dae.ShowDae();
32  Seci.Standard.Dae.SetTitleBarVisibility(false);
33 
34  //LockWindowUpdate(GetDesktopWindow());
35  System.Threading.Thread.Sleep(2000);
36 
37  _filename = Seci.Definitions.Status.LabViewDir + Seci.Definitions.Status.DaeFile;
38  findViHandle(_filename);
39  WinApi.SetParent(_viHandle, this.panel1.Handle);
40  repaintVi(_filename);
41  repositionVi(_filename, 0, 0);
42  int[] bounds = Seci.Managers.LabViewMgr.GetPanelBounds(_filename);
43  MaximumSize = new Size(bounds[2] - bounds[0], bounds[3] - bounds[1]);
44  timer1.Start();
45  }
46 
47  private void bringViToFront(string filename)
48  {
49  Seci.Standard.Dae.ShowDae();
50  }
51 
52  public void CascadeVi()
53  {
54  panel1.HorizontalScroll.Value = 0;
55  panel1.VerticalScroll.Value = 0;
56  if (!Seci.Managers.LabViewMgr.IsVIHidden(_filename))
57  {
58  repositionVi(_filename, 0, 0);
60  }
61  }
62 
63  private void findViHandle(string viName)
64  {
65  string viTitle = Seci.Managers.LabViewMgr.GetFrontPanelTitle(viName);
66  IntPtr viHandle = IntPtr.Zero;
67  StringBuilder title = new StringBuilder(50);
68  new WinApi.EnumReport().GetEnums();
69  for (int i = 0; i < WinApi.EnumReport.Handles.Count; i++)
70  {
71  title = new StringBuilder(50);
72  WinApi.GetWindowText(WinApi.EnumReport.Handles[i], title, 50);
73  if (title.ToString().StartsWith(viTitle))
74  {
75  string answer = title.ToString();
76  viHandle = new IntPtr(WinApi.EnumReport.Handles[i]);
77  break;
78  }
79  }
80  _winTitle = title.ToString();
81  _viHandle = viHandle;
82  }
83 
84  public void RemoveDaeVi()
85  {
86  WinApi.SetParent(_viHandle, IntPtr.Zero);
87  timer1.Stop();
88  }
89 
90  private void repaintVi(string filename)
91  {
92  Seci.Managers.LabViewMgr.MinimiseVI(filename);
93  Seci.Managers.LabViewMgr.RestoreVI(filename);
94  }
95 
96  private void repositionVi(string filename, int x, int y)
97  {
98  Seci.Managers.LabViewMgr.RestoreVI(filename);
99  Seci.Managers.LabViewMgr.SetFrontPanelBounds(filename, new int[] { x, y });
100  }
101 
102  private void timer1_Tick(object sender, EventArgs e)
103  {
104  if (_useScrollbars)
105  {
106  int Xmax = 0;
107  int Ymax = 0;
108  if (Seci.Managers.LabViewMgr.DoesVIExist(_filename) && !Seci.Managers.LabViewMgr.IsVIHidden(_filename))
109  {
110  int[] limits = Seci.Managers.LabViewMgr.GetPanelBounds(_filename);
111  if (limits[2] > Xmax)
112  {
113  Xmax = limits[2];
114  }
115  if (limits[3] > Ymax)
116  {
117  Ymax = limits[3];
118  }
119  }
120  if (_firstChange)
121  {
122  if ((_firstXmax == 0) && (_firstYmax == 0))
123  {
124  _firstXmax = Xmax;
125  _firstYmax = Ymax;
126  }
127  else if ((Xmax != _firstXmax) && (Ymax != _firstYmax))
128  {
129  _firstChange = false;
130  _sensiblePt = base.PointToScreen(base.Location);
131  }
132  }
133  else
134  {
135  _sensiblePt = base.PointToScreen(base.Location);
136  }
137  }
138  updateHandles();
139  }
140 
141  private void updateHandles()
142  {
143  if (Seci.Managers.LabViewMgr.DoesVIExist(_filename))
144  {
145  StringBuilder title = new StringBuilder(50);
146  WinApi.GetWindowText(_viHandle.ToInt32(), title, 50);
147  if (title.ToString().Trim() != _winTitle)
148  {
150  WinApi.SetParent(_viHandle, this.panel1.Handle);
151  _winTitle = title.ToString().Trim();
152  repositionVi(_filename, 0, 0);
153  int[] bounds = Seci.Managers.LabViewMgr.GetPanelBounds(_filename);
154  MaximumSize = new Size(bounds[2] - bounds[0], bounds[3] - bounds[1]);
155  base.Size = MaximumSize;
156  }
157  }
158  }
159 
160  }
161 }
void repaintVi(string filename)
Definition: DaeHost.cs:90
void bringViToFront(string filename)
Definition: DaeHost.cs:47
void repositionVi(string filename, int x, int y)
Definition: DaeHost.cs:96
void updateHandles()
Definition: DaeHost.cs:141
void findViHandle(string viName)
Definition: DaeHost.cs:63
void timer1_Tick(object sender, EventArgs e)
Definition: DaeHost.cs:102
void RemoveDaeVi()
Definition: DaeHost.cs:84
void InitializeComponent()
Required method for Designer support - do not modify the contents of this method with the code editor...