I'm in the middle of writing a GUI and I am trying to decide on the best approach for text. I need to be able to access the bits of the pixel directly and proform my own type of bitblt.

My first thought is to create a Dc with a DibSection and draw the text into that. My problem there is that I would need to be able to calculate the dimensions of the text so that the buffer Dc could be dynamically created to match. There is a flag in the DrawText function called DT_CALCRECT which the win32 hlp says Determines the width and height of the rectangle. If there are multiple lines of text, DrawTextEx uses the width of the rectangle pointed to by the lprc parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawTextEx modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawTextEx returns the height of the formatted text, but does not draw the text. That should work as I would already know the width (I tell it that before hand) and it will give me the new height. In fact if I'm reading it correctly I think it says it will modify the rect structre I provide it therefore doing everything for me.

Of course does any one know of an even better solution as even if the above one works it could mean alot of temporary Dcs and Bitmaps if one is needed for every bit of text?
Posted on 2001-08-23 16:31:11 by Eóin
Just an update to the thread, the first method I suggested might work does work as DT_CALCRECT does make the necessary changes to the rect I provide it so I can create a Dc and DibSection the the proper size.

Something tells me that I'm not going to find an easier method but I still open to ideas at this early stage.
Posted on 2001-08-23 17:53:42 by Eóin
I use GetTextExtentPoint32(). Returns the bounds in a pointer SIZE (declared as SIZEL in MASM32 windows.inc) structure.
Posted on 2001-08-27 21:29:34 by comrade
just an idea:

if you output the result of the text operation in your gui screen,
you possibly will never need a temporary buffer larger than
your screen, so you could hold one buffer in the size of the
gui window for all subsequent text operations.

of course, this will take more memory, and you need to resize it
during WM_SIZE of the main window.
Posted on 2001-08-28 14:49:37 by beaster
Thanks.

comrade: I don't think GetTextExtentPoint32 works for multiline text, which I need. DrawText with CALCRECT works at the moment.

beaster: That was an early idea but it would have ment that I couldn't handle more than one piece of text at a time.

The main problem I have now is that I need to work out the end of the text. This is simple in single line text but in multiline text the last character could be anywhere along the last line. I might end up having to handle each line seperatly. Which ain't too bad except it would make selecting text very awkard.
Posted on 2001-08-28 16:03:40 by Eóin