diff --git a/Supervisor.Plugin.Interface/IHost.vb b/Supervisor.Plugin.Interface/IHost.vb
index abcd531..d0f2e67 100644
--- a/Supervisor.Plugin.Interface/IHost.vb
+++ b/Supervisor.Plugin.Interface/IHost.vb
@@ -10,6 +10,8 @@ Public Interface IHost
Function PlgGetPrivateProfileString(lpAppName As String, lpKeyName As String, lpDefault As String, ByRef lpString As String, lpFileName As String) As Integer
Function PlgWritePrivateProfileString(lpAppName As String, lpKeyName As String, lpString As String, lpFileName As String) As Boolean
Function PlgExecProcess(sFileName As String, sMainLuaPath As String, sArguments As String) As Boolean
+ Function PlgExecProcessAsync(sFileName As String, sMainLuaPath As String, sArguments As String) As Boolean
+ Function PlgCheckExecProcessAsync(ByRef bHasExited As Boolean, ByRef nExitCode As Integer) As Boolean
Function ComReadShortVar(nVarAddr As Integer, ByRef nResult As Short, nMachine As Integer) As Boolean
Function ComReadBitVar(nVarAddr As Integer, nBit As Integer, ByRef bResult As Boolean, nMachine As Integer) As Boolean
Function ComReadDoubleVar(nVarAddr As Integer, ByRef dResult As Double, nMachine As Integer) As Boolean
diff --git a/Supervisor/Comms/MachineManager.vb b/Supervisor/Comms/MachineManager.vb
index 7a511e7..a0a1158 100644
--- a/Supervisor/Comms/MachineManager.vb
+++ b/Supervisor/Comms/MachineManager.vb
@@ -36,7 +36,7 @@ Public Class MachineManager
If sMachineSplit.Count >= 2 AndAlso Not String.IsNullOrWhiteSpace(sMachineSplit(1)) Then
Dim NewOsaiOpen As New NC.OsaiOpen
NewOsaiOpen.Connect(sMachineSplit(1))
- m_MachineList(nMachineIndex) = NewOsaiOpen
+ m_MachineList(nMachineIndex - 1) = NewOsaiOpen
End If
End Select
End If
diff --git a/Supervisor/Constants/ConstIni.vb b/Supervisor/Constants/ConstIni.vb
index 532396a..de10007 100644
--- a/Supervisor/Constants/ConstIni.vb
+++ b/Supervisor/Constants/ConstIni.vb
@@ -25,6 +25,7 @@ Module ConstIni
Public Const K_MACHINESTATE As String = "MachineState"
Public Const K_INITLUA As String = "InitLua"
Public Const K_PLUGINNAME As String = "PluginName"
+ Public Const K_WINPLACE = "WinPlace"
Public Const S_REDIS As String = "Redis"
Public Const K_ENABLED As String = "Enabled"
diff --git a/Supervisor/FiniteStateMachine.vb b/Supervisor/FiniteStateMachine.vb
index 604bcc5..8ee2764 100644
--- a/Supervisor/FiniteStateMachine.vb
+++ b/Supervisor/FiniteStateMachine.vb
@@ -1,6 +1,14 @@
Public Class FiniteStateMachine
+ Private m_bLuaExecuted As Boolean
+ Public ReadOnly Property bLuaExecuted As Boolean
+ Get
+ Return m_bLuaExecuted
+ End Get
+ End Property
+
Private m_State As Integer
+
Private m_sLuaPath As String
Friend ReadOnly Property sLuaPath As String
Get
@@ -10,7 +18,8 @@
Sub New(sLuaPath As String)
m_sLuaPath = sLuaPath
- LuaManager.ExecFile(Map.refMainWindowVM.MainWindowM.sScriptDir & "\" & sLuaPath)
+ m_bLuaExecuted = LuaManager.ExecFile(Map.refMainWindowVM.MainWindowM.sScriptDir & "\" & sLuaPath)
+ EgtOutLog(m_sLuaPath & " execution " & If(m_bLuaExecuted, "ok", "failed"))
End Sub
End Class
diff --git a/Supervisor/FiniteStateMachineManager/FiniteStateMachineManager.vb b/Supervisor/FiniteStateMachineManager/FiniteStateMachineManager.vb
index 9b4db36..d6e0a71 100644
--- a/Supervisor/FiniteStateMachineManager/FiniteStateMachineManager.vb
+++ b/Supervisor/FiniteStateMachineManager/FiniteStateMachineManager.vb
@@ -66,8 +66,11 @@ Public Class FiniteStateMachineManager
'm_bFiniteStateMachineExecuting = True
' lancio esecuzione macchine a stati
For nMachineIndex = 0 To m_FiniteStateMachineList.Count - 1
- LuaManager.ExecLuaFunction("MACHINE" & (nMachineIndex + 1).ToString() & "_Tick", -1, Nothing)
+ If m_FiniteStateMachineList(nMachineIndex).bLuaExecuted Then
+ LuaManager.ExecLuaFunction("MACHINE" & (nMachineIndex + 1).ToString() & "_Tick", -1, Nothing)
+ End If
Next
+
'' lancio esecuzione preprocessore
'LuaManager.SetGlobVar("PREPROC.ERROR", 0)
'LuaManager.SetGlobVar("PREPROC.ERROR_MSG", "")
diff --git a/Supervisor/LUA/Lua_Aux.vb b/Supervisor/LUA/Lua_Aux.vb
index 31a7fe6..912b201 100644
--- a/Supervisor/LUA/Lua_Aux.vb
+++ b/Supervisor/LUA/Lua_Aux.vb
@@ -107,6 +107,20 @@ Public Module Lua_Aux
Return True
End Function
+ Friend Function LuaSetParam(state As Lua, ByRef sValue() As String) As Boolean
+ Try
+ Dim nSize As Integer = sValue.Count()
+ state.CreateTable(nSize, 0)
+ For nIndex = 0 To nSize - 1
+ state.PushString(sValue(nIndex))
+ state.RawSetInteger(-2, nIndex)
+ Next
+ Catch ex As Exception
+ Return False
+ End Try
+ Return True
+ End Function
+
Friend Function LuaGetTabFieldParam(state As Lua, nIndex As Integer, sVarName As String, ByRef bValue As Boolean) As Boolean
If Not state.IsTable(nIndex) Then Return False
state.GetField(nIndex, sVarName)
diff --git a/Supervisor/LUA/Lua_General.vb b/Supervisor/LUA/Lua_General.vb
index 91e09a1..d5b1b5b 100644
--- a/Supervisor/LUA/Lua_General.vb
+++ b/Supervisor/LUA/Lua_General.vb
@@ -31,6 +31,7 @@ Public Module Lua_General
Friend func_EntGetNumberFromIni As LuaFunction = AddressOf Lua_EntGetNumberFromIni
Friend func_EntGetStringFromIni As LuaFunction = AddressOf Lua_EntGetStringFromIni
Friend func_EntWriteStringToIni As LuaFunction = AddressOf Lua_EntWriteStringToIni
+ Friend func_EntSplitString As LuaFunction = AddressOf Lua_EntSplitString
Friend func_EntExecProcess As LuaFunction = AddressOf Lua_EntExecProcess
Friend func_RdsStringGet As LuaFunction = AddressOf Lua_RdsStringGet
Friend func_RdsStringSetAsync As LuaFunction = AddressOf Lua_RdsStringSetAsync
@@ -129,9 +130,9 @@ Public Module Lua_General
LuaCheckParam(state, 3, dDef)
LuaCheckParam(state, 4, sIniFile)
LuaClearStack(state)
- Dim nResult As Integer = GetPrivateProfileInt(sSec, sKey, dDef, sIniFile)
+ Dim dResult As Double = GetPrivateProfileDouble(sSec, sKey, dDef, sIniFile)
' restituisco il risultato
- LuaSetParam(state, nResult)
+ LuaSetParam(state, dResult)
Return 1
End Function
@@ -172,6 +173,20 @@ Public Module Lua_General
Return 1
End Function
+ Private Function Lua_EntSplitString(ByVal p As IntPtr) As Integer
+ Dim state = Lua.FromIntPtr(p)
+ ' 4 parametri: sSec, sKey, sVal, sIniFile
+ Dim sVal As String = ""
+ Dim sSeparator As Char = ","c
+ LuaCheckParam(state, 1, sVal)
+ LuaGetParam(state, 2, sSeparator)
+ LuaClearStack(state)
+ Dim sSplitString() As String = sVal.Split(sSeparator)
+ ' restituisco il risultato
+ LuaSetParam(state, sSplitString)
+ Return 1
+ End Function
+
Private Function Lua_RdsStringGet(ByVal p As IntPtr) As Integer
Dim state = Lua.FromIntPtr(p)
If IsNothing(Map.refMainWindowVM.RedisManager) OrElse IsNothing(Map.refMainWindowVM.RedisManager.Subscriber) Then
@@ -359,6 +374,7 @@ Public Module Lua_General
state.Register("EntGetNumberFromIni", func_EntGetNumberFromIni)
state.Register("EntGetStringFromIni", func_EntGetStringFromIni)
state.Register("EntWriteStringToIni", func_EntWriteStringToIni)
+ state.Register("EntSplitString", func_EntSplitString)
state.Register("EntExecProcess", func_EntExecProcess)
state.Register("RdsStringGet", func_RdsStringGet)
state.Register("RdsStringSetAsync", func_RdsStringSetAsync)
diff --git a/Supervisor/MEFPlugin/SupervisorFunctions.vb b/Supervisor/MEFPlugin/SupervisorFunctions.vb
index 38b275e..17227bc 100644
--- a/Supervisor/MEFPlugin/SupervisorFunctions.vb
+++ b/Supervisor/MEFPlugin/SupervisorFunctions.vb
@@ -32,6 +32,15 @@ Public Class SupervisorFunctions
Public Function PlgExecProcess(sFileName As String, sMainLuaPath As String, sArguments As String) As Boolean Implements IHost.PlgExecProcess
Return ExecProcessManager.ExecProcess(sFileName, sMainLuaPath, sArguments)
End Function
+
+ Public Function PlgExecProcessAsync(sFileName As String, sMainLuaPath As String, sArguments As String) As Boolean Implements IHost.PlgExecProcessAsync
+ Return ExecProcessManager.ExecProcessAsync(sFileName, sMainLuaPath, sArguments)
+ End Function
+
+ Public Function PlgCheckExecProcessAsync(ByRef bHasExited As Boolean, ByRef nExitCode As Integer) As Boolean Implements IHost.PlgCheckExecProcessAsync
+ Return ExecProcessManager.CheckExecProcessAsync(bHasExited, nExitCode)
+ End Function
+
Public Function ComReadShortVar(nVarAddr As Integer, ByRef nResult As Short, nMachine As Integer) As Boolean Implements IHost.ComReadShortVar
If Map.refMainWindowVM.MachineManager.MachineList.Count >= nMachine AndAlso Not IsNothing(Map.refMainWindowVM.MachineManager.MachineList(nMachine - 1)) Then
Return Map.refMainWindowVM.MachineManager.MachineList(nMachine - 1).ReadShortVar(nVarAddr, nResult)
diff --git a/Supervisor/MainWindow/MainWindowV.xaml b/Supervisor/MainWindow/MainWindowV.xaml
index 93290fe..9dec1cf 100644
--- a/Supervisor/MainWindow/MainWindowV.xaml
+++ b/Supervisor/MainWindow/MainWindowV.xaml
@@ -1,13 +1,94 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Supervisor/MainWindow/MainWindowV.xaml.vb b/Supervisor/MainWindow/MainWindowV.xaml.vb
index 224e738..601de32 100644
--- a/Supervisor/MainWindow/MainWindowV.xaml.vb
+++ b/Supervisor/MainWindow/MainWindowV.xaml.vb
@@ -1,4 +1,6 @@
-Class MainWindowV
+Imports System.Windows.Interop
+
+Class MainWindowV
Private m_MainWindowVM As MainWindowVM
@@ -9,15 +11,69 @@
InitializeComponent()
' Assegno al riferimento locale al VM il VM preso dal DataContext
m_MainWindowVM = DirectCast(Me.DataContext, MainWindowVM)
+ AddHandler Me.Loaded, AddressOf MainWindowV_Loaded
+ AddHandler Me.StateChanged, AddressOf Window_StateChanged
+ AddHandler Me.Closing, AddressOf MainWindowV_Closing
AddHandler Me.Closed, AddressOf MainWindowV_Closed
+ Me.RefreshMaximizeRestoreButton()
End Sub
#End Region ' CONSTRUCTOR
+ Private Sub RefreshMaximizeRestoreButton()
+ If Me.WindowState = WindowState.Maximized Then
+ Me.maximizeButton.Visibility = Visibility.Collapsed
+ Me.restoreButton.Visibility = Visibility.Visible
+ Else
+ Me.maximizeButton.Visibility = Visibility.Visible
+ Me.restoreButton.Visibility = Visibility.Collapsed
+ End If
+ End Sub
+
+#Region "EVENTS"
+
+ Private Sub OnMinimizeButtonClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
+ Me.WindowState = WindowState.Minimized
+ End Sub
+
+ Private Sub OnMaximizeRestoreButtonClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
+ If Me.WindowState = WindowState.Maximized Then
+ Me.WindowState = WindowState.Normal
+ Else
+ Me.WindowState = WindowState.Maximized
+ End If
+ End Sub
+
+ Private Sub Window_StateChanged(ByVal sender As Object, ByVal e As EventArgs)
+ Me.RefreshMaximizeRestoreButton()
+ End Sub
+
+ Private Sub OnCloseButtonClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
+ Me.Close()
+ End Sub
+
+ Private Sub MainWindowV_Loaded(sender As Object, e As RoutedEventArgs)
+ ' Carico e imposto posizione finestra
+ WinPosFromIniToWindow(S_GENERAL, K_WINPLACE, Me)
+ End Sub
+
+ Private Sub MainWindowV_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs)
+ If (Keyboard.Modifiers And ModifierKeys.Alt) = ModifierKeys.Alt OrElse Keyboard.IsKeyDown(Key.F4) Then
+ e.Cancel = True
+ Return
+ End If
+ ' Salvo posizione finestra (se non minimizzata)
+ If WindowState <> WindowState.Minimized Then
+ WinPosFromWindowToIni(Me, S_GENERAL, K_WINPLACE)
+ End If
+ End Sub
+
Private Sub MainWindowV_Closed(sender As Object, e As EventArgs)
If Not IsNothing(m_MainWindowVM) AndAlso Not IsNothing(m_MainWindowVM.FiniteStateMachineManager) Then m_MainWindowVM.FiniteStateMachineManager.ResetFiniteStateMachineTimer()
LuaManager.Close()
EgtOutLog("Exit")
End Sub
+#End Region ' EVENTS
+
End Class
diff --git a/Supervisor/MainWindow/MainWindowVM.vb b/Supervisor/MainWindow/MainWindowVM.vb
index 01147d5..c6a8617 100644
--- a/Supervisor/MainWindow/MainWindowVM.vb
+++ b/Supervisor/MainWindow/MainWindowVM.vb
@@ -40,13 +40,17 @@ Public Class MainWindowVM
End Property
Private m_ContentPanel As Panel
- Public Property ContentPanel As Panel
+ Public ReadOnly Property ContentPanel As Panel
Get
Return m_ContentPanel
End Get
- Set(value As Panel)
- m_ContentPanel = value
- End Set
+ End Property
+
+ Private m_ContentMenu As Panel
+ Public ReadOnly Property ContentMenu As Panel
+ Get
+ Return m_ContentMenu
+ End Get
End Property
Sub New()
@@ -74,13 +78,13 @@ Public Class MainWindowVM
Application.Current.Resources.MergedDictionaries.Add(PluginDictionary)
'' aggiungo MainMenu dal plugin
Dim PluginMainMenu As IPluginControl = GetControlByName(Of IPluginControl)(sPluginName, "MainMenu")
- 'ContentPanel = PluginMainMenu
+ m_ContentMenu = PluginMainMenu
'' aggiungo manager delle funzioni Lua del Plugin
Dim PluginLuaManager As IPluginLuaManager = Map.refMainWindowVM.GetLuaManager(Of IPluginLuaManager)(sPluginName)
PluginLuaManager.PlgInit(LuaManager.state)
' aggiungo Project dal plugin
Dim ProjectPlugin As IPluginControl = GetControlByName(Of IPluginControl)(sPluginName, "Project")
- ContentPanel = ProjectPlugin
+ m_ContentPanel = ProjectPlugin
End If
End Sub
diff --git a/Supervisor/Resources/Icon.png b/Supervisor/Resources/Icon.png
new file mode 100644
index 0000000..209a58e
Binary files /dev/null and b/Supervisor/Resources/Icon.png differ
diff --git a/Supervisor/Supervisor.vbproj b/Supervisor/Supervisor.vbproj
index cb1b076..988f541 100644
--- a/Supervisor/Supervisor.vbproj
+++ b/Supervisor/Supervisor.vbproj
@@ -108,6 +108,7 @@
+ ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dllTrue
@@ -132,6 +133,7 @@
..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll
+
@@ -168,6 +170,7 @@
+ MSBuild:CompileDesigner
@@ -256,6 +259,9 @@
false
+
+
+
diff --git a/Supervisor/Utility/Dictionary.xaml b/Supervisor/Utility/Dictionary.xaml
index bfe5035..b12342a 100644
--- a/Supervisor/Utility/Dictionary.xaml
+++ b/Supervisor/Utility/Dictionary.xaml
@@ -60,8 +60,10 @@
+
+
+
+
diff --git a/Supervisor/Utility/ExecProcessManager.vb b/Supervisor/Utility/ExecProcessManager.vb
index 6facc09..b5299c1 100644
--- a/Supervisor/Utility/ExecProcessManager.vb
+++ b/Supervisor/Utility/ExecProcessManager.vb
@@ -1,5 +1,7 @@
Module ExecProcessManager
+ Private m_ExecProcess As Process
+
Friend Function ExecProcess(sFileName As String, sMainLuaPath As String, sArguments As String) As Boolean
' lancio esecuzione programma
Dim bResult As Boolean = True
@@ -25,4 +27,32 @@
Return bResult
End Function
+ Friend Function ExecProcessAsync(sFileName As String, sMainLuaPath As String, sArguments As String) As Boolean
+ If Not IsNothing(m_ExecProcess) Then
+ If Not m_ExecProcess.HasExited Then
+ m_ExecProcess.Kill()
+ End If
+ End If
+ ' lancio esecuzione programma
+ Dim bResult As Boolean = True
+ m_ExecProcess = New Process()
+ m_ExecProcess.StartInfo.FileName = sFileName
+ m_ExecProcess.StartInfo.RedirectStandardInput = False
+ m_ExecProcess.StartInfo.RedirectStandardOutput = False
+ m_ExecProcess.StartInfo.Arguments = 1.ToString() & " """ & sMainLuaPath & """ """ & sArguments & """"
+ m_ExecProcess.StartInfo.UseShellExecute = False
+ m_ExecProcess.StartInfo.CreateNoWindow = True
+ Return m_ExecProcess.Start()
+ End Function
+
+ Friend Function CheckExecProcessAsync(ByRef bHasExited As Boolean, ByRef nExitCode As Integer) As Boolean
+ If IsNothing(m_ExecProcess) Then Return False
+ bHasExited = m_ExecProcess.HasExited
+ If bHasExited Then
+ nExitCode = m_ExecProcess.ExitCode
+ End If
+ Threading.Thread.Sleep(100)
+ Return True
+ End Function
+
End Module
diff --git a/Supervisor/Utility/GenInterface.vb b/Supervisor/Utility/GenInterface.vb
index f7bf24d..cc0386e 100644
--- a/Supervisor/Utility/GenInterface.vb
+++ b/Supervisor/Utility/GenInterface.vb
@@ -52,6 +52,45 @@ Public Module GenInterface
Return nRet
End Function
+ Public Function GetPrivateProfileWinPos(
+ lpAppName As String,
+ lpKeyName As String,
+ ByRef nFlag As Integer,
+ ByRef nLeft As Integer,
+ ByRef nTop As Integer,
+ ByRef nWidth As Integer,
+ ByRef nHeight As Integer,
+ lpFileName As String) As Boolean
+ Dim sVal As String = String.Empty
+ GetPrivateProfileString(lpAppName, lpKeyName, "", sVal, lpFileName)
+ Dim sItems() As String = sVal.Split(",".ToCharArray)
+ If sItems.Count() >= 5 Then
+ Dim bOk As Boolean = True
+ If Not Integer.TryParse(sItems(0), nFlag) Then
+ nFlag = 0
+ bOk = False
+ End If
+ If Not Integer.TryParse(sItems(1), nLeft) Then
+ nLeft = 0
+ bOk = False
+ End If
+ If Not Integer.TryParse(sItems(2), nTop) Then
+ nTop = 0
+ bOk = False
+ End If
+ If Not Integer.TryParse(sItems(3), nWidth) Then
+ nWidth = 1024
+ bOk = False
+ End If
+ If Not Integer.TryParse(sItems(4), nHeight) Then
+ nHeight = 768
+ bOk = False
+ End If
+ Return bOk
+ End If
+ Return False
+ End Function
+
'-------------------------------- IniFile : Write ------------------------------------------------
Public Function WritePrivateProfileString(
@@ -61,6 +100,20 @@ Public Module GenInterface
lpFileName As String) As Boolean
End Function
+ Public Function WritePrivateProfileWinPos(
+ lpAppName As String,
+ lpKeyName As String,
+ nFlag As Integer,
+ nLeft As Integer,
+ nTop As Integer,
+ nWidth As Integer,
+ nHeight As Integer,
+ lpFileName As String) As Boolean
+ Dim sVal As String
+ sVal = nFlag.ToString & "," & nLeft.ToString & "," & nTop.ToString & "," & nWidth.ToString & "," & nHeight.ToString
+ Return WritePrivateProfileString(lpAppName, lpKeyName, sVal, lpFileName)
+ End Function
+
'-------------------------------- Windows --------------------------------------------------------
Public Enum SW As Integer
HIDE = 0
diff --git a/Supervisor/Utility/IniFile.vb b/Supervisor/Utility/IniFile.vb
index 2e61f35..febc606 100644
--- a/Supervisor/Utility/IniFile.vb
+++ b/Supervisor/Utility/IniFile.vb
@@ -39,6 +39,10 @@ Public Module IniFile
Return GetPrivateProfileString(IpAppName, IpKeyName, IpDefault, IpString, m_sPath)
End Function
+ Public Function GetMainPrivateProfileWinPos(IpAppName As String, IpKeyName As String, ByRef nFlag As Integer, ByRef nLeft As Integer, ByRef nTop As Integer, ByRef nWidth As Integer, ByRef nHeight As Integer) As Boolean
+ Return GetPrivateProfileWinPos(IpAppName, IpKeyName, nFlag, nLeft, nTop, nWidth, nHeight, m_sPath)
+ End Function
+
'Public Function GetPrivateProfileLanguage(lpAppName As String, lpKeyName As String, lpFileName As String) As Language
' Dim sVal As String = String.Empty
' GetPrivateProfileString(lpAppName, lpKeyName, "", sVal, lpFileName)
@@ -63,4 +67,8 @@ Public Module IniFile
Return WritePrivateProfileString(IpAppName, IpKeyName, IpString, m_sPath)
End Function
+ Public Function WriteMainPrivateProfileWinPos(IpAppName As String, IpKeyName As String, ByRef nFlag As Integer, ByRef nLeft As Integer, ByRef nTop As Integer, ByRef nWidth As Integer, ByRef nHeight As Integer) As Boolean
+ Return WritePrivateProfileWinPos(IpAppName, IpKeyName, nFlag, nLeft, nTop, nWidth, nHeight, m_sPath)
+ End Function
+
End Module
diff --git a/Supervisor/Utility/WinPos.vb b/Supervisor/Utility/WinPos.vb
new file mode 100644
index 0000000..7eda759
--- /dev/null
+++ b/Supervisor/Utility/WinPos.vb
@@ -0,0 +1,94 @@
+'----------------------------------------------------------------------------
+' EgalTech 2017-2017
+'----------------------------------------------------------------------------
+' File : WinPos.vb Data : 08.04.17 Versione : 1.8d1
+' Contenuto : Classe WinPos per gestione posizione e dimensioni finestra.
+'
+'
+'
+' Modifiche : 08.04.17 ES Creazione modulo.
+'
+'
+'----------------------------------------------------------------------------
+
+Public Module WinPosition
+
+ Public Class WinPos
+ ' Membri
+ Public nFlag As Integer
+ Public nLeft As Integer
+ Public nTop As Integer
+ Public nWidth As Integer
+ Public nHeight As Integer
+
+ Public Sub ToWindow(Window As Window)
+ ' Verifico che il punto in alto a sinistra stia nello schermo
+ Dim PtTL = New System.Drawing.Point(nLeft, nTop)
+ Dim s As System.Windows.Forms.Screen = System.Windows.Forms.Screen.FromPoint(PtTL)
+ If Not s.Bounds.Contains(PtTL) Then Return
+ ' Imposto posizione e dimensioni
+ Window.WindowStartupLocation = WindowStartupLocation.Manual
+ Window.Top = nTop
+ Window.Left = nLeft
+ Window.Height = nHeight
+ Window.Width = nWidth
+ Window.WindowState = If(nFlag = 1, WindowState.Maximized, WindowState.Normal)
+ End Sub
+
+ Public Sub FromWindow(Window As Window)
+ nTop = CInt(Window.Top)
+ nLeft = CInt(Window.Left)
+ nHeight = CInt(Window.Height)
+ nWidth = CInt(Window.Width)
+ nFlag = If(Window.WindowState = WindowState.Maximized, 1, 0)
+ If Window.WindowState = WindowState.Maximized Then
+ nHeight = CInt(Window.RestoreBounds.Height)
+ nWidth = CInt(Window.RestoreBounds.Width)
+ End If
+ End Sub
+
+ Public Overloads Function FromIni(sSection As String, sKey As String) As Boolean
+ Return GetMainPrivateProfileWinPos(sSection, sKey, nFlag, nLeft, nTop, nWidth, nHeight)
+ End Function
+
+ Public Overloads Function FromIni(sSection As String, sKey As String, IpFileName As String) As Boolean
+ Return GetMainPrivateProfileWinPos(sSection, sKey, nFlag, nLeft, nTop, nWidth, nHeight)
+ End Function
+
+ Public Overloads Function ToIni(sSection As String, sKey As String) As Boolean
+ Return WriteMainPrivateProfileWinPos(sSection, sKey, nFlag, nLeft, nTop, nWidth, nHeight)
+ End Function
+
+ Public Overloads Function ToIni(sSection As String, sKey As String, IpFileName As String) As Boolean
+ Return WriteMainPrivateProfileWinPos(sSection, sKey, nFlag, nLeft, nTop, nWidth, nHeight)
+ End Function
+
+ End Class
+
+ Public Function WinPosFromIniToWindow(sSection As String, sKey As String, Window As Window) As Boolean
+ Dim WinPos As New WinPos
+ If Not WinPos.FromIni(sSection, sKey) Then Return False
+ WinPos.ToWindow(Window)
+ Return True
+ End Function
+
+ Public Function WinPosFromIniToWindow(sSection As String, sKey As String, Window As Window, IpFileName As String) As Boolean
+ Dim WinPos As New WinPos
+ If Not WinPos.FromIni(sSection, sKey, IpFileName) Then Return False
+ WinPos.ToWindow(Window)
+ Return True
+ End Function
+
+ Public Function WinPosFromWindowToIni(Window As Window, sSection As String, sKey As String) As Boolean
+ Dim WinPos As New WinPos
+ WinPos.FromWindow(Window)
+ Return WinPos.ToIni(sSection, sKey)
+ End Function
+
+ Public Function WinPosFromWindowToIni(Window As Window, sSection As String, sKey As String, IpFileName As String) As Boolean
+ Dim WinPos As New WinPos
+ WinPos.FromWindow(Window)
+ Return WinPos.ToIni(sSection, sKey, IpFileName)
+ End Function
+
+End Module