Attribute VB_Name = "mod_Skin"
Option Explicit

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 myResizeDesktop As Boolean
Public myDesktop As RECT
Public myDesktopLeft As Long
Public myDesktopTop As Long
Public myWorktop As RECT
Public myPassword As String
Public myControls As Long

Public Sub HideTheme(strDir As String, strTheme As String, myform As Form)
    Dim myCounter As Long
    Dim mySleep As Long
    Dim myAnim As Boolean

    On Error Resume Next
    If INI_GetKey("DEFAULT", "Animated", strDir & strTheme) = True Then
        myAnim = iniValue
    End If
    If INI_GetKey("DEFAULT", "AnimDelay", strDir & strTheme) = True Then
        mySleep = iniValue
    End If
    
    For myCounter = myform.Controls.Count - 1 To myControls Step -1
        'If myform.Controls(myCounter).Visible = True Then
        '    myform.Controls(myCounter).Visible = False
        'End If
        Unload myform.Controls(myCounter)
        If myAnim = True Then
            Sleep mySleep
        End If
        DoEvents
    Next

End Sub

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)
            
            
    Dim myCounter As Long
    Dim myPicture 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 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
    
    
    myBcount = 0
    myCounter = 0
    myPicture = 0
    myAcount = 0
    myAframe = 0
    While INI_GetKey(mySection, Format(myCounter + 1, "00"), programDir & ThemeDir & ThemeName) = True
        tmpiniValue = iniValue
        If (INI_GetKey(mySection, Format(myCounter + 1, "00"), programDir & ThemeDir & Mid(ThemeName, 1, Len(ThemeName) - 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 = "P" Then
            myPicture = myPicture + 1
            Load myform.imgPic(myPicture)
            myform.imgPic(myPicture).Enabled = False
            myform.imgPic(myPicture).Stretch = 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))
            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(programDir & ThemeDir & 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) = Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma)
            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(programDir & ThemeDir & myFilename)
            myform.imgBut(myBcount).AutoRedraw = True
            myLCButtons(myBcount) = programDir & ThemeDir & 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
            
            'Eerste veld is de hele anim straks
            myAframe = myAframe + 1
            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).Enabled = False
            myform.imgGif(myAframe).Visible = True
            
            
            
            fptr = FreeFile
            Open programDir & ThemeDir & 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
                    If (myAframe = myLCAnimStart(myAcount) + 1) Then myform.imgGif(myLCAnimStart(myAcount)).Picture = myform.imgGif(myAframe).Picture
                    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
                If (myAframe = myLCAnimStart(myAcount) + 1) Then myform.imgGif(myLCAnimStart(myAcount)).Picture = myform.imgGif(myAframe).Picture
                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) + 1).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 Sub LoadStart(strDir As String, strTheme As String, myform As Form)
    Dim myKomma As Long
    Dim myRed As Long
    Dim myGreen As Long
    Dim myBlue As Long
    Dim myCounter As Long
    Dim myFilename As String
    Dim myLeft As Long
    Dim myTop As Long
    Dim myWidth As Long
    Dim myHeight As Long
    Dim ctlName As Control
    Dim myAnim As Boolean
    Dim mySleep As Long
    Dim strText As String

    If INI_GetKey("STARTUP", "StartupSound", strDir & strTheme) = True Then
        myFilename = iniValue
        PlaySound myFilename, False
    End If
    
    If INI_GetKey("STARTUP", "BackGround", strDir & strTheme) = 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
    
    myAnim = False
    
    
    If INI_GetKey("STARTUP", "Animated", strDir & strTheme) = True Then
        myAnim = iniValue
    End If
    If INI_GetKey("STARTUP", "AnimDelay", strDir & strTheme) = True Then
        mySleep = iniValue
    End If
    
    
    If INI_GetKey("DEFAULT", "size", strDir & strTheme) = True Then
        myKomma = InStr(iniValue, ",") + 1
        myform.Left = myDesktopLeft * Screen.TwipsPerPixelX
        myform.Top = myDesktopTop * Screen.TwipsPerPixelY
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myRed = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1)) * Screen.TwipsPerPixelX
        If myRed = 0 Then myRed = Screen.Width
        If myRed < 0 Then myRed = Screen.Width + myRed - myform.Left
        myform.Width = myRed
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myRed = Val(Mid(iniValue, myKomma)) * Screen.TwipsPerPixelY
        If myRed = 0 Then myRed = Screen.Height
        If myRed < 0 Then myRed = Screen.Height + myRed - myform.Top
        myform.Height = myRed
    End If
    
    myform.Show
    myCounter = 0
    While INI_GetKey("STARTUP", Format(myCounter + 1, "00"), strDir & strTheme) = True
        Load myform.imgPic(myCounter + 1)
        myform.imgPic(myCounter + 1).Enabled = False
        myform.imgPic(myCounter + 1).Stretch = True
        myKomma = InStr(iniValue, ",") + 1
        myFilename = Mid(iniValue, 1, myKomma - 2)
        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
        myform.imgPic(myCounter + 1).Left = myLeft
        myform.imgPic(myCounter + 1).Width = myWidth
        myform.imgPic(myCounter + 1).Top = myTop
        myform.imgPic(myCounter + 1).Height = myHeight
        myform.imgPic(myCounter + 1).Picture = LoadPicture(strDir & myFilename)
        myform.imgPic(myCounter + 1).Visible = True
        myCounter = myCounter + 1
        'If myAnim = True Then
            Sleep mySleep
        'End If
        DoEvents
    Wend
    
    Sleep 3000
    myPassword = GetSetting("LCARS Terminal", "DEFAULT", "Password", "")
    If myPassword = "" Then
        If INI_GetKey("DEFAULT", "Text-Pass", programDir & ThemeDir & ThemeName) = True Then
            strText = iniValue
        Else
            strText = "Enter a password for the secure sections in this program. Please remember the password because you need it to change settings and to enter secure sections."
        End If
        myPassword = InputBox(strText, "LCARS Terminal", "startrek")
        If myPassword <> "" Then
            SaveSetting "LCARS Terminal", "DEFAULT", "Password", myPassword
        End If
    End If

    For myRed = myform.Controls.Count - 1 To 0 Step -1
        For myGreen = 0 To myCounter - 1
            If myform.Controls(myRed).Name = "imgStartup_" & Format(myGreen, "00") Then
                myform.Controls(myRed).Visible = False
                'If myAnim = True Then
                    Sleep mySleep
                'End If
                DoEvents
            End If
        Next
    Next
End Sub

Public Sub LoadTheme(strDir As String, strTheme As String, myform As Form)
    Dim myFilename As String
    Dim myLeft As Long
    Dim myTop As Long
    Dim myWidth As Long
    Dim myHeight As Long
    Dim myKomma As Long
    Dim myCounter As Long
    Dim myAction As String
    Dim myPicture As Long
    Dim ctlName As Control
    Dim fptr
    Dim TimeWait As Long
    Dim I As Long
    Dim J As Long
    Static buf$, picbuf$
    Dim imgHeader As String
    Dim GifEnd
    Dim fileHeader As String
    Dim imgCount
    Dim myRed As Long
    Dim myGreen As Long
    Dim myBlue As Long
    Dim rgnPts(0 To 20) As POINTAPI
    Dim hRgn As Long
    Dim myMode As String
    Dim myAnim As Boolean
    Dim mySleep As Long
    
    SystemParametersInfo SPI_GETWORKAREA, vbNull, myWorktop, 0
    mySleep = myform.Controls.Count - 1
    For myCounter = myControls To mySleep
        Unload myform.Controls(myControls)
    Next
    mySleep = myform.Controls.Count - 1
    For myCounter = 0 To mySleep
        Debug.Print CStr(myCounter) & " " & myform.Controls(myCounter).Name
    Next
    frmMain.Visible = False
    
    If INI_GetKey("DEFAULT", "BackGround", strDir & strTheme) = 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", "Resize", strDir & strTheme) = True Then
        myResizeDesktop = iniValue
    End If
    
    If INI_GetKey("DEFAULT", "Animated", strDir & strTheme) = True Then
        myAnim = iniValue
    End If
    If INI_GetKey("DEFAULT", "AnimDelay", strDir & strTheme) = True Then
        mySleep = iniValue
    End If
    
    If INI_GetKey("DEFAULT", "size", strDir & strTheme) = True Then
        myKomma = InStr(iniValue, ",") + 1
        myform.Left = myDesktopLeft * Screen.TwipsPerPixelX
        myform.Top = myDesktopTop * Screen.TwipsPerPixelY
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myRed = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1)) * Screen.TwipsPerPixelX
        If myRed = 0 Then myRed = Screen.Width
        If myRed < 0 Then myRed = Screen.Width + myRed - myform.Left
        myform.Width = myRed
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myRed = Val(Mid(iniValue, myKomma)) * Screen.TwipsPerPixelY
        If myRed = 0 Then myRed = Screen.Height
        If myRed < 0 Then myRed = Screen.Height + myRed - myform.Top
        myform.Height = myRed
        
        
        myKomma = InStr(iniValue, ",") + 1
        myDesktopLeft = Val(Mid(iniValue, 1, myKomma - 2))
        myform.Left = myDesktopLeft * Screen.TwipsPerPixelX
        myDesktopTop = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1))
        myform.Top = myDesktopTop * Screen.TwipsPerPixelY
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myRed = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1)) * Screen.TwipsPerPixelX
        If myRed = 0 Then myRed = Screen.Width
        If myRed < 0 Then myRed = Screen.Width + myRed - myform.Left
        myform.Width = myRed
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myRed = Val(Mid(iniValue, myKomma)) * Screen.TwipsPerPixelY
        If myRed = 0 Then myRed = Screen.Height
        If myRed < 0 Then myRed = Screen.Height + myRed - myform.Top
        myform.Height = myRed
    End If
    SaveSetting "LCARS Terminal", "General", "Running", True
    
    If INI_GetKey("DEFAULT", "windows", strDir & strTheme) = True Then
        myKomma = InStr(iniValue, ",") + 1
        myRed = Val(Mid(iniValue, 1, myKomma - 2))
        myform.picDesktop(0).Left = myRed
        myRed = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1))
        myform.picDesktop(0).Top = myRed
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myRed = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1))
        If myRed <= 0 Then myRed = myform.ScaleWidth + myRed - myform.picDesktop(0).Left
        myform.picDesktop(0).Width = myRed
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myRed = Val(Mid(iniValue, myKomma))
        If myRed <= 0 Then myRed = myform.ScaleHeight + myRed - myform.picDesktop(0).Top
        myform.picDesktop(0).Height = myRed
        myDesktop.Left = myform.picDesktop(0).Left + (myform.Left / Screen.TwipsPerPixelX) ' + 4
        myDesktop.Top = myform.picDesktop(0).Top + (myform.Top / Screen.TwipsPerPixelY) ' + 4
        myDesktop.Right = myform.picDesktop(0).Left + (myform.Left / Screen.TwipsPerPixelX) + myform.picDesktop(0).Width ' - 6
        myDesktop.Bottom = myform.picDesktop(0).Top + (myform.Top / Screen.TwipsPerPixelY) + myform.picDesktop(0).Height ' - 6
        If (myResizeDesktop = True) Then
            SystemParametersInfo SPI_SETWORKAREA, vbNull, myDesktop, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE
            myform.Left = myDesktopLeft * Screen.TwipsPerPixelX
            myform.Top = myDesktopTop * Screen.TwipsPerPixelY
        End If
    End If
    frmMain.Visible = True
    
    'hier is het
    LoadControls myform, "DEFAULT", myButCount, myButtons, myActions, mySndClick, mySndOver, mySecurity, myAnimCount, myAnimFrame, myAnimStart, myAnimEnd, myAnimCurrent, myAnim, mySleep
    

    
    If INI_GetKey("DEFAULT", "windows", strDir & strTheme) = True Then
        myKomma = InStr(iniValue, ",") + 1
        myRed = Val(Mid(iniValue, 1, myKomma - 2))
        myform.picDesktop(0).Left = myRed
        myRed = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1))
        myform.picDesktop(0).Top = myRed
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myRed = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1))
        If myRed <= 0 Then myRed = myform.ScaleWidth + myRed - myform.picDesktop(0).Left
        myform.picDesktop(0).Width = myRed
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myRed = Val(Mid(iniValue, myKomma))
        If myRed <= 0 Then myRed = myform.ScaleHeight + myRed - myform.picDesktop(0).Top
        myform.picDesktop(0).Height = myRed
        myDesktop.Left = myform.picDesktop(0).Left + (myform.Left / Screen.TwipsPerPixelX) ' + 4
        myDesktop.Top = myform.picDesktop(0).Top + (myform.Top / Screen.TwipsPerPixelY) ' + 4
        myDesktop.Right = myform.picDesktop(0).Left + (myform.Left / Screen.TwipsPerPixelX) + myform.picDesktop(0).Width ' - 6
        myDesktop.Bottom = myform.picDesktop(0).Top + (myform.Top / Screen.TwipsPerPixelY) + myform.picDesktop(0).Height ' - 6
        'If (myResizeDesktop = True) Then
        '    SystemParametersInfo SPI_SETWORKAREA, vbNull, myDesktop, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE
        '    myform.Left = myDesktopLeft * Screen.TwipsPerPixelX
        '    myform.Top = myDesktopTop * Screen.TwipsPerPixelY
        'End If
        
        If INI_GetKey("DEFAULT", "desktop", strDir & strTheme) = True Then
            myKomma = InStr(iniValue, ",") + 1
            myRed = Val(Mid(iniValue, 1, myKomma - 2))
            myform.picDesktop(1).Left = myRed
            myRed = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1))
            myform.picDesktop(1).Top = myRed
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myRed = Val(Mid(iniValue, myKomma, InStr(myKomma, iniValue, ",") - 1))
            If myRed <= 0 Then myRed = myform.ScaleWidth + myRed - myform.picDesktop(0).Left
            myform.picDesktop(1).Width = myRed
            myKomma = InStr(myKomma + 1, iniValue, ",") + 1
            myRed = Val(Mid(iniValue, myKomma))
            If myRed <= 0 Then myRed = myform.ScaleHeight + myRed - myform.picDesktop(0).Top
            myform.picDesktop(1).Height = myRed
        Else
            myform.picDesktop(1).Left = myform.picDesktop(0).Left
            myform.picDesktop(1).Top = myform.picDesktop(0).Top
            myform.picDesktop(1).Width = myform.picDesktop(0).Width
            myform.picDesktop(1).Height = myform.picDesktop(0).Height
        End If
        
        
        rgnPts(0).X = 0
        rgnPts(0).Y = 0
        
        rgnPts(1).X = myform.picDesktop(0).Left
        rgnPts(1).Y = 0
        
        rgnPts(2).X = myform.picDesktop(0).Left
        rgnPts(2).Y = myform.picDesktop(0).Top + myform.picDesktop(0).Height
        
        rgnPts(3).X = myform.picDesktop(0).Left + myform.picDesktop(0).Width
        rgnPts(3).Y = myform.picDesktop(0).Top + myform.picDesktop(0).Height
        
        rgnPts(4).X = myform.picDesktop(0).Left + myform.picDesktop(0).Width
        rgnPts(4).Y = myform.picDesktop(0).Top
        
        rgnPts(5).X = myform.picDesktop(0).Left
        rgnPts(5).Y = myform.picDesktop(0).Top
        
        rgnPts(6).X = myform.picDesktop(0).Left
        rgnPts(6).Y = 0
        
        If myform.picDesktop(0).Left <> myform.picDesktop(1).Left Or _
        myform.picDesktop(0).Top <> myform.picDesktop(1).Top Or _
        myform.picDesktop(0).Width <> myform.picDesktop(1).Width Or _
        myform.picDesktop(0).Height <> myform.picDesktop(1).Height Then
            rgnPts(7).X = myform.picDesktop(1).Left
            rgnPts(7).Y = 0
            rgnPts(8).X = myform.picDesktop(1).Left
            rgnPts(8).Y = myform.picDesktop(1).Top + myform.picDesktop(1).Height
            rgnPts(9).X = myform.picDesktop(1).Left + myform.picDesktop(1).Width
            rgnPts(9).Y = myform.picDesktop(1).Top + myform.picDesktop(1).Height
            rgnPts(10).X = myform.picDesktop(1).Left + myform.picDesktop(1).Width
            rgnPts(10).Y = myform.picDesktop(1).Top
            rgnPts(11).X = myform.picDesktop(1).Left
            rgnPts(11).Y = myform.picDesktop(1).Top
            rgnPts(12).X = myform.picDesktop(1).Left
            rgnPts(12).Y = 0
            rgnPts(13).X = myform.ScaleWidth
            rgnPts(13).Y = 0
            rgnPts(14).X = myform.ScaleWidth
            rgnPts(14).Y = myform.ScaleHeight
            rgnPts(15).X = 0
            rgnPts(15).Y = myform.ScaleHeight
            hRgn = CreatePolygonRgn(rgnPts(0), 16, 1)
        Else
            rgnPts(7).X = myform.ScaleWidth
            rgnPts(7).Y = 0
            rgnPts(8).X = myform.ScaleWidth
            rgnPts(8).Y = myform.ScaleHeight
            rgnPts(9).X = 0
            rgnPts(9).Y = myform.ScaleHeight
            hRgn = CreatePolygonRgn(rgnPts(0), 10, 1)
        End If
        Call SetWindowRgn(myform.hwnd, hRgn, True)
    
        SaveSetting "LCARS Terminal", "Screen", "Left", myform.picDesktop(1).Left + (myform.Left / Screen.TwipsPerPixelX)
        SaveSetting "LCARS Terminal", "Screen", "Top", myform.picDesktop(1).Top + (myform.Top / Screen.TwipsPerPixelY)
        SaveSetting "LCARS Terminal", "Screen", "Right", myform.picDesktop(1).Left + (myform.Left / Screen.TwipsPerPixelX) + myform.picDesktop(1).Width
        SaveSetting "LCARS Terminal", "Screen", "Bottom", myform.picDesktop(1).Top + (myform.Top / Screen.TwipsPerPixelY) + myform.picDesktop(1).Height
    End If
    
    BackGroundMode = False
    If INI_GetKey("DEFAULT", "Playbackground", programDir & ThemeDir & "terminal.skn") = True Then
        BackGroundMode = iniValue
    End If
    
    If INI_GetKey("DEFAULT", "BackgroundSound", strDir & strTheme) = True Then
        BackGroundSound = iniValue
    End If
    If BackGroundMode = True Then
        PlayBackSound
    End If
    SaveSetting "LCARS Terminal", "Default", "ProgramDir", programDir
    SaveSetting "LCARS Terminal", "Default", "ThemeDir", ThemeDir
    
    myFilename = programDir & "\desktop.scf"
    fptr = FreeFile
    Open myFilename For Output As #fptr
    Print #fptr, "[Shell]"
    Print #fptr, "Command = 2"
    Print #fptr, "IconFile=explorer.exe,3"
    Print #fptr, "[Taskbar]"
    Print #fptr, "Command = ToggleDesktop"
    Close #fptr
    
    If INI_GetKey("DEFAULT", "Shell", strDir & strTheme) = True Then
        If iniValue = "True" Then
            ShellExecute frmMain.hwnd, "open", programDir & "\shell.exe", "", programDir, 1
        End If
    End If
    If INI_GetKey("DEFAULT", "VoiceControl", strDir & strTheme) = True Then
        If iniValue = "True" Then
            ShellExecute frmMain.hwnd, "open", programDir & "\voicecontrol.exe", "", programDir, 1
        End If
    End If
    ShellExecute frmMain.hwnd, "open", programDir & "\alert.exe", "", programDir, 1
    
End Sub
