Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DrawText/DrawTextEX DT_CALCRECT not working

891 views
Skip to first unread message

eshipman

unread,
Oct 8, 2004, 11:20:39 AM10/8/04
to

iFormat := DT_CALCRECT or DT_EDITCONTROL or
DT_WORDBREAK or DT_NOPREFIX;
DrawTextEx(Form1.Canvas.Handle, PChar(S), Length(S), LRect,
iFormat,
nil );

DrawText(Form1.Canvas.Handle, PChar(s), Length(s), LRect, iFormat);

Neither one of these modify LRect...

What gives? It looks like I'm doing it right...

Scott Price

unread,
Oct 8, 2004, 11:38:23 AM10/8/04
to
eshipman wrote:

myRect := Result := Rect(0, 0, 0, 0);

// Then either of the following should work
DrawText(Self.Canvas.Handle, PChar(S), -1, myRect, iFormat);

DrawText(Self.Canvas.Handle, PChar(S), Length(S), myRect, iFormat);

Give that a try :)

Some of the Win32 and .net routines check if the rect already has
dimensions, as it will not increase already set parameters. Instead,
for example, if it was a fixed width Rect, it would try to increase the
height to contain the text and maintain the width passed.

Hope that helps.


Scott :)

eshipman

unread,
Oct 8, 2004, 11:51:35 AM10/8/04
to
<SNIP>

>
> myRect := Result := Rect(0, 0, 0, 0);
>

<SNIP>


Thanks, that worked.

Michael Winter

unread,
Oct 8, 2004, 11:36:19 AM10/8/04
to
eshipman wrote:

> iFormat := DT_CALCRECT or DT_EDITCONTROL or
> DT_WORDBREAK or DT_NOPREFIX;
> DrawTextEx(Form1.Canvas.Handle, PChar(S), Length(S), LRect,
> iFormat,
> nil );
>
> DrawText(Form1.Canvas.Handle, PChar(s), Length(s), LRect, iFormat);
>
> Neither one of these modify LRect...

You need to set Left and Top of the Rect to 0 and Right to the width of
the text box you intend to draw to. DrawText will the put the needed
height into Bottom.

BTW, what's the result of DrawText and, in case it's 0, what's the
returns GetLastError?

-Michael

Scott Price

unread,
Oct 8, 2004, 12:40:18 PM10/8/04
to
eshipman wrote:

You're very welcome :)

Also, try that with fixed left, and top parameters, and watch the other
two change to fit the text you pass. Then just play with the initially
set parameters, it will become pretty clear after a few funnily drawn
rects :D

Have a good weekend.


Scott :)

0 new messages