Yo, All.
This is more like a Windows problem then a pure Delphi problem, yet
interesting enough to share I think.
I'd like some pro opinions, tricks, views, whatever, regarding a problem that
I am trying to tackle in an intelligaent way.
Here's what I need to do. I have this series of text chunks I want to
display. Each individual chunk should be displayed in a color of its own and
all chunks together, when read from the first one to the last, make up one
logic statement which should wrap around in a predefined rectangle, much like
a left aligned paragraph in a word processor.
Example:
Chunk 1: "Trying to make a computer " Color: Red
Chunk 2: "write meaningless text " Color: Green
Chunk 3: "to a control canvas " Color: Blue
Chunk 4: "in a controled fashion " Color: Gray
Chunk 5: "can be a frustrating experience." Color: Green
Normally, this would be easy using DrawTextEx which does the job splendidly
for any atomic piece of text. My text is not atomic though, I need to set the
font color for each chunk before it is written and DrawTextEx does not start
writing anywhere else but in the upper left corner of the specified rectangle
(plus an optional left margin which would apply to all the lines following
the first one too). I tried to set text alignment to TA_UPDATECP but found
out this was never meant to be done, it made DrawTextEx ignore the
DT_WORDBREAK option.
All I want is being able to tell DrawTextEx where to start writing and it
would suit my needs perfectly.
I _could_ do the wrapping logic myself (measuring every word with TextWidth
before I write it and setting CurrentPoition to the beginning of the next
line with MoveToEx if needed) but I would feel stupid doing so since I still
feel there must be a better, more powerfull way.
Another unsatisfying way I tried was to use DrawTextEx with a rectangle just
high enough to display one line in, and use the extra options record which
returns the number of characters that actually appeared to fit in the
rectangle. Then lower the rectangle one line and do the same with the rest of
the text until there's no text left. Ugly again and for some reason it only
seemed to work when the rectangle's height was no more than TextHeight - 1,
clipping the lower pixels of g's.
If you're a true Windows API gopher who can show me the way, please help.
Groeten, Martin.
--- FMail/386 1.02
---------------
* Origin: -=[ E-mail: m_maat@knoware.nl .......... ]=- (2:286/420.1)
|