获取字符串宽度,而不是用len()获取字符个数,请知道的朋友教一下,不论用什么方法,只要能实现就可以了。
------解决方案--------------------
//====================================================================
// 事件: of_getsize()
//--------------------------------
// 描述:
//--------------------------------
// 参数:
// value window aw 窗口
// value datawindow adw 数据窗口
// value long al_row 行
// value string as_col 列名
// reference integer ai_width 宽
// reference integer ai_height 高
//--------------------------------
// 返回: integer
//--------------------------------
// 修改历史:
//
//====================================================================
Int li_height, li_width
String ls_text, ls_fontface, ls_fontsize, ls_weight, ls_italic, ls_underline
Boolean lb_italic, lb_underline
ls_text = adw.GetItemString(al_row, as_col)
IF IsNull(ls_text) Or Len(ls_text) = 0 THEN RETURN -1
ls_fontface = adw.Describe(as_col + '.font.face')
ls_fontsize = adw.Describe(as_col + '.font.height')
ls_weight = adw.Describe(as_col + '.font.weight')
ls_italic = adw.Describe(as_col + '.font.italic')
ls_underline = adw.Describe(as_col + '.font.underline')
IF ls_italic = '1' THEN
lb_italic = True
ELSE
lb_italic = False
END IF
IF ls_underline = '1' THEN
lb_underline = True
ELSE
lb_underline = False
END IF
Integer li_Len, li_Return, li_WM_GETFONT = 49 // hex 0x0031
ULong lul_Hdc, lul_Handle, lul_hFont
StaticText lst_temp
size lstr_Size
IF IsNull(aw) Or Not IsValid (aw) THEN RETURN -1
li_Return = aw.OpenUserObject(lst_temp)
IF li_Return = 1 THEN
lst_temp.FaceName = ls_fontface
lst_temp.TextSize = Integer(ls_fontsize)
lst_temp.Weight = Integer(ls_weight)
lst_temp.Italic = lb_italic
lst_temp.Underline = lb_underline
lst_temp.width = 700
li_Len = Lena(ls_text)
lul_Handle = Handle(lst_temp)
lul_Hdc = GetDC(lul_Handle)
lul_hFont = Send(lul_Handle, li_WM_GETFONT, 0, 0)
SelectObject(lul_Hdc, lul_hFont)
IF Not GetTextExtentpoint32A(lul_Hdc, ls_text, li_Len, lstr_Size ) THEN
aw.CloseUserObject(lst_temp)
RETURN -1
END IF
ai_Width = PixelsToUnits ( lstr_Size.l_cx, XPixelsToUnits! )
ai_Height = PixelsToUnits ( lstr_Size.l_cy, YPixelsToUnits! )
// long ll_sp
// ll_sp = long(UnitsToPixels ( (700 - ai_width)/(li_len - 1), XUnitsToPixels!))
// SetTextCharacterExtra(lul_hdc, ll_sp)