Inhalt test.data:
BBC6BBE8CAA5B5EE33C7F8B5A5C8CBC4A3CABDD7E8B5B2C3C500000000
Code: Alles auswählen
Enumeration
#Window
#File
#Library
#String_0
#String_1
#String_2
#Font
EndEnumeration
LoadFont (#Font, "SimSun", 40)
If ReadFile(#File, "C:\test.data")
input.s = ReadString(#File, #PB_Unicode)
CloseFile(#File)
EndIf
#UseDLL = 0 ; 1 use transformation via c_g18030.dll
; 0 use transformation via MultiByteToWideChar_ / WideCharToMultiByte_
output.s = Space(Len(input))
If #UseDLL
pcchLeftOverBytes.s = Space(Len(input)) ; UINT that contains GB18030 bytes at the end of the buffer
; that cannot be converted. These bytes could be the leading
; bytes of valid GB18030 bytes in the Next incoming GB18030 bytes.
OpenLibrary(#Library, "c_g18030.dll")
CallFunction(#Library, "BytesToUnicode", @input, Len(input)*2, @pcchLeftOverBytes, @output, Len(output)*2)
; Transforms Unicode (GB2212) to GB18030
output2.s = Space(Len(output))
CallFunction(#Library, "UnicodeToBytes", @output, Len(output), @output2, Len(output2) * 2)
; Transforms GB18030 to Unicode (GB2212)
Else
CodePage = 54936 ; CodePage of GB18030
dwFlags = 0 ; Otherwise, the function fails with ERROR_INVALID_FLAGS
MultiByteToWideChar_(CodePage, dwFlags, @input, Len(input)*2, @output, Len(output)*2)
; Transforms Unicode (GB2212) to GB18030
output2.s = Space(Len(output))
WideCharToMultiByte_(CodePage, dwFlags, @output, Len(output)*2, @output2, Len(output2) * 2, 0, 0)
; Transforms GB18030 to Unicode (GB2212)
EndIf
If OpenWindow(#Window, 100, 200, 750, 200, "GB18030 transformation demo")
If CreateGadgetList(WindowID(0))
StringGadget(#String_0, 10, 10, 730, 60, "Unicode (GB2212)")
StringGadget(#String_1, 10, 70, 730, 60, "Unicode (GB2212) -> GB18030")
StringGadget(#String_2, 10, 130, 730, 60, "GB18030 -> Unicode (GB2212)")
EndIf
SetGadgetFont(#String_0, FontID(#Font))
SetGadgetFont(#String_1, FontID(#Font))
SetGadgetFont(#String_2, FontID(#Font))
SetGadgetText(#String_0, input)
SetGadgetText(#String_1, output)
SetGadgetText(#String_2, output2)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
quit = 1
EndIf
Until quit = 1
EndIf
End

oben: Unicode-String in GB2312 dargestellt
mitte: Unicode-String in GB18030 konvertiert
unten: GB18030-String zurück in Unicode-String (GB2312) konvertiert
Titel ergänzt - Suchtags hinzugefügt - Kaeru fecit
Suchtags:
Zeichensatz Font Schriftzeichen Unicode Gadget Darstellung