unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
BitBtn1: TBitBtn;
GroupBox1: TGroupBox;
Memo1: TMemo;
TV: TTreeView;
procedure FormCreate(Sender: TObject);
private
function GBToBig5(GBStr: string): AnsiString;
function Big5ToGB(BIG5Str: string): AnsiString;
function GBCht2Chs(GBStr: string): AnsiString;
function GBChs2Cht(GBStr: string): AnsiString;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GBToBig5(GBStr: string): AnsiString;
{进行GB转BIG5内码}
var
Len: Integer;
pGBCHTChar: PChar;
pGBCHSChar: PChar;
pUniCodeChar: PWideChar;
pBIG5Char: PChar;
begin
pGBCHSChar := PChar(GBStr);
Len := MultiByteToWideChar(936, 0, pGBCHSChar, -1, nil, 0);
GetMem(pGBCHTChar, Len * 2 + 1);
ZeroMemory(pGBCHTChar, Len * 2 + 1);
//GB CHS -> GB CHT
LCMapString($804, LCMAP_TRADITIONAL_CHINESE, pGBCHSChar, -1, pGBCHTChar, Len * 2);
GetMem(pUniCodeChar, Len * 2);
ZeroMemory(pUniCodeChar, Len * 2);
//GB CHT -> UniCode
MultiByteToWideChar(936, 0, pGBCHTChar, -1, pUniCodeChar, Len * 2);
Len := WideCharToMultiByte(950, 0, pUniCodeChar, -1, nil, 0, nil, nil);
GetMem(pBIG5Char, Len);
ZeroMemory(pBIG5Char, Len);
//UniCode -> Big5
WideCharToMultiByte(950, 0, pUniCodeChar, -1, pBIG5Char, Len, nil, nil);
Result := string(pBIG5Char);
FreeMem(pBIG5Char);
FreeMem(pGBCHTChar);
FreeMem(pUniCodeChar);
end;
function TForm1.Big5ToGB(BIG5Str: string): AnsiString;
{进行big5转GB内码}
var
Len: Integer;
pBIG5Char: PChar;
pGBCHSChar: PChar;
pGBCHTChar: PChar;
pUniCodeChar: PWideChar;
begin
//String -> PChar
pBIG5Char := PChar(BIG5Str);
Len := MultiByteToWideChar(950, 0, pBIG5Char, -1, nil, 0);
GetMem(pUniCodeChar, Len * 2);
ZeroMemory(pUniCodeChar, Len * 2);
//Big5 -> UniCode
MultiByteToWideChar(950, 0, pBIG5Char, -1, pUniCodeChar, Len);
Len := WideCharToMultiByte(936, 0, pUniCodeChar, -1, nil, 0, nil, nil);
GetMem(pGBCHTChar, Len * 2);
GetMem(pGBCHSChar, Len * 2);
ZeroMemory(pGBCHTChar, Len * 2);
ZeroMemory(pGBCHSChar, Len * 2);
//UniCode->GB CHT
WideCharToMultiByte(936, 0, pUniCodeChar, -1, pGBCHTChar, Len, nil, nil);
//GB CHT -> GB CHS
LCMapString($804, LCMAP_SIMPLIFIED_CHINESE, pGBCHTChar, -1, pGBCHSChar, Len);
Result := string(pGBCHSChar);
FreeMem(pGBCHTChar);
FreeMem(pGBCHSChar);
FreeMem(pUniCodeChar);
end;
function TForm1.GBCht2Chs(GBStr: string): AnsiString;
{进行GBK繁体转简体}
var
Len: Integer;
pGBCHTChar: PChar;
pGBCHSChar: PChar;
begin
pGBCHTChar := PChar(GBStr);
Len := MultiByteToWideChar(936, 0, pGBCHTChar, -1, nil, 0);
GetMem(pGBCHSChar, Len * 2 + 1);
ZeroMemory(pGBCHSChar, Len * 2 + 1);
//GB CHS -> GB CHT
LCMapString($804, LCMAP_SIMPLIFIED_CHINESE, pGBCHTChar, -1, pGBCHSChar, Len * 2);
Result := string(pGBCHSChar);
FreeMem(pGBCHSChar);
end;
function TForm1.GBChs2Cht(GBStr: string): AnsiString;
{进行GBK简体转繁体}
var
Len: Integer;
pGBCHTChar: PChar;
pGBCHSChar: PChar;
begin
pGBCHSChar := PChar(GBStr);
Len := MultiByteToWideChar(936, 0, pGBCHSChar, -1, nil, 0);
GetMem(pGBCHTChar, Len * 2 + 1);
ZeroMemory(pGBCHTChar, Len * 2 + 1);
//GB CHS -> GB CHT
LCMapString($804, LCMAP_TRADITIONAL_CHINESE, pGBCHSChar, -1, pGBCHTChar, Len * 2);
Result := string(pGBCHTChar);
FreeMem(pGBCHTChar);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Len, i: integer;
tmpCap: String;
begin
self.Font.Name := '新細明體';
self.Font.Charset := CHINESEBIG5_CHARSET;
self.Font.Size := 10;
self.Font.Color := clRed;
Len := Label1.GetTextLen;
SetString(tmpCap, PChar(nil), Len);
Label1.GetTextBuf(Pointer(tmpCap), Len + 1);
Label1.SetTextBuf(PChar(GBToBig5(tmpCap)));
Memo1.Text := GBToBig5(Memo1.Text);
GroupBox1.Caption := GBToBig5(GroupBox1.Caption);
BitBtn1.Caption := GBToBig5(BitBtn1.Caption);
for i := 0 to TV.Items.Count - 1do
TV.Items.Text := GBToBig5(TV.Items.Text);
TV.FullExpand;
end;
end.
我的代码是不是和你的是一样的?