给定某些字体,在PowerBuilder中截断列

时间:2011-08-05 07:55:25

标签: powerbuilder datawindow

我有一个专栏varchar(5000)。在PowerBuilder数据窗口中。当字体大小为12时,当字符串的长度高于4600时,此列的显示将被截断。

但是当字体大小为8时,它会显示该列的所有值/内容。

我想澄清我的想法是PB限制。

1 个答案:

答案 0 :(得分:0)

您可以检查未正确显示的字符串是否具有超过显着值的显示大小。我怀疑如果字符串超过32768/65536单位宽度,当PB“绘制”列值时可能会被截断...

以下是一些以像素和单位进行测试的代码,使用与DW中的字体名称和大小相同的字体名称和大小来调用它:

public function long of_getstringwidth (window aw_parent, string as_text, string as_fontname, integer ai_size, boolean ab_bold, boolean ab_italic);// computes the width in pixels of a string as drawn in the specified font

ulong ll_handle, ll_hdc, ll_hdcbis
ulong ll_hfont
ulong weight
long height
long width = -1
st_size size

ll_handle = handle(aw_parent)
ll_hdc = GetDC(ll_handle)

// create the specified font
if ab_bold then weight = FW_BOLD else weight = FW_NORMAL
// compute the height using the display device physical properties
height = -MulDiv(ai_size, GetDeviceCaps(ll_hdc, LOGPIXELSX), 72)
ll_hfont = CreateFont( height, 0, 0, 0, weight, ab_italic, false, false, 0, DEFAULT_CHARSET, 0, 0, 0, as_fontname)
// use that font for the device context
SelectObject(ll_hdc, ll_hfont)

if GetTextExtentPoint32(ll_hdc, as_text, len(as_text), size) then
    width = size.cx + 1 //add 1 is better, look trhough MSDN for clues ;o)
end if

ReleaseDC(ll_handle, ll_hdc)

return width

end function

public function long of_getstringwidthunits (window aw_parent, string as_text, string as_fontname, integer ai_size, boolean ab_bold, boolean ab_italic);// computes the size in pixels of a string as drawn in the specified font
// returns a result in PB units

long width = -1

width = of_getstringwidth(aw_parent, as_text, as_fontname, ai_size, ab_bold, ab_italic)
width = PixelsToUnits(width, XPixelsToUnits!) 

return width

end function

以下是所需的外部函数和声明(我希望我没有错过一个,但可以在平台SDK / MSDN中检索这些值):

Function ULong GetDC(ULong hWnd) Library "User32.DLL"
Function ULong ReleaseDC(ULong hWnd, ULong hDC) Library "User32.DLL"
function long MulDiv(long nNumber, long nNumerator, int nDenominator) library "kernel32.dll"
Function ulong CreateFont(long nHeight,ulong nWidth,ulong nEscapement,ulong nOrientation,ulong fnWeight,boolean fdwItalic,boolean fdwUnderline,boolean fdwStrikeOut,ulong fdwCharSet,ulong fdwOutputPrecision,ulong fdwClipPrecision,ulong fdwQuality,ulong dwPitchAndFamily,ref string lpszFace) LIBRARY "gdi32.dll" ALIAS FOR "CreateFontW"  
Function Ulong SelectObject (Ulong hDC, Ulong hObject) Library "gdi32.dll"
Function Boolean GetTextExtentpoint32(ULong hdc, string lpString, int cbString, ref ST_SIZE lpSize) library "gdi32.dll" alias for "GetTextExtentPoint32W"
Function ulong GetDeviceCaps(ulong hdc,ulong nIndex) library "gdi32.dll"
constant integer FW_NORMAL     = 400
constant integer FW_BOLD       = 700
constant ulong LOGPIXELSX = 88  //Number of pixels per logical inch along the screen width.
constant ulong DEFAULT_CHARSET     = 1   //(x01)

该代码是一个userobject的一部分,我放了许多GDI函数。如果有人有兴趣,我可以分享它的代码。