IonicWind Software

Creative Basic => General Questions => Topic started by: GWS on January 24, 2012, 09:42:42 AM

Title: Printing Text in the centre of a window.
Post by: GWS on January 24, 2012, 09:42:42 AM
Hi,

This may not be particularly useful ... I've developed it from an old post by Paul - so always worth a looksee .. ;D

It show two ways to centre text on the screen - one using an API call - the other easier way using CB's own commands.

Two ways to skin a cat as it were ..  ;D ;D


' Two ways to Print text in the centre of a Window.
' GWS - 2012

TYPE SIZE
    DEF xSize:INT
    DEF ySize:INT
ENDTYPE

DECLARE "gdi32",GetTextExtentPoint32A(hdc:INT,text:STRING,textLen:INT,width: SIZE),int

DEF nSize:SIZE
DEF hDC:int
DEF a$:string
DEF varW,varH:int

def win:window
def error:int

WINDOW(win,0,0,400,300,0xa0000,0,"Centre Window Text",mainwindow)
setwindowcolor win,0xaa5500
frontpen win,0xffeeee
hDC = GetHDC win

setfont win,"Arial",20,700
a$ = "Test Text"

' First method ..
GetTextExtentPoint32A(hDC, a$, len(a$), nSize)
ReleaseHDC win,hDC

move win,(400-nSize.xSize)/2,80
PRINT win, a$


' Second method .. (much easier using CB native statements I think) ..
a$ = "is at the Centre"
gettextsize win,a$,varW,varH
move win,(400-varW)/2,150
PRINT win, a$

run = 1
waituntil run = 0
closewindow win
end

mainwindow:
select @class
case @IDCLOSEWINDOW
run = 0
endselect
return



best wishes, :)

Graham