Attribute VB_Name = "modWinPos"
Option Explicit

Private Type FORMDIMENSIONS
    UseValues As Boolean
    Top As Long
    Left As Long
    Height As Long
    Width As Long
    WindowState As Byte
End Type

'Form Dimension Index
Public Const fdiGoalies = 0
Public Const fdiGoalieEdit = 1
Public Const fdiLineEdit = 2
Public Const fdiLines = 3
Public Const fdiMenuDefaults = 4
Public Const fdiPeriodLengthEdit = 5
Public Const fdiPeriodLengths = 6
Public Const fdiPlayerEdit = 7
Public Const fdiPlayers = 8
Public Const fdiPlayoffDrawEdit = 9
Public Const fdiPlayoffDraws = 10
Public Const fdiRink = 11
Public Const fdiRules = 12
Public Const fdiRuleEdit = 14
Public Const fdiStrips = 15
Public Const fdiTeamEdit = 16
Public Const fdiTeams = 17
'Public objfdi(fdiGoalies To fdiTeams) As FORMDIMENSIONS
Public objfdi(fdiGoalies To fdiTeams) As FORMDIMENSIONS

Sub sFormDimensionRestore(ByRef frm As Form, ByRef obj As FORMDIMENSIONS, Optional ByVal blnCheckIfSaved As Boolean = False, Optional ByVal blnForceWindowNormal As Boolean = False)
On Error GoTo Err_

If blnCheckIfSaved Then
    If Not obj.UseValues Then
        If frm.BorderStyle = vbFixedDialog And frm.MDIChild = False Then 'Center Modal Dialogs
            frm.Top = (frmMDI.Height - frm.Height) \ 2
            frm.Left = (frmMDI.Width - frm.Width) \ 2
        End If
        GoTo Exit_
    End If
End If
    
frm.WindowState = vbNormal
frm.Top = obj.Top
frm.Left = obj.Left

If frm.WindowState = vbSizable Then
    frm.Width = obj.Width
    frm.Height = obj.Height
End If

If Not blnForceWindowNormal Then
    frm.WindowState = obj.WindowState
End If

'Debug.Print frm.Name; obj.Top; frm.Top; obj.Left; frm.Left; "Restore"

Exit_:
Exit Sub

Err_:
MsgBox Err.Description, vbExclamation, Err.Number
Resume Next

End Sub

Sub sFormDimensionSave(ByRef frm As Form, ByRef obj As FORMDIMENSIONS)
On Error GoTo Err_

obj.UseValues = True
obj.WindowState = frm.WindowState
If Not frm.WindowState = vbNormal Then
    frm.WindowState = vbNormal
End If
obj.Top = frm.Top
obj.Left = frm.Left
obj.Height = frm.Height
obj.Width = frm.Width

'Debug.Print frm.Name; obj.Top; frm.Top; obj.Left; frm.Left; "Save"

Exit_:
Exit Sub

Err_:
MsgBox Err.Description, vbExclamation, Err.Number
Resume Next

End Sub

