Attribute VB_Name = "mod_Global"
Option Explicit

Private Const HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1
Public booVoice As Boolean

Private Type BITMAPHEADER
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmbpImage As Integer
    bmBits As Long
End Type
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Const WS_EX_LAYERED = &H80000
Public Const LWA_COLORKEY = &H1

Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function PlaySoundNow Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Public iniValue As Variant
Public inputBack As String
Public inputMode As Boolean
Public mouseH As Long
Public mouseX As Long
Public mouseY As Long
Public myAnim As Boolean
Public myControls As Long
Public myPassword As String
Public mySleep As Long

Public myButtons() As String
Public myActions() As String
Public mySndClick() As String
Public mySndOver() As String
Public mySecurity() As Long
Public myButCount As Long
Public myAnimStart() As Long
Public myAnimCurrent() As Long
Public myAnimEnd() As Long
Public myAnimCount As Long
Public myAnimFrame As Long

Public strApplication As String
Public strProgram As String
Public strProgramdir As String
Public strThemedir As String
Public RegisterText As String
Public strThemeName As String

Public Const conHwndTopmost = -1
Public Const conHwndTopNot = -2
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Public Const GWL_EXSTYLE = (-20)
Public Const GWL_HWNDPARENT = (-8)
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const WS_BORDER = &H800000
Public Const WS_EX_TOOLWINDOW = &H80
Public Const WS_VISIBLE = &H10000000

Public Type POINTAPI
    X As Long
    Y As Long
End Type

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function mciExecute& Lib "winmm.dll" (ByVal lpstrCommand As String)
Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function WindowFromPoint Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Function Activate_Application() As Long
    Dim lngStyle As Long
    Dim Addcounter As Integer
    Dim tempcheck As String
    Dim currWnd As Long
    Dim Length As Long
    Dim listItem$
    Dim IsTask As Long
    Dim Counting As Long
    
    Activate_Application = -1
    IsTask = WS_VISIBLE Or WS_BORDER
    
    currWnd = GetWindow(frmMain.hWnd, GW_HWNDFIRST)
    While currWnd <> 0
        If IsWindowVisible(currWnd) Then
            If GetParent(currWnd) = 0 Then
                lngStyle = GetWindowLong(currWnd, GWL_HWNDPARENT)
                If (lngStyle = 0) Or IsToolWindow(lngStyle) Then
                    If Not IsToolWindow(currWnd) Then
                        Length = GetWindowTextLength(currWnd)
                        listItem$ = Space$(Length + 1)
                        Length = GetWindowText(currWnd, listItem$, Length + 1)
                        If (Left(listItem$, Length) = strApplication) Then
                            Activate_Application = currWnd
                       End If
                    End If
                End If
            End If
        End If
        currWnd = GetWindow(currWnd, GW_HWNDNEXT)
    Wend
End Function

Public Function Check_Shareware() As String
    Dim userSkey As Long
    Dim userLkey As Long
    Dim userXkey As Long
    Dim Skey As String
    Dim Lkey As String
    Dim Xkey As String
    Dim Cname As String
    Dim CData As String
    Dim CNaam As String
    Dim I As Long
    Dim lngCdate As Long
    Dim lngSdate As Long
    Dim lngEdate As Long
    Dim sDate
    Dim dDate
    
    Skey = GetSetting("LCARS Terminal", "Default", "Skey", "1")
    Lkey = GetSetting("LCARS Terminal", "Default", "Lkey", "1")
    Xkey = GetSetting("LCARS Terminal", "Default", "Xkey", "1")
    CNaam = GetSetting("LCARS Terminal", "Default", "Name", "1")
    CData = GetSetting("LCARS Terminal", "Default", "Date", "20010101")
    Check_Shareware = ""
    lngCdate = Val(Format(Now, "yyyymmdd"))
    lngSdate = Val(CData)
    
    Cname = Mid(CData, 7, 2) & "-" & MonthName(CLng(Mid(CData, 5, 2))) & "-" & Left(CData, 4)
    sDate = CDate(Cname)
    dDate = DateAdd("m", 12, sDate)
    lngEdate = Val(Format(dDate, "yyyymmdd"))
    Cname = CData & CNaam
    
    If lngCdate >= 20050101 Then
        lngEdate = lngCdate
    End If
    
    
    If Skey <> "1" And Lkey <> "1" And Xkey <> "1" And Cname <> "1" And CData <> "1" And lngCdate <= lngEdate Then
        userSkey = Len(Cname)
        For I = 1 To Len(Cname)
            If I < 9 Then
                userSkey = userSkey + Asc(Mid(Cname, I, 1))
            End If
        Next
        userLkey = userSkey
        For I = 1 To Len(Cname)
            userLkey = userLkey + (I * Asc(Mid(Cname, I, 1)))
        Next
        userXkey = userLkey
        For I = 1 To Len(Cname)
            userXkey = userXkey + (I * Asc(Mid(Cname, I, 1)))
            userXkey = userXkey + (I * 5 * Asc(Mid(Cname, I, 1)))
        Next
        If (Val(Skey) = userSkey And Val(Lkey) = userLkey And Val(Xkey) = userXkey) Then
            Check_Shareware = CNaam
        End If
    End If
End Function

Public Function GetSecurity(gsIndex As Integer) As Boolean
    Dim gsPos As Long
    Dim gsString As String
    
    GetSecurity = False
    If INI_GetKey("DEFAULT", Format(mySecurity(gsIndex), "00"), strProgramdir & strThemedir & strThemeName & ".ini") = True Then
        gsString = iniValue
        gsPos = InStr(gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsString = Mid(gsString, gsPos + 1)
        GetSecurity = Mid(gsString, 1, InStr(gsString, ",") - 1)
    ElseIf INI_GetKey("DEFAULT", Format(mySecurity(gsIndex), "00"), strProgramdir & strThemedir & strThemeName & ".skn") = True Then
        gsString = iniValue
        gsPos = InStr(gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsPos = InStr(gsPos + 1, gsString, ",")
        gsString = Mid(gsString, gsPos + 1)
        GetSecurity = Mid(gsString, 1, InStr(gsString, ",") - 1)
    End If
End Function

Public Function GetShortName(ByVal sLongFileName As String) As String
    Dim lRetVal As Long, sShortPathName As String, iLen As Integer

    sShortPathName = Space(255)
    iLen = Len(sShortPathName)

    lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
    GetShortName = Left(sShortPathName, lRetVal)
End Function

Public Function INI_GetKey(SectionName As String, KeyName As String, IniFileName As String) As Boolean
    Dim ReturnString As String
    Dim ReturnValue As Long
    
    On Local Error GoTo GetKey_Err
    ReturnString = String$(32000, 0)
    iniValue = ""
    ReturnValue = GetPrivateProfileString(SectionName & Chr(0), KeyName, "NotFound", ReturnString, Len(ReturnString), IniFileName & Chr(0))
    If Left(ReturnString, InStr(ReturnString, Chr$(0)) - 1) = "NotFound" Then
        INI_GetKey = False
    Else
        INI_GetKey = True
        iniValue = Left(ReturnString, InStr(ReturnString, Chr$(0)) - 1)
    End If

GetKey_End:
    Exit Function

GetKey_Err:
    MsgBox "Error Retrieving Key"
    INI_GetKey = False
    Resume GetKey_End
End Function

Public Function IsToolWindow(ByVal hWnd As Long) As Boolean
   ' Check for toolwindow style bit.
   IsToolWindow = ((GetWindowLong(hWnd, GWL_EXSTYLE) And WS_EX_TOOLWINDOW) = WS_EX_TOOLWINDOW)
End Function

Public Sub LoadControls(myForm As Form, _
ByRef mySection As String, _
ByRef myBcount, _
ByRef myLCButtons, _
ByRef myLCActions, _
ByRef myLCSndClick, _
ByRef myLCSndOver, _
ByRef myLCSecurity, _
ByRef myAcount, _
ByRef myAframe, _
ByRef myLCAnimStart, _
ByRef myLCAnimEnd, _
ByRef myLCAnimCurrent, _
ByRef myLCAnim, _
ByRef myLCSleep, _
ByRef mySknfile As String)
            
            
    Dim myCounter As Long
    Dim myPicture As Long
    Dim myTextbox As Long
    Dim myKomma As Long
    Dim myFilename As String
    Dim myMode As String
    Dim myLeft As Long
    Dim myTop As Long
    Dim myWidth As Long
    Dim myHeight As Long
    Dim myTemp As String
    Dim GifEnd
    Dim fptr
    Static buf$, picbuf$
    Dim imgHeader As String
    Dim I, J As Long
    Dim fileHeader As String
    Dim TimeWait As Long
    Dim tmpiniValue As String
    
    On Error Resume Next
    myBcount = 0
    myCounter = 0
    myPicture = 0
    myTextbox = 0
    myAcount = 0
    myAframe = 0
    While INI_GetKey(mySection, Format(myCounter + 1, "00"), mySknfile) = True
        tmpiniValue = iniValue
        If (INI_GetKey(mySection, Format(myCounter + 1, "00"), Mid(mySknfile, 1, Len(mySknfile) - 3) & "ini") = True) Then
            tmpiniValue = iniValue
        End If
        iniValue = tmpiniValue
        myKomma = InStr(iniValue, ",") + 1
        myFilename = Mid(iniValue, 1, myKomma - 2)
        myMode = Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - myKomma)
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        If myMode = "L" Then
            '08=null,T,-350,50,0,-180,0,0,0,255,128,0,courier,10
            myTextbox = myTextbox + 1
            Load myForm.txtBox(myTextbox)
            myLeft = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myTop = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myWidth = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myHeight = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            If myLeft < 0 Then myLeft = myForm.ScaleWidth + myLeft
            If myTop < 0 Then myTop = myForm.ScaleHeight + myTop
            If myWidth <= 0 Then myWidth = myForm.ScaleWidth + myWidth - myLeft
            If myHeight <= 0 Then myHeight = myForm.ScaleHeight + myHeight - myTop
            myForm.txtBox(myTextbox).Left = myLeft
            myForm.txtBox(myTextbox).Width = myWidth
            myForm.txtBox(myTextbox).Top = myTop
            myForm.txtBox(myTextbox).Height = myHeight
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myLeft = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myTop = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myWidth = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myForm.txtBox(myTextbox).BackColor = RGB(myLeft, myTop, myWidth)
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myLeft = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myTop = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myWidth = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myForm.txtBox(myTextbox).ForeColor = RGB(myLeft, myTop, myWidth)
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myFilename = Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma)
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myLeft = Val(Mid(iniValue, myKomma))
            'myForm.txtBox(myTextbox).MultiLine = True
            myForm.txtBox(myTextbox).FontName = myFilename
            myForm.txtBox(myTextbox).FontSize = myLeft
            myForm.txtBox(myTextbox).Text = ""
            myForm.txtBox(myTextbox).Enabled = True
            myForm.txtBox(myTextbox).Visible = True
        End If
        If myMode = "P" Then
            myPicture = myPicture + 1
            Load myForm.imgPic(myPicture)
            myForm.imgPic(myPicture).Enabled = False
            myForm.imgPic(myPicture).Stretch = True
            myTemp = Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - myKomma)
            If (Right(myTemp, 1) = "%") Then
                myLeft = Val((myForm.ScaleWidth * Val(myTemp)) / 100)
            Else
                myLeft = Val(myTemp)
            End If
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myTemp = Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma)
            If (Right(myTemp, 1) = "%") Then
                myTop = Val((myForm.ScaleHeight * Val(myTemp)) / 100)
            Else
                myTop = Val(myTemp)
            End If
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myTemp = Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma)
            If (Right(myTemp, 1) = "%") Then
                myWidth = Val((myForm.ScaleWidth * Val(myTemp)) / 100)
            Else
                myWidth = Val(myTemp)
            End If
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myTemp = Mid(iniValue, myKomma)
            If (Right(myTemp, 1) = "%") Then
                myHeight = Val((myForm.ScaleHeight * Val(myTemp)) / 100)
            Else
                myHeight = Val(myTemp)
            End If
            If myLeft < 0 Then myLeft = myForm.ScaleWidth + myLeft
            If myTop < 0 Then myTop = myForm.ScaleHeight + myTop
            If myWidth <= 0 Then myWidth = myForm.ScaleWidth + myWidth - myLeft
            If myHeight <= 0 Then myHeight = myForm.ScaleHeight + myHeight - myTop
            myForm.imgPic(myPicture).Left = myLeft
            myForm.imgPic(myPicture).Width = myWidth
            myForm.imgPic(myPicture).Top = myTop
            myForm.imgPic(myPicture).Height = myHeight
            myForm.imgPic(myPicture).Picture = LoadPicture(strProgramdir & strThemedir & myFilename)
            myForm.imgPic(myPicture).Visible = True
        End If
        If myMode = "B" Then
            myBcount = myBcount + 1
            ReDim Preserve myLCButtons(myBcount)
            ReDim Preserve myLCActions(myBcount)
            ReDim Preserve myLCSndClick(myBcount)
            ReDim Preserve myLCSndOver(myBcount)
            ReDim Preserve myLCSecurity(myBcount)
            Load myForm.imgBut(myBcount)
            myForm.imgBut(myBcount).Visible = True
            
            myLeft = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myTop = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myWidth = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myHeight = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myLCSndOver(myBcount) = Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma)
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myLCSndClick(myBcount) = Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma)
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myLCSecurity(myBcount) = myCounter + 1
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myLCActions(myBcount) = Mid(iniValue, myKomma)
            If myLeft < 0 Then myLeft = myForm.ScaleWidth + myLeft
            If myTop < 0 Then myTop = myForm.ScaleHeight + myTop
            If myWidth < 0 Then myWidth = myForm.ScaleWidth + myWidth - myLeft
            If myHeight < 0 Then myHeight = myForm.ScaleHeight + myHeight - myTop
            myForm.imgBut(myBcount).Left = myLeft
            myForm.imgBut(myBcount).Width = myWidth
            myForm.imgBut(myBcount).Top = myTop
            myForm.imgBut(myBcount).Height = myHeight
            myForm.imgBut(myBcount).Picture = LoadPicture(strProgramdir & strThemedir & myFilename)
            myLCButtons(myBcount) = strProgramdir & strThemedir & myFilename
        End If
        
        If myMode = "A" Then
            GifEnd = Chr(0) & "!ù"
            myAcount = myAcount + 1
            ReDim Preserve myLCAnimStart(myAcount)
            ReDim Preserve myLCAnimEnd(myAcount)
            ReDim Preserve myLCAnimCurrent(myAcount)
            
            myLCAnimStart(myAcount) = myAframe + 1
            myLeft = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myTop = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - 1))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myWidth = Val(Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - 1))
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myHeight = Val(Mid(iniValue, myKomma))
            If myLeft < 0 Then myLeft = myForm.ScaleWidth + myLeft
            If myTop < 0 Then myTop = myForm.ScaleHeight + myTop
            If myWidth < 0 Then myWidth = myForm.ScaleWidth + myWidth - myLeft
            If myHeight < 0 Then myHeight = myForm.ScaleHeight + myHeight - myTop
            
            fptr = FreeFile
            Open strProgramdir & strThemedir & myFilename For Binary Access Read As fptr
                buf = String(LOF(fptr), Chr(0))
                Get #fptr, , buf
            Close fptr
        
            I = 1
        
            J = (InStr(1, buf, GifEnd) + Len(GifEnd)) - 2
            fileHeader = Left(buf, J)
            I = J + 2
        
            Load myForm.tmrAnim(myAcount)
            myForm.tmrAnim(myAcount).Enabled = False
            Do
                J = InStr(I, buf, GifEnd) + Len(GifEnd)
                If J > Len(GifEnd) Then
                    myAframe = myAframe + 1
                    fptr = FreeFile
                    Open "tmp.gif" For Binary As fptr
                    picbuf = String(Len(fileHeader) + J - I, Chr(0))
                    picbuf = fileHeader & Mid(buf, I - 1, J - I)
                    Put #fptr, 1, picbuf
                    imgHeader = Left(Mid(buf, I - 1, J - I), 16)
                    Close fptr
                
                    TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * CLng(256))) * CLng(10)
                    Load myForm.imgGif(myAframe)
                    myForm.imgGif(myAframe).ZOrder 0
                    myForm.imgGif(myAframe).Stretch = True
                    myForm.imgGif(myAframe).Left = myLeft
                    myForm.imgGif(myAframe).Top = myTop
                    myForm.imgGif(myAframe).Width = myWidth
                    myForm.imgGif(myAframe).Height = myHeight
                    myForm.imgGif(myAframe).Tag = TimeWait
                    myForm.imgGif(myAframe).Picture = LoadPicture("tmp.gif")
                    myForm.imgGif(myAframe).Enabled = False
                    If (myAframe = myLCAnimStart(myAcount)) Then myForm.imgGif(myAframe).Visible = True
                    Kill ("tmp.gif")
                    I = J
                End If
                DoEvents
            Loop Until J = Len(GifEnd)
        
            If I < Len(buf) Then
                myAframe = myAframe + 1
                fptr = FreeFile
                Open "tmp.gif" For Binary As fptr
                    picbuf = String(Len(fileHeader) + Len(buf) - I, Chr(0))
                    picbuf = fileHeader & Mid(buf, I - 1, Len(buf) - I)
                    Put #fptr, 1, picbuf
                    imgHeader = Left(Mid(buf, I - 1, Len(buf) - I), 16)
                Close fptr
    
                TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * CLng(256))) * CLng(10)
                Load myForm.imgGif(myAframe)
                myForm.imgGif(myAframe).ZOrder 0
                myForm.imgGif(myAframe).Stretch = True
                myForm.imgGif(myAframe).Left = myLeft
                myForm.imgGif(myAframe).Top = myTop
                myForm.imgGif(myAframe).Width = myWidth
                myForm.imgGif(myAframe).Height = myHeight
                myForm.imgGif(myAframe).Tag = TimeWait
                myForm.imgGif(myAframe).Picture = LoadPicture("tmp.gif")
                myForm.imgGif(myAframe).Enabled = False
                If (myAframe = myLCAnimStart(myAcount)) Then myForm.imgGif(myAframe).Visible = True
                Kill ("tmp.gif")
            End If
        
            myLCAnimEnd(myAcount) = myAframe
            myLCAnimCurrent(myAcount) = myLCAnimStart(myAcount)
        
            'On Error GoTo badTime
            myForm.tmrAnim(myAcount).Interval = CInt(myForm.imgGif(myLCAnimStart(myAcount)).Tag)
badTime:
            myForm.tmrAnim(myAcount).Enabled = True
        End If
        
        myCounter = myCounter + 1
        If myLCAnim = True Then
            Sleep myLCSleep
        End If
        DoEvents
    Wend
End Sub

Public Function mkSkin(ByVal Form As Form, ByVal cTransparent As Long, Optional Image As String) As Boolean
    Dim iImage As BITMAPHEADER
    Dim Ret As Long
    Dim xdcImage, ydcImage As Byte
    Dim tImage As Boolean
    Dim bImage, bpImage, cImage, dtImage, etImage, hImage, hRgn, hRgnt, sImage, xImage, xMax, yImage, yMax As Long
    Dim lngRow As Long
    Dim lngCol As Long
    Dim lngStart As Long
    
    Dim OSInfo As OSVERSIONINFO
    Dim IsWindowsNTa As Boolean

    With OSInfo
        .dwOSVersionInfoSize = Len(OSInfo)
        .szCSDVersion = Space$(128)
        GetVersionEx OSInfo
        IsWindowsNTa = (.dwPlatformId = VER_PLATFORM_WIN32_NT)
    End With
    If IsWindowsNTa = True Then
        Form.Picture = LoadPicture(Image)
        hImage = Form.Picture
        GetObject Form.Picture, Len(iImage), iImage
        xMax = iImage.bmWidth
        yMax = iImage.bmHeight
        Form.Width = xMax * Screen.TwipsPerPixelX
        Form.Height = yMax * Screen.TwipsPerPixelY
        
        
        'Set the window style to 'Layered'
        Ret = GetWindowLong(Form.hWnd, GWL_EXSTYLE)
        Ret = Ret Or WS_EX_LAYERED
        SetWindowLong Form.hWnd, GWL_EXSTYLE, Ret
        'Set the opacity of the layered window to 128
        SetLayeredWindowAttributes Form.hWnd, cTransparent, 0, LWA_COLORKEY
        Form.Refresh
    Else
        Form.Picture = LoadPicture(Image)
        hImage = Form.Picture
        GetObject Form.Picture, Len(iImage), iImage
        xMax = iImage.bmWidth
        yMax = iImage.bmHeight
        hRgn = CreateRectRgn(0, 0, 0, 0)
        bpImage = 3
        sImage = xMax * yMax * bpImage
        Form.Width = xMax * Screen.TwipsPerPixelX
        Form.Height = yMax * Screen.TwipsPerPixelY
        ReDim pbImage(0 To sImage) As Byte
        ReDim pimage(0 To xMax, 0 To yMax) As Long
        GetBitmapBits hImage, sImage, pbImage(0)
        For bImage = 0 To sImage - 3 Step bpImage
            yImage = Int((bImage) / (xMax * bpImage))
            xImage = ((bImage) / bpImage) - ((yImage) * xMax)
            pimage(xImage, yImage) = RGB(pbImage(bImage), pbImage(bImage + 1), pbImage(bImage + 2))
        Next bImage
            
        For lngRow& = 0 To yMax - 1
            lngCol& = 0
            Do While lngCol& < xMax
                Do While lngCol& < xMax And pimage(lngCol, lngRow) = cTransparent
                    lngCol& = lngCol& + 1
                Loop
                If lngCol& < xMax Then
                    lngStart& = lngCol&
                    Do While lngCol& < xMax And pimage(lngCol, lngRow) <> cTransparent
                        lngCol& = lngCol& + 1
                    Loop
                    If lngCol& > xMax Then lngCol& = xMax
                    hRgnt = CreateRectRgn(lngStart&, lngRow&, lngCol&, lngRow& + 1)
                    CombineRgn hRgn, hRgn, hRgnt, 2
                    DeleteObject (hRgnt)
                End If
            Loop
        Next
            
        mkSkin = SetWindowRgn(Form.hWnd, hRgn, 1)
        DeleteObject hRgn
        Form.Refresh
    End If
End Function

Public Sub Mouse_Get(myForm As Form)
    Dim mouseco As POINTAPI
    
    GetCursorPos mouseco
    mouseX = mouseco.X - (myForm.Left \ Screen.TwipsPerPixelX)
    mouseY = mouseco.Y - (myForm.Top \ Screen.TwipsPerPixelY)
    mouseH = WindowFromPoint(mouseco.X, mouseco.Y)
End Sub

Public Sub PlaySound(mySound As String, myWait As Boolean)
    Dim Variable
    Dim strSound As String
    Dim booSound As Boolean
    Dim booMultiple As Boolean
    
    booSound = True
    On Error Resume Next
    If INI_GetKey("DEFAULT", "Sound", strProgramdir & strThemedir & "terminal.skn") = True Then
        booSound = iniValue
    End If
    If booSound = False Then Exit Sub
    
    booMultiple = False
    If INI_GetKey("DEFAULT", "Multiple", strProgramdir & strThemedir & "terminal.skn") = True Then
        booMultiple = iniValue
    End If
    
    Variable = 0
    If InStr(mySound, ":") > 0 Then
        strSound = GetShortName(mySound)
    Else
        strSound = GetShortName(strProgramdir & strThemedir & mySound & ".wav")
    End If
    Variable = FileLen(strSound)
    If (Variable > 0) Then
        If myWait = True Then
            If booMultiple = True Then
                Variable = mciExecute("play " & strSound & " wait")
            Else
                Variable = PlaySoundNow(strSound, 1, 0)
            End If
        Else
            If booMultiple = True Then
                Variable = mciExecute("play " & strSound)
            Else
                Variable = PlaySoundNow(strSound, 1, &H1)
            End If
        End If
    End If
End Sub

Public Sub Startup_Form(myForm As Form)
    Dim lngCWnd As Long
    Dim booRunning As Boolean
    Dim myKomma As Long
    Dim myRed As Long
    Dim myGreen As Long
    Dim myBlue As Long
    Dim mySound As String
    
    myForm.cmdFake.Left = -100
    myForm.cmdFake.Visible = False

    If (App.PrevInstance) Then
        myForm.Caption = "Piet van Stralen"
        lngCWnd = Activate_Application
        If lngCWnd <> -1 Then
            SetWindowPos lngCWnd, conHwndTopmost, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
            SetWindowPos lngCWnd, conHwndTopNot, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
        End If
        End
    Else
        myForm.Caption = strApplication
    End If
    
    SaveSetting "LCARS Terminal", "EXIT", strApplication, "0"
    SaveSetting "LCARS Terminal", "Voice", strProgram, ""
    booRunning = GetSetting("LCARS Terminal", "General", "Running", False)
    If (booRunning = True) Then
        myForm.Left = GetSetting("LCARS Terminal", "Screen", "Left", frmStartupMax.Left / Screen.TwipsPerPixelX) * Screen.TwipsPerPixelX
        myForm.Top = GetSetting("LCARS Terminal", "Screen", "Top", frmStartupMax.Top / Screen.TwipsPerPixelY) * Screen.TwipsPerPixelY
        myForm.Width = GetSetting("LCARS Terminal", "Screen", "Right", (frmStartupMax.Width + myForm.Left) / Screen.TwipsPerPixelX) * Screen.TwipsPerPixelX - myForm.Left
        myForm.Height = GetSetting("LCARS Terminal", "Screen", "Bottom", (frmStartupMax.Height + myForm.Top) / Screen.TwipsPerPixelY) * Screen.TwipsPerPixelY - myForm.Top
    Else
        frmStartupMax.Show
        myForm.Left = frmStartupMax.Left + 60
        myForm.Top = frmStartupMax.Top + 60
        myForm.Height = frmStartupMax.Height - 120
        myForm.Width = frmStartupMax.Width - 120
        Unload frmStartupMax
    End If
    
    strProgramdir = GetSetting("LCARS Terminal", "Default", "ProgramDir", "")
    strThemedir = GetSetting("LCARS Terminal", "Default", "ThemeDir", "")
    myControls = myForm.Controls.Count

    myPassword = GetSetting("LCARS Terminal", "DEFAULT", "Password", "")
    
    strThemeName = strProgram & CStr(Screen.Width / Screen.TwipsPerPixelX)
    If INI_GetKey("DEFAULT", "BackGround", strProgramdir & strThemedir & strThemeName & ".skn") = False Then
        strThemeName = strProgram
    End If
    

    If INI_GetKey("DEFAULT", "Animated", strProgramdir & strThemedir & "terminal.skn") = True Then
        myAnim = iniValue
    End If
    If INI_GetKey("DEFAULT", "AnimDelay", strProgramdir & strThemedir & "terminal.skn") = True Then
        mySleep = iniValue
    End If
    If INI_GetKey("ABOUT", "Text-Register", strProgramdir & strThemedir & "terminal.skn") = True Then
        RegisterText = iniValue
    Else
        RegisterText = "This program is Shareware. If you like this program please register it."
    End If


    If INI_GetKey("DEFAULT", "BackGround", strProgramdir & strThemedir & strThemeName & ".skn") = True Then
        myKomma = InStr(iniValue, ",") + 1
        myRed = Val(Mid(iniValue, 1, myKomma - 2))
        myGreen = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1))
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myBlue = Val(Mid(iniValue, myKomma))
        myForm.BackColor = RGB(myRed, myGreen, myBlue)
    End If
    If INI_GetKey("DEFAULT", "StartupSound", strProgramdir & strThemedir & strThemeName & ".skn") = True Then
        mySound = iniValue
        PlaySound mySound, False
    End If
    myForm.Show
    DoEvents
    LoadControls myForm, "DEFAULT", myButCount, myButtons, myActions, mySndClick, mySndOver, mySecurity, myAnimCount, myAnimFrame, myAnimStart, myAnimEnd, myAnimCurrent, myAnim, mySleep, strProgramdir & strThemedir & strThemeName & ".skn"

End Sub

Public Sub Stop_Form(myForm As Form)
    Dim myCounter As Long
    On Error Resume Next
   
    If INI_GetKey("DEFAULT", "Animated", strProgramdir & strThemedir & "terminal.skn") = True Then
        myAnim = iniValue
    End If
    If INI_GetKey("DEFAULT", "AnimDelay", strProgramdir & strThemedir & "terminal.skn") = True Then
        mySleep = iniValue
    End If
   
    For myCounter = myForm.Controls.Count - 1 To myControls Step -1
        If myAnim = True And myForm.Controls(myCounter).Visible = True Then
            Sleep mySleep
        End If
        Unload myForm.Controls(myCounter)
        DoEvents
    Next

End Sub
