Login
`
Templates, Tools and Utilities
|
||
Icetips Article
Back to article list
Search Articles
Add Comment
Printer friendly
Direct link
Par2: Centered multi-line auto-sizing message window 1998-08-01 -- Frank Piscopo No pun intended - there's no OOP here. What you get is a centered multi-line
auto-sizing window in its own thread with ONE call, letting you go on with your work
in the background. Call it as many times as you want with different text; as soon as
you're ready to let the user know what mischief you've be up to, call it again with a
blank string to close it. That simple!
Usage examples:
Inform('Doing something...<10>Please wait') ! a 2-liner
Inform('Doing something else...<10>Boring, I know, but<10>Please wait') ! a 3-liner
Inform('') ! closes the message window
Inform PROCEDURE(M)
MsgText CSTRING(1001),STATIC
MsgThread LONG,STATIC
State BYTE,STATIC
Window WINDOW,AT(,,50,50),FONT('MS Sans Serif',10,,),CENTER,GRAY,DOUBLE
END
CODE
CASE State
OF 0
IF M
State = 1
MsgText = M
MsgThread = START(Inform,,'')
ACCEPT
IF EVENT() = EVENT:Suspend THEN BREAK.
END
END
OF 1
State = 2
OPEN(Window)
DO FormatText
ACCEPT
IF EVENT() = EVENT:User
DO FormatText
END
END
CLEAR(MsgThread)
State = 0
OF 2
IF M
MsgText = M
POST(EVENT:User,,MsgThread)
ELSE
POST(EVENT:CloseWindow,,MsgThread)
END
END
FormatText ROUTINE
DATA
c LONG
p1 LONG(1)
p2 LONG,AUTO
w1 LONG,AUTO
w2 LONG
CODE
DESTROY(1,LASTFIELD())
LOOP
p2 = INSTRING('<10>',MsgText,,p1)
IF p2
c = CREATE(c+1,CREATE:String)
c{PROP:Text} = MsgText[p1 : p2-1]
w1 = c{PROP:Width}
IF w1 > w2 THEN w2 = w1.
ELSIF LEN(MsgText) => p1
c = CREATE(c+1,CREATE:String)
c{PROP:Text} = MsgText[p1 : LEN(MsgText)]
w1 = c{PROP:Width}
IF w1 > w2 THEN w2 = w1.
END
p1 = p2 + 1
WHILE p2
Window{PROP:Width} = w2 + 6
Window{PROP:Height} = c{PROP:Height} * c + 4
Window{PROP:Center} = 1
LOOP c = 1 TO LASTFIELD()
SETPOSITION(c,2,2+(c-1)*c{PROP:Height},w2)
c{PROP:Center} = 1
c{PROP:Hide} = 0
END
I'll try to post a write-up of the principles involved later. Right now, have to dash.
Hope you like it.
Today is November 21, 2024, 8:24 am This article has been viewed 35194 times.
|
|