首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > PB >

获取字符串宽度,该怎么处理

2013-01-07 
获取字符串宽度获取字符串宽度,而不是用len()获取字符个数,请知道的朋友教一下,不论用什么方法,只要能实现

获取字符串宽度
获取字符串宽度,而不是用len()获取字符个数,请知道的朋友教一下,不论用什么方法,只要能实现就可以了。
[解决办法]

//====================================================================
// 事件: of_getsize()
//--------------------------------
// 描述:
//--------------------------------
// 参数:
// value    window    aw       窗口
// value    datawindowadw      数据窗口
// value    long      al_row   行
// value    string    as_col   列名
// referenceinteger   ai_width 宽
// referenceinteger   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

Integerli_Len, li_Return, li_WM_GETFONT = 49 //  hex 0x0031
ULonglul_Hdc, lul_Handle, lul_hFont
StaticTextlst_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)


//TextOut(lul_hdc, ls_text)

ReleaseDC(lul_Handle, lul_Hdc)

//lst_temp.width = ai_width
lst_temp.height = ai_height
lst_temp.Text = ls_text
lst_temp.Show()
//li_Return = aw.CloseUserObject(lst_temp)
END IF

RETURN li_Return



API
Function ulong GetDC(ulong hWnd) Library "USER32.DLL"
Function long ReleaseDC(ulong hWnd, ulong hdcr) Library "USER32.DLL"
Function boolean GetTextExtentPoint32A(ulong hdcr, string lpString, long nCount, ref size size) Library "GDI32.DLL" alias for "GetTextExtentPoint32A;Ansi"
Function ulong SelectObject(ulong hdc, ulong hWnd) Library "GDI32.DLL"

热点排行