Discussion:
DrawText with DT_CALCRECT problem (drawgrid, multiline)
(too old to reply)
Paul
2003-07-30 12:46:29 UTC
Permalink
Tested: DrawText, DrawTextEx

When I call DrawText with DT_CALCRECT and then normal DrawText to
output some text, there is a problem with allignment. No matter if I
set alligment to the RIGHT, it is always drawn in the TOP LEFT corner
of a cell.
What's the problem?
Yes and, when I simply delete the line with W:= DrawTextEx... on which
I can obtain the height of the cell... then everything's perfect (but
the Multiline mode does not work, obviously)

Take a look:

Flag:= DT_NOPREFIX or DT_MODIFYSTRING or DT_END_ELLIPSIS;
if saiRightAlign in sas then Flag := Flag or DT_RIGHT else
Flag := Flag or DT_LEFT;

if FMultiLineCells and not Fixed then
begin
Flag := Flag or DT_WORDBREAK or DT_WORD_ELLIPSIS or DT_TOP;
W := DrawTextEx(Canvas.Handle,PChar(S),-1,Rect, Flag or DT_CALCRECT,
nil);
Inc(W, 4);
if (RowHeights[ARow] < W) then
RowHeights[ARow]:= W;
end else
begin
Flag := Flag or DT_SINGLELINE or DT_VCENTER;
Rect:= dRect(Rect, 2,0,-2,0);
end;

DrawTextEx(Canvas.Handle,PChar(S),-1,Rect, Flag, nil);
Bruce Roberts
2003-07-30 15:45:14 UTC
Permalink
Post by Paul
Tested: DrawText, DrawTextEx
When I call DrawText with DT_CALCRECT and then normal DrawText to
output some text, there is a problem with allignment. No matter if I
set alligment to the RIGHT, it is always drawn in the TOP LEFT corner
of a cell.
What's the problem?
If you are working with a single line of text this is the behavior I would
expect. dt_CalcRect, in this situation, will adjust the right boundary of
the rect structure.
Rob Kennedy
2003-07-30 17:41:06 UTC
Permalink
Post by Paul
When I call DrawText with DT_CALCRECT and then normal DrawText to
output some text, there is a problem with allignment. No matter if I
set alligment to the RIGHT, it is always drawn in the TOP LEFT corner
of a cell.
What's the problem?
With dt_CalcRect, the left and bottom coordinates will not be modified.
Only the *size* of the rectangle is calculated, and it's documented that
way. It's your responsibility to reposition the resized rectangle afterward.

OffsetRect(Rect, OldRectRight - Rect.Right, 0);
--
Rob
AlanGLLoyd
2003-07-31 19:08:43 UTC
Permalink
Post by Paul
Flag:= DT_NOPREFIX or DT_MODIFYSTRING or DT_END_ELLIPSIS;
if saiRightAlign in sas then Flag := Flag or DT_RIGHT else
Flag := Flag or DT_LEFT;
if FMultiLineCells and not Fixed then
begin
Flag := Flag or DT_WORDBREAK or DT_WORD_ELLIPSIS or DT_TOP;
W := DrawTextEx(Canvas.Handle,PChar(S),-1,Rect, Flag or DT_CALCRECT,
nil);
To my mind you appear to be trying to confuse DrawTextEx <g>. Firstly with
DT_MODIFYSTRING or DT_END_ELLIPSIS you say "truncate this string to fit the
rectangle I specify". Then with DT_CALCRECT you say "calculate the rect I need
for this text".

I have not seen anywhere any documentation of what DrawTextEx does if you
specify both instructions as you have. Or whether whatever happens is
repeatable.

Alan Lloyd
***@aol.com

Loading...