Attribute VB_Name = "modMain"
Public Const SRCCOPY = &HCC0020
Public Const SRCPAINT = &HEE0086
Public Const SRCAND = &H8800C6

Global delay(2) As Double
Global music() As String
Global res() As String
Global resCustom() As Boolean
Global Dat() As String
Global tim() As Long
Global cond() As String
Global modifs() As ChilkatXml

'For the modifier xml
Global mods As ChilkatXml
Global types As ChilkatXml
Global supports As ChilkatXml

'To try to fix OCX/dll problems
Private Declare Function RegComCtl32 Lib "chilkatxml.dll" Alias _
    "DllRegisterServer" () As Long
Private Declare Function RegComCtl32png Lib "PNGlib.dll" Alias _
    "DllRegisterServer" () As Long
    
Public Enum PNGErrorContants
    pngeSucceeded
    pngeFileNotFound
    pngeOpenError
    pngeInvalidFile
End Enum

Public Declare Function BitBlt Lib "gdi32" _
  (ByVal hDCDest As Long, ByVal XDest As Long, _
   ByVal YDest As Long, ByVal nWidth As Long, _
   ByVal nHeight As Long, ByVal hDCSrc As Long, _
   ByVal xSrc As Long, ByVal ySrc As Long, _
   ByVal dwRop As Long) As Long
    
'Public Declare Function LoadPNGFile Lib "pnglib.dll" (FileName As String) As PNGErrorContants
'Public Declare Sub DrawToDC Lib "pnglib.dll" (hDC As Long, X As Long, Y As Long)

Private Declare Function RegComCtl32Com Lib "comdlg32.ocx" Alias _
    "DllRegisterServer" () As Long

Sub Main()
On Error GoTo bla
    'Tries to load a commondialog
    Dim w As CommonDialog
    'Set w = New CommonDialog
    'Set w = Nothing
    'If the component is not registered, goes to bla: and registers component
On Error GoTo gla
    Dim s As cPNG
    Set s = New cPNG
    Set s = Nothing
    
On Error GoTo hla
    Dim R As ChilkatXml
    'Set r = New ChilkatXml
    'Set r = Nothing
    
    Load frmMain
    frmMain.Show
    Exit Sub
bla:
    RegComCtl32Com
    MsgBox "Restart the program"
    Exit Sub
    'MsgBox Err
    'Resume Next
hla:
    If Err = 429 Then
        MsgBox "Unknown error: " & Err & " " & Err.Description
        Resume Next
    End If
    
    RegComCtl32
    MsgBox "Restart the program"
    'MsgBox Err.Description
    MsgBox Err
    Exit Sub
    'Resume Next
gla:
    RegComCtl32png
    MsgBox "Restart the program"
    Exit Sub
End Sub

Public Function isPng(inp As String) As Boolean
    If LCase(Right(inp, 3)) = "png" Then
        isPng = True
    Else
        isPng = False
    End If
End Function

Public Function isPic(inp As String) As Boolean
    If LCase(Right(inp, 3)) = "wmv" Or LCase(Right(inp, 3)) = "png" Then
        isPic = False
    Else
        isPic = True
    End If
End Function

Public Function getName(inp As String) As String
    Dim i As Integer
    
    Do While InStr(i + 1, inp, "\") <> 0
        i = InStr(i + 1, inp, "\")
    Loop
    
    getName = Mid(inp, i + 1, Len(inp) - 4 - i)
End Function

Public Function getfile(inp As String) As String
    Dim i As Integer
    
    Do While InStr(i + 1, inp, "\") <> 0
        i = InStr(i + 1, inp, "\")
    Loop
    
    getfile = Mid(inp, i + 1, Len(inp) - i)
End Function

Public Function makeTag(field As String, valu As String) As String
    makeTag = "<" & field & ">" & valu & "</" & field & ">"
End Function

Public Function makeTagWithAttrib(field As String, valu As String, attri As String) As String
    makeTagWithAttrib = "<" & field & " " & attri & ">" & valu & "</" & field & ">"
End Function

Public Sub registerDll()
On Error Resume Next
    Dim ret As Long
    ret = RegComCtl32
    
    If Err <> 0 Then
        MsgBox Err.Description
    End If
End Sub

Public Function fixPath(inp As String) As String
    If Right(inp, 1) <> "\" Then
        fixPath = inp & "\"
    Else
        fixPath = inp
    End If
End Function

Function getResFile(inp As String) As String
    Dim i As Integer
    For i = 0 To frmMain.lstR.ListCount - 1
        If LCase(frmMain.lstR.List(i)) = LCase(inp) Then getResFile = res(i)
    Next i
End Function
' For command line parameteres
' Dim aryParams() As String
' Dim strMessage As String
' Dim intParam As Integer
' aryParams = Split(Command(), " ") 'Assumes parameters are seperated by spaces, change second argument if different
' For intParam = LBound(aryParams) To UBound(aryParams)
'   strMessage = strMessage & "Parameter " & CStr(intParam) & " = " & aryParams(intParam) & vbLf
' Next
' MsgBox "Application started with the following parameters" & vbLf & strMessage

