获取字符串宽度

SQL code
//====================================================================
// 事件: 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)
//    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
SQL code
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"

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值