1. program
Can anyone please find my error in this program?
--to calculate how many characters an EditText field may contain before
--scrolling
without warning
include win32lib.ew
constant
TextWin=create(Window,"Calculate Field Limit",0,0,0,400,100,0),
DataWin=create(EditText,"",TextWin,0,32,100,28,0)
integer w,maxX,character,ok
sequence s
procedure PaintWin(integer x1,integer y1,integer x2,integer y2)
-- get font size
s = getTextExtent( DataWin, "M" )
w = s[1]
-- get field size
s = getSize( DataWin )
maxX = s[3] - s[1]
character=floor(maxX/w)
setPosition(TextWin,0,0)
wPuts(TextWin,"This field can hold an average of " &
sprintf("%d",character) & " characters before
scrolling")
end procedure
onPaint[TextWin]=routine_id("PaintWin")
procedure onOpenWin()
setFont(TextWin,"Ariel",10,Bold)
setFont(DataWin,"Courier New",10,Bold)
end procedure
onOpen[TextWin]=routine_id("onOpenWin")
WinMain(TextWin,Normal)
thanks all,
Judith
2. Re: program
I noticed that on posting the wPuts line got split. In my program there is
no break in the text.
Also the field can hold 12 characters but the calculation gives 8!
Judith
3. Re: program
Judith wondered:
>Can anyone please find my error in this program?
The problem is with Win32Lib. Apparently, getTextExtent works with windows,
but not with controls. So changing the code to:
setFont( TextWin, "Courier New", 10, Bold )
s = getTextExtent( TextWin, "M" )
setFont( TextWin, "Arial", 10, Bold )
will give you the result (12) that you are after. Note the spelling of
"Arial" needs to be corrected as well.
I suspect that the reason the function doesn't work is because the control
doesn't have a DC (device context) of it's own, so it merely borrows that of
the parent. In this case, it's the main window, and Win32 grabs the font
attributes set in the window. I'll have to do some trickery so that Win32Lib
automagically redirects font requests to a real window. Grumble...
Thanks!
-- David Cuny
4. Re: program
David, thanks for the help! I knew it had to be something simple. This
program is not a big deal but something that I can put into my programs in
order to obtain a value for sendMessage(edittextfield,EM_LIMITTEXT,nn,1) as
I do not want to loose my free statement count by modifying win32lib.
Judith