VERSION 5.00
Begin VB.Form frmMediaControl 
   Appearance      =   0  'Flat
   AutoRedraw      =   -1  'True
   BackColor       =   &H00C0C0C0&
   BorderStyle     =   0  'None
   ClientHeight    =   11520
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   15360
   ControlBox      =   0   'False
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   Moveable        =   0   'False
   NegotiateMenus  =   0   'False
   PaletteMode     =   2  'Custom
   ScaleHeight     =   768
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   1024
   ShowInTaskbar   =   0   'False
   WindowState     =   2  'Maximized
   Begin VB.Timer Timer1 
      Interval        =   1000
      Left            =   90
      Top             =   10350
   End
   Begin VB.CommandButton cmdButton 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   525
      Index           =   0
      Left            =   300
      TabIndex        =   0
      Top             =   1080
      Visible         =   0   'False
      Width           =   1125
   End
   Begin VB.Label always_Date 
      BackColor       =   &H00FFFFFF&
      BackStyle       =   0  'Transparent
      Caption         =   "Date"
      BeginProperty Font 
         Name            =   "Century Gothic"
         Size            =   15.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0075544A&
      Height          =   375
      Left            =   75
      TabIndex        =   4
      Top             =   9600
      Width           =   7710
   End
   Begin VB.Label always_Time 
      Alignment       =   1  'Right Justify
      BackColor       =   &H00FFFFFF&
      BackStyle       =   0  'Transparent
      Caption         =   "Time"
      BeginProperty Font 
         Name            =   "Century Gothic"
         Size            =   15.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0075544A&
      Height          =   375
      Left            =   8100
      TabIndex        =   3
      Top             =   9600
      Width           =   7230
   End
   Begin VB.Label lblColumn 
      Alignment       =   2  'Center
      BackColor       =   &H00FFFFFF&
      BackStyle       =   0  'Transparent
      Caption         =   "Title"
      BeginProperty Font 
         Name            =   "Century Gothic"
         Size            =   14.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0075544A&
      Height          =   345
      Index           =   0
      Left            =   300
      TabIndex        =   2
      Top             =   690
      Width           =   1125
   End
   Begin VB.Label always_lblControl 
      Alignment       =   2  'Center
      BackColor       =   &H00FFFFFF&
      BackStyle       =   0  'Transparent
      Caption         =   "Media Control"
      BeginProperty Font 
         Name            =   "Century Gothic"
         Size            =   20.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00400000&
      Height          =   600
      Left            =   60
      TabIndex        =   1
      Top             =   60
      Width           =   2850
   End
   Begin VB.Image optLightControl 
      Height          =   1200
      Left            =   1710
      Top             =   10140
      Width           =   2670
   End
   Begin VB.Image optMP3Control 
      Height          =   1140
      Left            =   5190
      Top             =   10200
      Width           =   2610
   End
   Begin VB.Image optWebControl 
      Height          =   1170
      Left            =   8640
      Top             =   10170
      Width           =   2460
   End
   Begin VB.Image optMediaControl 
      Height          =   1215
      Left            =   11910
      Top             =   10140
      Width           =   2670
   End
   Begin VB.Image cmd_Exit 
      Height          =   615
      Left            =   60
      Top             =   10860
      Width           =   1125
   End
End
Attribute VB_Name = "frmMediaControl"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim media_ini As String, inifile As String, imgpath As String
Dim NumDevices As Integer, DeviceName() As String
Dim NumCmd() As Integer, TotalCmd As Integer, ColCount As Integer
Dim AllCmdlbl() As String, AllCmd() As String
Dim FormWidth As Integer, BPC As Integer
Dim Skin As String, SkinPath As String

Private Sub cmd_Exit_Click()
    Unload frmMusic
    Unload frmMain
    Unload frmWeb
    Unload frmMediaControl
End Sub

Private Sub cmdButton_Click(Index As Integer)
    'frmMain.winsock1.SendData "ir" & cmdButton(Index).Tag
    'SeerCmd_Msg "ir" & cmdButton(Index).Tag
End Sub

'Create controls dynamically.  Store the number of devices and commands.
'Put the actual command into the Tag of the created control.

Private Sub Form_Load()
    Dim s As String, i As Integer, j As Integer, n As Integer
    Dim temptag As String, DevCmd As Variant
    media_ini = App.Path & "\MediaPanel.ini"
    inifile = App.Path & "\HomePanel.ini"
    imgpath = App.Path & "\images\"
    Me.always_Date.Caption = "": Me.always_Time.Caption = ""
    fReadValue inifile, "Options", "MakeSkin", "S", "0", temptag
    If temptag = "1" Then PrintControl frmMediaControl, "Section4": End
       
    FormWidth = 780: BPC = 17
    fReadValue inifile, "Section4", "Background", "S", "err", temptag
    If temptag <> "err" Then frmMediaControl.Picture = LoadPicture(imgpath & temptag)
    fReadValue inifile, "Section4", "MainLabel", "S", "err", temptag
    If temptag <> "err" Then frmMediaControl.always_lblControl.Caption = temptag
    SkinMe "Section4", frmMediaControl
    
    TotalCmd = 0: n = 0: ColCount = 0
    fReadValue media_ini, "DeviceList", "NumberofDevices", "S", "0", s
    NumDevices = CLng(s)
    ReDim DeviceName(NumDevices)
    ReDim NumCmd(NumDevices)
    For i = 1 To NumDevices
        fReadValue media_ini, "DeviceList", "Device" & i, "S", "err", s
        DeviceName(i - 1) = s
        fReadValue media_ini, "Device" & i, "NumberofCommands", "S", "0", s
        NumCmd(i - 1) = CLng(s)
        TotalCmd = TotalCmd + NumCmd(i - 1)
    Next i
    ReDim AllCmd(TotalCmd)
    ReDim AllCmdlbl(TotalCmd)
    For i = 1 To NumDevices
        For j = 1 To NumCmd(i - 1)
            If j = 17 Or j = 34 Or j = 51 Then ColCount = ColCount + 1
            fReadValue media_ini, "Device" & i, "Command" & j, "S", "", s
            AllCmd(n) = s
            fReadValue media_ini, "Device" & i, "Label" & j, "S", "", s
            AllCmdlbl(n) = s
            DevCmd = Split(AllCmd(n), ",")
            If AllCmdlbl(n) = "" Then AllCmdlbl(n) = DevCmd(1)
            n = n + 1
        Next j
        ColCount = ColCount + 1
    Next i
    cmdButton(0).Width = FormWidth / ColCount
    lblColumn(0).Width = FormWidth / ColCount
    AddButtons
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set frmMediaControl = Nothing
End Sub

Private Sub AddButtons()
    Dim i As Integer, j As Integer, n As Integer
    Dim col As Integer, lcol As Integer
    col = 0: lcol = 0: n = 0
    lblColumn(col).Caption = DeviceName(n)
    For i = 1 To NumDevices
        lcol = 0
        lblColumn(col).Move lblColumn(col).Left + col * lblColumn(col).Width
        lblColumn(col).Caption = DeviceName(i - 1)
        lblColumn(col).Visible = True
        For j = 1 To NumCmd(i - 1)
            n = n + 1
            Load cmdButton(n)
            With cmdButton(n)
                If (j Mod BPC) = 0 Then
                    col = col + 1: lcol = 0
                    Load lblColumn(col)
                    lblColumn(col).Move lblColumn(col).Left + col * lblColumn(col).Width
                    lblColumn(col).Caption = DeviceName(i - 1)
                    lblColumn(col).Visible = True
                End If
                .Move .Left + col * .Width, cmdButton(1).Top + (lcol) * .Height
                .Caption = AllCmdlbl(n - 1)
                .Tag = AllCmd(n - 1)
                .Visible = True
                lcol = lcol + 1
            End With
        Next j
        col = col + 1
        Load lblColumn(col)
    Next i
End Sub

Public Sub TimerStart()
    'Timer2.Enabled = True:  Timer3.Enabled = True
End Sub

Private Sub optLightControl_Click()
    If Section1 Then
        frmMain.Show
        frmMediaControl.Hide
        frmMain.optLightControl_Click
        frmMain.TimerStart
    End If
End Sub

Private Sub optMP3Control_Click()
    If Section2 Then
        frmMusic.Show
        frmMediaControl.Hide
        frmMusic.TimerStart
    End If
End Sub

Private Sub optWebControl_Click()
    If Section3 Then
        frmWeb.Show
        frmMediaControl.Hide
        frmWeb.TimerStart
    End If
End Sub

Private Sub Timer1_Timer()
    If Me.always_Date.Caption <> Format(Date, "mmm-dd-yyyy") Then Me.always_Date.Caption = Format(Date, "mmm-dd-yyyy")
    Me.always_Time.Caption = Format(Now, "hh:mm:ss AM/PM")
End Sub

Public Function gc(n As String) As Control
    Dim tempctl As Control
    For Each tempctl In frmMediaControl
        If tempctl.Name = n Then Set gc = tempctl: Exit For
    Next tempctl
End Function

Private Sub SkinMe(Section As String, frm As Form)
    Dim ctl As Control, temptag As String, FontMod As Integer
    Dim pos As Variant, size As Variant, c As Variant
    
    fReadValue inifile, "Options", "Skin", "S", "", Skin
    If Skin = "" Then Exit Sub
    SkinPath = App.Path & "\skin\" & Skin & "\"
    Skin = SkinPath & "skin.ini"
    fReadValue Skin, Section, "FontSizeMod", "S", "0", temptag
    FontMod = Val(temptag)
    For Each ctl In frm
        On Error Resume Next
        Err.Clear
        fReadValue Skin, Section, "Image_" & ctl.Name, "S", "", temptag
        If LCase(temptag) = "none" Then ctl.Picture = LoadPicture(): temptag = ""
        If temptag <> "" Then ctl.Picture = LoadPicture(SkinPath & temptag)
        If Err.Number <> 0 Then Err.Clear
        ctl.FontSize = ctl.FontSize + FontMod
        If Err.Number <> 0 Then Err.Clear
        fReadValue Skin, Section, "PosXY_" & ctl.Name, "S", "", temptag
        If temptag <> "" Then
            pos = Split(temptag, ",", 2)
            If Err.Number <> 0 Then Err.Clear
            ctl.Move pos(0), pos(1)
            If Err.Number <> 0 Then Err.Clear
        End If
        
        fReadValue Skin, Section, "FontName_" & ctl.Name, "S", "", temptag
        If temptag <> "" Then ctl.Font = temptag
        If Err.Number <> 0 Then Err.Clear
        
        fReadValue Skin, Section, "FontColorRGB_" & ctl.Name, "S", "", temptag
        c = Split(temptag, ",")
        If Err.Number <> 0 Then Err.Clear: temptag = ""
        If temptag <> "" Then
            ctl.ForeColor = RGB(c(0), c(1), c(2))
            If Err.Number <> 0 Then Err.Clear
        End If
        
        fReadValue Skin, Section, "FontSize_" & ctl.Name, "S", "", temptag
        If temptag <> "" Then ctl.FontSize = Val(temptag)
        If Err.Number <> 0 Then Err.Clear
        
        fReadValue Skin, Section, "BorderColorRGB_" & ctl.Name, "S", "", temptag
        c = Split(temptag, ",")
        If Err.Number <> 0 Then Err.Clear: temptag = ""
        If temptag <> "" Then
            ctl.BorderColor = RGB(c(0), c(1), c(2))
            If Err.Number <> 0 Then Err.Clear
        End If
        
        fReadValue Skin, Section, "BackColorRGB_" & ctl.Name, "S", "", temptag
        If LCase(temptag) = "none" Then
            ctl.BackStyle = 0
            If Err.Number <> 0 Then Err.Clear
        Else
            If temptag <> "" Then ctl.BackStyle = 1
            If Err.Number <> 0 Then Err.Clear
        End If
        c = Split(temptag, ",")
        If Err.Number <> 0 Then Err.Clear: temptag = ""
        If temptag <> "" Then
            ctl.BackColor = RGB(c(0), c(1), c(2))
            If Err.Number <> 0 Then Err.Clear
        End If
        
        fReadValue Skin, Section, "SizeWH_" & ctl.Name, "S", "", temptag
        If temptag <> "" Then
            size = Split(temptag, ",", 2)
            If Err.Number <> 0 Then Err.Clear
            ctl.Move ctl.Left, ctl.Top, size(0), size(1)
            If Err.Number <> 0 Then Err.Clear
            
            If Left(ctl.Name, 5) = "line_" Then
                ctl.X1 = pos(0): ctl.X2 = pos(0) + size(0)
                ctl.Y1 = pos(1): ctl.Y2 = pos(1)
            End If
        End If
    Next ctl
    
    fReadValue Skin, Section, "Background", "S", "", temptag
    If temptag <> "" Then frm.Picture = LoadPicture(SkinPath & temptag)
    fReadValue Skin, Section, "ButtonsPerColumn", "S", "17", temptag
    BPC = Val(temptag)
    fReadValue Skin, Section, "ButtonFormWidth", "S", "780", temptag
    FormWidth = Val(temptag)
    
End Sub

Private Sub PrintControl(frm As Form, sect As String)
    Dim c As Control, x As String, temptag As String
    Skin = "": SkinPath = ""
    fReadValue inifile, "Options", "Skin", "S", "", Skin
    If Skin = "" Then Exit Sub
    SkinPath = App.Path & "\skin\" & Skin & "\"
    Skin = SkinPath & "skin.ini"
    For Each c In frm
        x = c.Name
        If LCase(Left(x, 5)) <> "timer" And LCase(Left(x, 5)) <> "winso" And LCase(Left(x, 5)) <> "line_" Then
            x = "PosXY_" & c.Name
            fReadValue Skin, sect, x, "S", "err", temptag
            If temptag <> "err" Then fWriteValue Skin, sect, x, "S", c.Left & "," & c.Top
            x = "SizeWH_" & c.Name
            fReadValue Skin, sect, x, "S", "err", temptag
            If temptag <> "err" Then fWriteValue Skin, sect, x, "S", c.Width & "," & c.Height
            x = "FontSize_" & c.Name
            fReadValue Skin, sect, x, "S", "err", temptag
            If temptag <> "err" Then fWriteValue Skin, sect, x, "S", c.FontSize
            x = "FontColorRGB_" & c.Name
            fReadValue Skin, sect, x, "S", "err", temptag
            If temptag <> "err" Then fWriteValue Skin, sect, x, "S", RGBS(c.ForeColor)
            x = "BorderColorRGB_" & c.Name
            fReadValue Skin, sect, x, "S", "err", temptag
            If temptag <> "err" Then fWriteValue Skin, sect, x, "S", RGBS(c.BorderColor)
            x = "BackColorRGB_" & c.Name
            fReadValue Skin, sect, x, "S", "err", temptag
            If temptag <> "err" Then fWriteValue Skin, sect, x, "S", RGBS(c.BackColor)
            Debug.Print "Sent Media - " & c.Name
        End If
        If LCase(Left(x, 5)) = "line_" Then
            x = "PosXY_" & c.Name
            fReadValue Skin, sect, x, "S", "err", temptag
            If temptag <> "err" Then fWriteValue Skin, sect, x, "S", c.X1 & "," & c.Y1
            x = "SizeWH_" & c.Name
            fReadValue Skin, sect, x, "S", "err", temptag
            If temptag <> "err" Then fWriteValue Skin, sect, x, "S", (c.X2 - c.X1) & "," & (c.Y2 - c.Y1)
            Debug.Print "Sent Music - " & c.Name
        End If
    Next c
End Sub
