' Unicode(UTF16) -> MultiByte(UTF8) API
Private Declare Function WideCharToMultiByte Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cbMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cbMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Function PathFileExistsW Lib "shlwapi.dll" (ByVal lpathfile As Long) As Boolean
' 常量定义
Private Const WC_NO_BEST_FIT_CHARS As Long = &H400
Private Const CP_UTF8 As Long = 65001
Dim lpWav As String
' 输入:VB6原生字符串(UTF16)
' 输出:UTF8编码的Byte数组
Public Function UnicodeToUTF8(ByVal strUnicode As String) As Byte()
Dim lngStrLen As Long
Dim lngBufSize As Long
Dim abytUTF8() As Byte
' 源字符串长度(字符数)
lngStrLen = Len(strUnicode)
If lngStrLen = 0 Then
ReDim UnicodeToUTF8(-1) ' 返回空数组
Exit Function
End If
' 逐字节拷贝
For I = 1 To rawLen
out(3 + I) = raw(I)
Next I
UnicodeToUTF8_BOM = out
End Function
Public Sub SaveAsUTF8(ByVal sText As String, ByVal sFilePath As String)
Dim bUTF8() As Byte
Dim fNum As Integer
bUTF8 = UnicodeToUTF8(sText)
fNum = FreeFile
Open sFilePath For Binary As #fNum
Put #fNum, , bUTF8
Close #fNum
End Sub
Public Function BytesToHex(bArr() As Byte) As String
Dim I As Long
Dim sOut As String
For I = LBound(bArr) To UBound(bArr)
sOut = sOut & Right("00" & Hex(bArr(I)), 2) & " "
Next
BytesToHex = Trim(sOut)
End Function
'============Form Commnd====================
Private Sub CD_Click()
Dim lW As String, LstD() As Byte, Dt() As String, LstStr As String, lD As String
On Error GoTo Err_x
lpWav = GetFilePaths(Form1.hWnd, "打开WAVE文件", "WAV文件|*.WAV|", Explorer窗口, App.Path, Chr(0))
T.Text = Replace(LstStr, Chr(0), "") & vbCrLf & "文件路径:" & lpWav
' End If
Exit Sub
Err_x:
T.Text = LstStr & vbCrLf & "文件路径:" & lpWav
End Sub
Public Function GetXFontSize(ByVal XF As Form, ByVal THeight As Long) As Long
Dim I As Long, X(1 To 32) As Long
For I = 1 To 32
XF.ScaleMode = 3
XF.Font.Size = I
If XF.TextHeight("H") = THeight Then
GetXFontSize = I
End If
Next
If GetXFontSize = 0 Then
For I = 1 To 32
XF.ScaleMode = 3
XF.Font.Size = I
If XF.TextHeight("H") > THeight And I > 1 Then
X(I) = XF.TextHeight("H")
If X(I - 1) < THeight Then
GetXFontSize = IIf(X(I) - THeight < THeight - X(I - 1), I, I - 1)
End If
Exit For
End If
Next
End If
End Function
Dim lpOut As String
lpOut = Left(lpWav, InStrRev(lpWav, ".") - 1) & "_list.wav"
CreateListWaveFile lpWav, lpOut, LDI, Ls
End Sub
Private Sub Command1_Click()
Dim LDI(4) As LSTDATAINFO, Ls(4) As Variant
If IT(1).Text = "标题" Or IT(1).Text = "" Or IT(0).Text = "艺术家" Or IT(0).Text = "" Or IT(2).Text = "专辑" Or IT(2).Text = "" Then Exit Sub
If CB(0).Text = "中日英文字" Then
Ls(0) = UnicodeToUTF8(IT(0).Text & Chr(0))
LDI(0).Size = Val(UBound(UnicodeToUTF8(IT(0).Text & Chr(0))))
Else
Ls(0) = UnicodeToUTF8_BOM(IT(0).Text & Chr(0))
LDI(0).Size = Val(UBound(UnicodeToUTF8_BOM(IT(0).Text & Chr(0))))
End If
If CB(1).Text = "中日英文字" Then
Ls(1) = UnicodeToUTF8(IT(1).Text & Chr(0))
LDI(1).Size = Val(UBound(UnicodeToUTF8(IT(1).Text & Chr(0))))
Else
Ls(1) = UnicodeToUTF8_BOM(IT(1).Text & Chr(0))
LDI(1).Size = Val(UBound(UnicodeToUTF8_BOM(IT(1).Text & Chr(0))))
End If
If CB(2).Text = "中日英文字" Then
Ls(2) = UnicodeToUTF8(IT(2).Text & Chr(0))
LDI(2).Size = Val(UBound(UnicodeToUTF8(IT(2).Text & Chr(0))))
Else
Ls(2) = UnicodeToUTF8_BOM(IT(2).Text & Chr(0))
LDI(2).Size = Val(UBound(UnicodeToUTF8_BOM(IT(2).Text & Chr(0))))
End If
If CB(3).Text = "中日英文字" Then
Ls(3) = UnicodeToUTF8(IT(3).Text & Chr(0))
LDI(3).Size = Val(UBound(UnicodeToUTF8(IT(3).Text & Chr(0))))
Else
Ls(3) = UnicodeToUTF8_BOM(IT(3).Text & Chr(0))
LDI(3).Size = Val(UBound(UnicodeToUTF8_BOM(IT(3).Text & Chr(0))))
End If
Private Sub Command2_Click()
Dim lpOut As String
lpOut = Left(lpWav, InStrRev(lpWav, ".") - 1) & "_nolist.wav"
CreateNoListWaveFile lpWav, lpOut
End Sub
Private Sub Form_Load()
Dim I As Byte
For I = 0 To 3
CB(I).AddItem "中日英文字"
CB(I).AddItem "其他文字"
CB(I).Text = "中日英文字"
Next
End Sub
'Judge ID rule
Private Function GetRuleID(ByVal ID As String) As Boolean
Dim I As Integer, StrX As String, Str3 As String
For I = 1 To 4
StrX = Mid(ID, I, 1)
If I <= 3 Then
If Asc(StrX) < 65 Or Asc(StrX) > 122 Then
GetRuleID = False: Exit For
Else
GetRuleID = True
End If
Else
Str3 = Left(ID, 3)
If (Asc(StrX) < 65 Or Asc(StrX) > 122) Then
If UCase(Str3) = "FMT" And Asc(StrX) = 32 Then
GetRuleID = True
Else
GetRuleID = False: Exit For
End If
Else
GetRuleID = True
End If
End If
Next
End Function
'GET LIST INFO
Private Function GetWavListKey(Dat() As Byte) As String
Dim wBt() As Byte, LDI As LSTDATAINFO, StepX As Integer, TmpStr As String, ID As String
On Error GoTo Err_INF
Do Until StepX >= UBound(Dat)
GetWantData Dat, wBt, StepX, 8
RtlMoveMemory LDI, wBt(0), 8
Erase wBt
ID = LDI.ID
If GetRuleID(ID) = False Then
StepX = StepX + 1
GetWantData Dat, wBt, StepX, 8
RtlMoveMemory LDI, wBt(0), 8
Erase wBt
Else
TmpStr = TmpStr & LDI.ID & "="
TmpStr = Replace(TmpStr, Chr(0), "")
StepX = StepX + 8
GetWantData Dat, wBt, StepX, Val(LDI.Size)
TmpStr = TmpStr & Utf8ToStr(wBt, LDI.Size) & vbCrLf
Erase wBt
StepX = StepX + Val(LDI.Size)
If StepX = UBound(Dat) Then Exit Do
End If
Loop
GetWavListKey = TmpStr
Exit Function
Err_INF:
GetWavListKey = ""
End Function
'--- UTF-8 Byte数组 → VB6 Unicode String ---
Private Function Utf8ToStr(b() As Byte, ByVal Length As Long) As String
Dim Ws As String, Rtn As Long
If Length <= 0 Then Exit Function
Ws = Space$(Length)
' MultiByteToWideChar CP_UTF8=65001
Rtn = MultiByteToWideChar(65001, 0, VarPtr(b(0)), Length, StrPtr(Ws), Length)
Utf8ToStr = Left(Ws, Rtn)
End Function