Attribute VB_Name = "libPrivateInfo"
Option Explicit

Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) 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 WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Public Declare Function ExpandEnvironmentStrings Lib "kernel32" Alias "ExpandEnvironmentStringsA" (ByVal lpSrc As String, ByVal lpDst As String, ByVal nSize As Long) As Long
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) 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 HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long

Public Declare Function GetSystemDefaultLangID Lib "kernel32" () As Integer
       
Global Const HH_DISPLAY_TOPIC = &H0
Global Const HH_DISPLAY_TOC = &H1
Global Const HH_DISPLAY_INDEX = &H2
Global Const HH_DISPLAY_SEARCH = &H3

Dim szLanFile As String ' Language Profile
Dim szProfile As String ' Private Information File




Function GetEMailPro() As String
    Dim sValue As String, nLength As Long
    
    sValue = String(128, 0)
    nLength = GetWindowsDirectory(sValue, Len(sValue))
    sValue = Mid$(Left(sValue, nLength), 1, 3)
    
    GetEMailPro = sValue + "Program Files\Outlook Express\msimn.exe"
End Function

Function GetInterPro() As String
    Dim sValue As String, nLength As Long
    
    sValue = String(128, 0)
    nLength = GetWindowsDirectory(sValue, Len(sValue))
    sValue = Mid$(Left(sValue, nLength), 1, 3)
    
    GetInterPro = sValue + "Program Files\Internet Explorer\Iexplore.exe"
End Function


Function GetSettingStrX(Section As String, KeyName As String, Optional DefValue As String = "", Optional InfoFile As String = "") As String
    Dim nLength As Integer, sValue As String
    
    sValue = String(1024, 0)
    
    If InfoFile = "" Then
        nLength = GetPrivateProfileString(Section, KeyName, DefValue, sValue, Len(sValue), App.path + "\" + App.Title + ".INF")
    Else
        nLength = GetPrivateProfileString(Section, KeyName, DefValue, sValue, Len(sValue), InfoFile)
    End If
    
    If nLength > 0 Then
        GetSettingStrX = Replace(Left$(sValue, nLength), "\n", vbCrLf)
    Else
        GetSettingStrX = DefValue
    End If
End Function


Function GetWinDirectory() As String
    Dim sValue As String, nLength As Long
    
    sValue = String(128, 0)
    nLength = GetWindowsDirectory(sValue, Len(sValue))
    If nLength > 0 Then
        GetWinDirectory = Left(sValue, nLength)
    End If
End Function

' User Tag Number Load Language String
' 2001/10/05 Jason Liao
Public Sub LoadResStrings(frm As Form)
    Dim ctl As Control
    Dim obj As Object
    Dim but As Object
    Dim fnt As Font
    Dim sCtlType As String
    Dim nVal As Long
    Dim i As Integer, ctlWidth As Double, ctlHeight As Double
    
    If szLanFile = "" Then Exit Sub
    
    ' Update Form
    frm.Caption = LoadResStringX(val(frm.Tag), frm.Caption)
    
    On Error Resume Next
    If LoadResStringX(20) <> "" Then
        Set fnt = frm.Font
        fnt.Name = "Fixedsys"   ' 2002/11/6 Jason for Japanese change
        fnt.Name = LoadResStringX(20)
        fnt.size = CInt(LoadResStringX(21))
    End If
    
    On Error Resume Next
    For Each ctl In frm.Controls
        'If ctl.Visible Then
        
            ctlWidth = ctl.Width
            ctlHeight = ctl.Height
            
            ctl.Font.Name = "Fixedsys"  ' 2002/11/6 Jason for Japanese change
            ctl.Font.Name = fnt.Name
            ctl.Font.size = fnt.size

            Select Case TypeName(ctl)
                Case "Toolbar"
                    For Each but In ctl.Buttons
                        but.ToolTipText = LoadResStringX(CLng(but.ToolTipText), "")
                    Next
                Case "Menu"
                    ctl.Caption = LoadResStringX(ctl.HelpContextID, ctl.Caption)
                Case "TabStrip"
                    For Each obj In ctl.Tabs
                        obj.Caption = LoadResStringX(CLng(obj.Tag), obj.Caption)
                        obj.ToolTipText = LoadResStringX(CLng(obj.ToolTipText), obj.ToolTipText)
                    Next
                Case "SSTab"
                    For i = 0 To ctl.Tabs - 1
                        ctl.Tab = i
                        ctl.Caption = LoadResStringX(CLng(ctl.Caption), ctl.Caption)
                        ctl.ToolTipText = LoadResStringX(CLng(obj.ctltooltiptext), obj.ToolTipText)
                    Next
                Case "Toolbar"
                    For Each obj In ctl.Buttons
                        obj.Caption = LoadResStringX(CInt(obj.Caption))
                        obj.ToolTipText = LoadResStringX(CInt(obj.ToolTipText), obj.ToolTipText)
                    Next
                Case "ListView"
                    For Each obj In ctl.ColumnHeaders
                        obj.Text = LoadResStringX(CInt(obj.Tag), obj.Text)
                    Next
                Case "PictureBox"
                    If ctl.Tag <> "" Then
                        ctl.Picture = LoadResPicture(CInt(ctl.Tag), 0)
                    End If
                Case "Image"
                    If CInt(ctl.Tag) > 0 Then
                        ctl.Picture = LoadResPicture(CInt(ctl.Tag), 0)
                    End If
                    If CInt(ctl.ToolTipText) > 0 Then
                        ctl.ToolTipText = LoadResStringX(CInt(ctl.ToolTipText))
                    End If
                Case "TextBox"
                    If CLng(ctl.Tag) > 0 Then
                        ctl.Text = LoadResStringX(CLng(ctl.Tag), ctl.Text)
                    End If
                Case Else
                    If CLng(ctl.Tag) > 0 Then ctl.Caption = LoadResStringX(CLng(ctl.Tag), ctl.Caption)
                    If CLng(ctl.ToolTipText) > 0 Then ctl.ToolTipText = LoadResStringX(CLng(ctl.ToolTipText), ctl.ToolTipText)
            End Select
            
            If ctl.Height < ctlHeight Then ctl.Height = ctlHeight + fnt.size
        'End If
    Next
    On Error GoTo 0
End Sub


Public Function LoadResStringX(key As Long, Optional ByVal DefValue As String = "") As String
    Dim szValue As String, nLength As Long
    
    szValue = String(1024, 0)
    nLength = GetPrivateProfileString("LANGUAGE", CStr(key), DefValue, szValue, Len(szValue), szLanFile)
    
    If nLength > 0 Then
        LoadResStringX = Replace(Left(szValue, nLength), "\n", vbCrLf)
    Else
        LoadResStringX = DefValue
    End If
End Function

' User Object Caption Load Language String
' 2001/10/05
Public Function LoadResStringZ(key As String) As String
    Dim szValue As String, nLength As Long
    
    szValue = String(1024, 0)
    nLength = GetPrivateProfileString("LANGUAGE", CStr(key), "", szValue, Len(szValue), szLanFile)
    
    If nLength > 0 Then
        LoadResStringZ = Left(szValue, nLength)
    Else
        LoadResStringZ = key
    End If
End Function

Public Sub SetLanguageProfile(FileName As String)
    szLanFile = FileName
End Sub




Function SetSettingStrX(Section As String, KeyName As String, sValue As String, Optional InfoFile As String = "") As Boolean
    Dim result As Boolean
    
    sValue = Replace(sValue, vbCrLf, "\n")
    
    If InfoFile = "" Then
        SetSettingStrX = WritePrivateProfileString(Section, KeyName, sValue, App.path + "\" + App.Title + ".INF")
    Else
        SetSettingStrX = WritePrivateProfileString(Section, KeyName, sValue, InfoFile)
    End If
    
End Function


