1. Centering Text in Win32
All,
I need a little help with a procedure to Center Text on
a line in a Window, I am using win32lib and the Window is Re-sizeable.
TIA,
Later,
+ + + Rev. Ferlin Scarborough - Centreville, Alabama - USA
2. Re: Centering Text in Win32
Rev. Ferlin Scarborough asked:
> I need a little help with a procedure to
> Center Text on a line in a Window, I am
> using win32lib and the Window is Re-sizeable.
I've included the code. Note that if you are not calling repaintRect(), the
(x2,y2) parameter of onPaint will be equal to the size of the window. The
getFontSize() routine returns the *average* size of a character in the
current font.
Hope this helps!
-- David Cuny
-- Begin Code: Center Text Demo --
include win32lib.ew
constant Win =
create( Window, "Centered Text Demo", 0, Default, Default, 200, 100, 0 )
-- setFont( Win, "Courier New", 12, 0 )
procedure Paint( integer x1, integer y1, integer x2, integer y2 )
integer textWide, winWide, atX
sequence fontSize, winSize, text
-- set text
text = "Hello, World!"
-- get size of font
fontSize = getFontSize( Win )
-- text width
textWide = fontSize[1] * length( text )
-- get size of window
winSize = getWindowExtent( Win )
winWide = winSize[1]
-- calculate start of text
atX = floor( (winWide/2) - (textWide/2) )
-- display, if there is room
if atX > 0 then
setPosition( Win, atX, 0 )
wPuts( Win, "Hello, World!" )
end if
end procedure
-- tell Windows when to do the action
onPaint[Win] = routine_id( "Paint" )
-- hand control over to Windows
WinMain( Win )
-- End Code: Center Text Demo --
3. Centering Text in Win32
- Posted by Ad Rienks <Ad_Rienks at COMPUSERVE.COM>
Nov 05, 1998
-
Last edited Nov 06, 1998
-- resize demo
include Win32Lib.ew
constant
Main =3D create(Window, "Resize demo", 0, Default, Default, 640 , 480=
, 0)
global procedure onResize_Main(integer clientX, integer clientY)
integer len, fontwidth
sequence sizes, text
fontwidth =3D 12
setFont(Main, "Courier New", fontwidth, Bold)
sizes =3D getWindowSize(Main)
len =3D sizes[3] - sizes[1] -- rigth - left
text =3D "Window width =3D " & sprintf("%d", len)
len =3D floor((sizes[3] - sizes[1] - fontwidth*length(text))/2)
setPosition(Main, len, 10)
wPuts(Main, text)
end procedure
onResize[Main] =3D routine_id("onResize_Main")
WinMain(Main) =
--------------------
original message:
All,
I need a little help with a procedure to Center Text on
a line in a Window, I am using win32lib and the Window is Re-sizeable.
TIA,
Later,
+ + + Rev. Ferlin Scarborough - Centreville, Alabama - USA