procedure TForm1.DrawFont(ParentHandle: HWND; x, y, fw, fh: Integer; c: string);
var
FLogFont : tagLogFontA; //逻辑字体--结构体类型
hTempFont,
hPrevFont : HFONT; //字体句柄
hTempDC : HDC; //设备描述表或图形设备句柄
TempString : string; //输出的文字
begin
FLogFont.lfHeight := fh; //字高
FLogFont.lfWidth := fw; //字宽
FLogFont.lfWeight := 1; //字体笔划粗细程度
FLogFont.lfUnderline := 0; //没有下划线
FLogFont.lfStrikeOut := 0; //没有删除线
FLogFont.lfItalic := 0; //斜体效果否
FLogFont.lfCharSet := GB2312_CHARSET; //字符集
FLogfont.lfEscapement := 0; //倾斜度
FLogFont.lfOrientation := 0; //方向与倾斜度取值同
FLogFont.lfFaceName := '宋体'; //字体名称
hTempFont := CreateFontIndirect(FLogFont); //创建逻辑字体
TempString := c;
hTempDC := GetDc(ParentHandle); //取得窗口的设备句柄
hPrevFont := SelectObject(hTempDC, hTempFont); //取出窗口设备的当前字体,并替换为新字体
//SetTextColor(hTempDc, clRed); //设置设备窗口的文字色彩
TextOut(hTempDc, x, y, PChar(TempString), Length(TempString)); //输出文字
SelectObject(hTempDc, hPrevFont); //恢复原有淖痔?br> DeleteObject(hTempFont); //删除逻辑字体
ReleaseDC(Handle, hTempDC); //释放设备接口
end;
var
I : Integer;
s : WideString;
Len : Integer;
p : Integer;
begin
panel1.Width := 100;
panel1.Height := 23;
s := '中国人';
len := length(s);
p := panel1.Width div len;
for i := 1 to len do
begin
if (ByteType(copy(s, i,1),1) = mbSingleByte) then
drawFont(panel1.Handle, (i - 1) * p, 0, p, panel1.Height, copy(s, i, 1))
else
drawFont(panel1.Handle, (i - 1) * p, 0, p div 2, panel1.Height, copy(s, i,
1)); //中文.
end;