日语系统显示汉字

在非中文操作系统下要正确显示简体汉字,需要解决如下问题:

  1. ANSI 字符串转 UNICODE 字符串的技术
  2. 设置显示字体的技术
  3. 显示 UNICODE 字符串的技术

中文 ANSI 字符串转 UNICODE 字符串的技术

function chnByteToWideChar(s:string; var ws:WideString):Integer;
var
  l : integer;
begin
  l := MultiByteToWideChar(936,0,pchar(s),-1,nil,0);
  setlength(ws,l);
  MultiByteToWideChar(936,0,pchar(s),-1,@ws[1],l);
  result := l;
end;

从MDB数据库获取UNICODE字符串

var
  l : integer;
  ws : widestring;
begin
  ws := widestring(rs.FieldByName('title').Value);
  l := Length(ws);
end;

设置显示字体的技术

function MakeFont(F:TFont):HGDIOBJ;
var
  bold:integer;
  obj : integer;
begin
  if fsBold in F.Style then bold:=700 else bold:=0;

  result := createfont(
    muldiv(F.size, 96, 72),
    muldiv(F.Size, 96, 72) div 2,
    0,0,
    bold,integer(fsItalic in F.Style),
    integer(fsUnderline in F.Style),integer(fsStrikeOut in F.Style),
    GB2312_charset,0,
    0,0,
    0,pchar(F.Name));
end;

显示 UNICODE 字符串的技术

l := chnByteToWideChar(ts.Text, ws);
selectobject(image1.Canvas.Handle,makefont(font));
settextcolor(image1.canvas.Handle, clBlack);
textoutw(image1.Canvas.Handle, 0,0, @ws[1], l );