Discussion:
How to calculate if it fits
(too old to reply)
Stark
2010-05-13 19:24:16 UTC
Permalink
In a DBGrid I show the memo field of my dBase file using the followin
routine (part):
DrawText(Canvas.Handle, PChar(Column.Field.AsString),
Length(Column.Field.AsString), R,
DT_WORDBREAK OR DT_NOPREFIX);

What I would like is to know if my string fills the space of the DBGrid
column. I it doesn't, may be I can do something about it.
But how do I calculate the space occupied by the string, given that a font
or another can be used, etc.

It must be over complicated, so I tried something and gave up after a while.
Can anyone help?
a***@aol.com
2010-05-13 20:11:47 UTC
Permalink
Post by Stark
In a DBGrid I show the memo field of my dBase file using the followin
� � DrawText(Canvas.Handle, PChar(Column.Field.AsString),
� � � � Length(Column.Field.AsString), R,
� � � � DT_WORDBREAK OR DT_NOPREFIX);
What I would like is to know if my string fills the space of the DBGrid
column. I it doesn't, may be I can do something about it.
But how do I calculate the space occupied by the string, given that a font
or another can be used, etc.
It must be over complicated, so I tried something and gave up after a while.
Can anyone help?
TW := Canvas.TextWidth(Column.Field.AsString)

Alternatively you can use the DT_CALCRECT flag with DrawText and get
the height of the resultant word-broken text. See Win32 Help file.

Note that if you are passing a PChar to DrawText you can pass -1
instead of the length, and DrawText will calculate the length for you.

Alan Lloyd
Stark
2010-05-13 22:27:56 UTC
Permalink
Post by Stark
In a DBGrid I show the memo field of my dBase file using the followin
� � DrawText(Canvas.Handle, PChar(Column.Field.AsString),
� � � � Length(Column.Field.AsString), R,
� � � � DT_WORDBREAK OR DT_NOPREFIX);
What I would like is to know if my string fills the space of the DBGrid
column. I it doesn't, may be I can do something about it.
But how do I calculate the space occupied by the string, given that a font
or another can be used, etc.
It must be over complicated, so I tried something and gave up after a while.
Can anyone help?
TW := Canvas.TextWidth(Column.Field.AsString)

Alternatively you can use the DT_CALCRECT flag with DrawText and get
the height of the resultant word-broken text. See Win32 Help file.

Note that if you are passing a PChar to DrawText you can pass -1
instead of the length, and DrawText will calculate the length for you.

Alan Lloyd

Thanks Allan, in the meantime I tried in 3 different ways, getting 3
different results:
Note: The string int the memo field is simply "A"
1-
L:= DrawText(Canvas.Handle, PChar(Column.Field.AsString),
Length(Column.Field.AsString), R,
DT_CALCRECT OR DT_NOPREFIX);
result L= 13

2-
L:= Length(Column.Field.AsString);
L=1

3-
L:= Canvas.TextWidth(Column.Field.AsString));
L=7

Another string "A word" gives these results: 13 6 33
I think I understand the length given by method 2, which should be the strng
lentgh as number of bytes. But what is the defference with the others ?
BRoberts
2010-05-13 22:23:14 UTC
Permalink
Post by Stark
In a DBGrid I show the memo field of my dBase file using the followin
DrawText(Canvas.Handle, PChar(Column.Field.AsString),
Length(Column.Field.AsString), R,
DT_WORDBREAK OR DT_NOPREFIX);
What I would like is to know if my string fills the space of the DBGrid
column. I it doesn't, may be I can do something about it.
But how do I calculate the space occupied by the string, given that a font
or another can be used, etc.
It must be over complicated, so I tried something and gave up after a
while. Can anyone help?
Take a look at the various flags available to DrawText. There is one that
will, rather than paint the text, return the text width - DT_CalcRect. It is
also that it's possible to instruct DrawText to include ellipsis if the text
exceeds the given rectangle - DT_End_Ellipsis. Check the Win32 SDK help or
at msdn.com.

If different fonts are being used set the appropriate Canvas.Font properties
immediately before calling DrawText. If memory serves I generally do
something like

var svFont : tFont;

. . .
svFont := tFont.Create;
try
svFont.Assign (aCanvas.Font);
aCanvas.Font.Name := drawFontName;
aCanvas.Font.Size := drawFontSize;
aCanvas.Font.Style := drawFontStyle;
// set up draw text parameters and then execute DrawText
finally
aCanvas.Font.Assign (svFont);
svFont.Free;
end;
Stark
2010-05-14 17:44:07 UTC
Permalink
Post by BRoberts
Post by Stark
In a DBGrid I show the memo field of my dBase file using the followin
DrawText(Canvas.Handle, PChar(Column.Field.AsString),
Length(Column.Field.AsString), R,
DT_WORDBREAK OR DT_NOPREFIX);
What I would like is to know if my string fills the space of the DBGrid
column. I it doesn't, may be I can do something about it.
But how do I calculate the space occupied by the string, given that a
font or another can be used, etc.
It must be over complicated, so I tried something and gave up after a
while. Can anyone help?
Take a look at the various flags available to DrawText. There is one that
will, rather than paint the text, return the text width - DT_CalcRect. It
is also that it's possible to instruct DrawText to include ellipsis if the
text exceeds the given rectangle - DT_End_Ellipsis. Check the Win32 SDK
help or at msdn.com.
If different fonts are being used set the appropriate Canvas.Font
properties immediately before calling DrawText. If memory serves I
generally do something like
var svFont : tFont;
. . .
svFont := tFont.Create;
try
svFont.Assign (aCanvas.Font);
aCanvas.Font.Name := drawFontName;
aCanvas.Font.Size := drawFontSize;
aCanvas.Font.Style := drawFontStyle;
// set up draw text parameters and then execute DrawText
finally
aCanvas.Font.Assign (svFont);
svFont.Free;
end;
OK, I used the DrawText function with the DT_CALCRECT flag that retuned a
value. Now I want to know if this value will fit or not the space I have
available in this column of the DBGrid. How do I know the total available
space ?
Stark
2010-05-14 19:07:39 UTC
Permalink
Post by Stark
Post by BRoberts
Post by Stark
In a DBGrid I show the memo field of my dBase file using the followin
DrawText(Canvas.Handle, PChar(Column.Field.AsString),
Length(Column.Field.AsString), R,
DT_WORDBREAK OR DT_NOPREFIX);
What I would like is to know if my string fills the space of the DBGrid
column. I it doesn't, may be I can do something about it.
But how do I calculate the space occupied by the string, given that a
font or another can be used, etc.
It must be over complicated, so I tried something and gave up after a
while. Can anyone help?
Take a look at the various flags available to DrawText. There is one that
will, rather than paint the text, return the text width - DT_CalcRect. It
is also that it's possible to instruct DrawText to include ellipsis if
the text exceeds the given rectangle - DT_End_Ellipsis. Check the Win32
SDK help or at msdn.com.
If different fonts are being used set the appropriate Canvas.Font
properties immediately before calling DrawText. If memory serves I
generally do something like
var svFont : tFont;
. . .
svFont := tFont.Create;
try
svFont.Assign (aCanvas.Font);
aCanvas.Font.Name := drawFontName;
aCanvas.Font.Size := drawFontSize;
aCanvas.Font.Style := drawFontStyle;
// set up draw text parameters and then execute DrawText
finally
aCanvas.Font.Assign (svFont);
svFont.Free;
end;
OK, I used the DrawText function with the DT_CALCRECT flag that retuned a
value. Now I want to know if this value will fit or not the space I have
available in this column of the DBGrid. How do I know the total available
space ?
I tried several tests with DT_CALCRECT modifying the string and I think I
found values that look very strange to me. The string "a word" returns a
value 13 and the string "a word xxxxxxxxx" still gives a value 13. On the
other hand, a shorter strin contained in another memo field returns a bigger
value of 26.
I also tried to use the expression "Canvas.TextWidth(Column.Field.AsString)"
in parallel with the above to compare results and these are totally
different...
I am on the point of giving up understanding...
a***@aol.com
2010-05-14 20:44:31 UTC
Permalink
Post by Stark
Post by Stark
Post by BRoberts
Post by Stark
In a DBGrid I show the memo field of my dBase file using the followin
� �DrawText(Canvas.Handle, PChar(Column.Field.AsString),
� � � �Length(Column.Field.AsString), R,
� � � �DT_WORDBREAK OR DT_NOPREFIX);
What I would like is to know if my string fills the space of the DBGrid
column. I it doesn't, may be I can do something about it.
But how do I calculate the space occupied by the string, given that a
font or another can be used, etc.
It must be over complicated, so I tried something and gave up after a
while. Can anyone help?
Take a look at the various flags available to DrawText. There is one that
will, rather than paint the text, return the text width - DT_CalcRect. It
is also that it's possible to instruct DrawText to include ellipsis if
the text exceeds the given rectangle - DT_End_Ellipsis. Check the Win32
SDK help or at msdn.com.
If different fonts are being used set the appropriate Canvas.Font
properties immediately before calling DrawText. If memory serves I
generally do something like
� �var � �svFont : tFont;
� �. . .
� �svFont := tFont.Create;
� �try
� � � �svFont.Assign (aCanvas.Font);
� � � �aCanvas.Font.Name := drawFontName;
� � � �aCanvas.Font.Size := drawFontSize;
� � � �aCanvas.Font.Style := drawFontStyle;
� � � �// set up draw text parameters and then execute DrawText
� �finally
� � � �aCanvas.Font.Assign (svFont);
� � � �svFont.Free;
� � � �end;
OK, I used the DrawText function with the DT_CALCRECT flag that retuned a
value. Now I want to know if this value will fit or not the space I have
available in this column of the DBGrid. How do I know the total available
space ?
I tried several tests with DT_CALCRECT modifying the string and I think I
found values that look very strange to me. The string "a word" returns a
value 13 and the string "a word xxxxxxxxx" still gives a value 13. On the
other hand, a shorter strin contained in another memo field returns a bigger
value of 26.
I also tried to use the expression "Canvas.TextWidth(Column.Field.AsString)"
in parallel with the above to compare results and these are totally
different...
I am on the point of giving up understanding...- Hide quoted text -
Post a copy of some of your code, particularly the DrawText call, but
also any other associated with your attempt to measure the width or
rect.

Have you looked up DrawText on an MSDN (Mictosoft Development Network)
Library. There are a lot of flags associated with DrawText which may
affect you.

Alan Lloyd
Stark
2010-05-15 13:57:46 UTC
Permalink
Post by Stark
Post by Stark
Post by BRoberts
Post by Stark
In a DBGrid I show the memo field of my dBase file using the followin
� �DrawText(Canvas.Handle, PChar(Column.Field.AsString),
� � � �Length(Column.Field.AsString), R,
� � � �DT_WORDBREAK OR DT_NOPREFIX);
What I would like is to know if my string fills the space of the DBGrid
column. I it doesn't, may be I can do something about it.
But how do I calculate the space occupied by the string, given that a
font or another can be used, etc.
It must be over complicated, so I tried something and gave up after a
while. Can anyone help?
Take a look at the various flags available to DrawText. There is one that
will, rather than paint the text, return the text width - DT_CalcRect. It
is also that it's possible to instruct DrawText to include ellipsis if
the text exceeds the given rectangle - DT_End_Ellipsis. Check the Win32
SDK help or at msdn.com.
If different fonts are being used set the appropriate Canvas.Font
properties immediately before calling DrawText. If memory serves I
generally do something like
� �var � �svFont : tFont;
� �. . .
� �svFont := tFont.Create;
� �try
� � � �svFont.Assign (aCanvas.Font);
� � � �aCanvas.Font.Name := drawFontName;
� � � �aCanvas.Font.Size := drawFontSize;
� � � �aCanvas.Font.Style := drawFontStyle;
� � � �// set up draw text parameters and then execute DrawText
� �finally
� � � �aCanvas.Font.Assign (svFont);
� � � �svFont.Free;
� � � �end;
OK, I used the DrawText function with the DT_CALCRECT flag that retuned a
value. Now I want to know if this value will fit or not the space I have
available in this column of the DBGrid. How do I know the total available
space ?
I tried several tests with DT_CALCRECT modifying the string and I think I
found values that look very strange to me. The string "a word" returns a
value 13 and the string "a word xxxxxxxxx" still gives a value 13. On the
other hand, a shorter strin contained in another memo field returns a bigger
value of 26.
I also tried to use the expression
"Canvas.TextWidth(Column.Field.AsString)"
in parallel with the above to compare results and these are totally
different...
I am on the point of giving up understanding...- Hide quoted text -
Post a copy of some of your code, particularly the DrawText call, but
also any other associated with your attempt to measure the width or
rect.

Have you looked up DrawText on an MSDN (Mictosoft Development Network)
Library. There are a lot of flags associated with DrawText which may
affect you.

Alan Lloyd

The Draw routine is very long, so I am posting the part that deals with the
memo field. Here it is, supplemented with the debug code I have used to
compare sizes:
..........................................................
if ((Column.Field is TMemoField)) then
begin
Canvas.FillRect(Rect);
if Column.Field.AsString <>'' then
begin
R:=Rect;
Canvas.FillRect(R);
Inc(R.Top,2);
Inc(R.Left,2);
H:= DrawText(Canvas.Handle, PChar(Column.Field.AsString),
Length(Column.Field.AsString), R,
DT_CALCRECT);
// Debug code
ListBox1.Items.Add(Column.Field.AsString);
ListBox1.Items.Add('H='+inttostr(H);
ListBox1.Items.Add('L='+inttostr(Length(Column.Field.AsString));
ListBox1.Items.Add('C='+inttostr(Canvas.TextWidth(Column.Field.AsString));

DrawText(Canvas.Handle, PChar(Column.Field.AsString),
Length(Column.Field.AsString), R,
DT_NOCLIP OR DT_WORDBREAK);
end;
end else
// OTHER COLUMNS_ CENTER TEXT IN THE HEIGHT
begin
Txt := Column.Field.Text;
H := Dbgrid1.Canvas.TextHeight(Txt); //senza H e W non è
perfett.centrato
W := Dbgrid1.Canvas.TextWidth(Txt);
X := Rect.Left;
Y := (Rect.Bottom + Rect.Top - H) DIV 2;
//
Canvas.TextRect(Rect, X, Y, Txt );
end;
end;
end; //with Sender as TDBGrid
a***@aol.com
2010-05-15 14:52:16 UTC
Permalink
You did not put DT_WORDBREAK flag in your call with DT_CALCRECT.

Put a TImage, sized to 50 x 50, a button & a TListBox on a form & code
the button . . .

procedure TForm1.BitBtn1Click(Sender: TObject);
var
Rect, R : TRect;
PtTL, PtBR : TPoint;
H, L, C : integer;
Str : String;
begin
// Get Canvas Rect . . .
Rect.TopLeft :=
Image1.ScreenToClient(Form1.ClientToScreen(Image1.BoundsRect.TopLeft));
Rect.BottomRight :=
Image1.ScreenToClient(Form1.ClientToScreen(Image1.BoundsRect.BottomRight));
// . . . & some text fo tests
Str := Edit1.Text;
with Image1 do begin
Canvas.FillRect(Rect);
if Str <>'' then begin
R:=Rect;
Canvas.FillRect(R);
Inc(R.Top,2);
Inc(R.Left,2);
H := DrawText(Canvas.Handle, PChar(Str),
-1, R, // No need to specify length
with a PChar
DT_CALCRECT or DT_WORDBREAK); // < < < < <
// Debug code
ListBox1.Clear;
ListBox1.Items.Add(Str);
ListBox1.Items.Add('H='+inttostr(H));
ListBox1.Items.Add('L='+inttostr(Length(Str)));
ListBox1.Items.Add('C='+inttostr(Canvas.TextWidth(Str)));

DrawText(Canvas.Handle, PChar(Str),
-1, R,
DT_NOCLIP OR DT_WORDBREAK);
end;
end;
end;

You'll get . . .

H=13 L=6 C=33 and H=26, L=16 C = 81

If you look up DrawText you'll see all the flags (including
DT_WORDBREAK & DT_CALCRECT) explained.

Alan Lloyd
Stark
2010-05-15 19:35:11 UTC
Permalink
Post by a***@aol.com
You did not put DT_WORDBREAK flag in your call with DT_CALCRECT.
Put a TImage, sized to 50 x 50, a button & a TListBox on a form & code
the button . . .
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Rect, R : TRect;
PtTL, PtBR : TPoint;
H, L, C : integer;
Str : String;
begin
// Get Canvas Rect . . .
Rect.TopLeft :=
Image1.ScreenToClient(Form1.ClientToScreen(Image1.BoundsRect.TopLeft));
Rect.BottomRight :=
Image1.ScreenToClient(Form1.ClientToScreen(Image1.BoundsRect.BottomRight));
// . . . & some text fo tests
Str := Edit1.Text;
with Image1 do begin
Canvas.FillRect(Rect);
if Str <>'' then begin
R:=Rect;
Canvas.FillRect(R);
Inc(R.Top,2);
Inc(R.Left,2);
H := DrawText(Canvas.Handle, PChar(Str),
-1, R, // No need to specify length
with a PChar
DT_CALCRECT or DT_WORDBREAK); // < < < < <
// Debug code
ListBox1.Clear;
ListBox1.Items.Add(Str);
ListBox1.Items.Add('H='+inttostr(H));
ListBox1.Items.Add('L='+inttostr(Length(Str)));
ListBox1.Items.Add('C='+inttostr(Canvas.TextWidth(Str)));
DrawText(Canvas.Handle, PChar(Str),
-1, R,
DT_NOCLIP OR DT_WORDBREAK);
end;
end;
end;
You'll get . . .
H=13 L=6 C=33 and H=26, L=16 C = 81
If you look up DrawText you'll see all the flags (including
DT_WORDBREAK & DT_CALCRECT) explained.
Alan Lloyd
Thanks for your patience. I made the test you suggested and got the
following results:
Edit1 (this is the string in the edit) H=13 L=5 C=24

You don't say the string you used ( and why you get two set of results)

Anyway, changing the text in the edit (adding a letter at a time several
times and recalculating), I always get 13 as the H value.
And Yes, I looked up to see all of the flags explanation and made several
tests which did not matched with my understanding of the function..
What I need looked simple: I need to know the total space I have available
(which i still don't know how to calculate) and compare with the size my
string need (which I believed was this "H" value).
a***@aol.com
2010-05-15 19:58:23 UTC
Permalink
Post by Stark
Thanks for your patience. I made the test you suggested and got the
Edit1 (this is the string in the edit) H=13 L=5 C=24
You don't say the string you used ( and why you get two set of results)
Anyway, changing the text in the edit (adding a letter at a time several
times and recalculating), I always get 13 as the H value.
And Yes, I looked up to see all of the flags explanation and made several
tests which did not matched with my understanding of the function..
What I need looked simple: I need to know the total space I have available
(which i still don't know how to calculate) and compare with the size my
string need (which I believed was this "H" value).- Hide quoted text -
I entered longer strings & it double-lined. I entered 'a word' for the
first test and it did it on a single line. Then I entered 'a word
xxxxxxxxx' (just as you did) and it double-lined with an H of 26.

Did you make the image 50 wide & 50 high, so that the longer string
double lined.

If you get a different answer to me, you've done something different.
Did you copy to the clipboard from my post & paste into your button
event handler.

You get the column width in a DBGrid with . . .

ColWidth := MyDBGrid.Columns.Items[4].Width;

. . . where 4 is the zero-based index of the column you're interested
in.

If you set dgColumnReSize in the DBGrid's Options you will be able to
resize the column in code(and also you would need to resize the DBGrid
control as well).

Alan Lloyd.
Stark
2010-05-15 22:24:34 UTC
Permalink
Post by a***@aol.com
Post by Stark
Thanks for your patience. I made the test you suggested and got the
Edit1 (this is the string in the edit) H=13 L=5 C=24
You don't say the string you used ( and why you get two set of results)
Anyway, changing the text in the edit (adding a letter at a time several
times and recalculating), I always get 13 as the H value.
And Yes, I looked up to see all of the flags explanation and made several
tests which did not matched with my understanding of the function..
What I need looked simple: I need to know the total space I have available
(which i still don't know how to calculate) and compare with the size my
string need (which I believed was this "H" value).- Hide quoted text -
I entered longer strings & it double-lined. I entered 'a word' for the
first test and it did it on a single line. Then I entered 'a word
xxxxxxxxx' (just as you did) and it double-lined with an H of 26.
Did you make the image 50 wide & 50 high, so that the longer string
double lined.
If you get a different answer to me, you've done something different.
Did you copy to the clipboard from my post & paste into your button
event handler.
You get the column width in a DBGrid with . . .
ColWidth := MyDBGrid.Columns.Items[4].Width;
. . . where 4 is the zero-based index of the column you're interested
in.
If you set dgColumnReSize in the DBGrid's Options you will be able to
resize the column in code(and also you would need to resize the DBGrid
control as well).
Alan Lloyd.
Sorry Allan, but you should add to the above some english problem. What do
you mean when youi says your string "double-lined "?
I copied the code from your message, I made the image 50 wide & 50 high.
But when I clic ont the button the text appears on the image but it does not
wrap (if this is what you mean by double-line..).

Here is the entire code:
unit ProvaAlanU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
Image1: TImage;
ListBox1: TListBox;
Edit1: TEdit;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Rect, R : TRect;
PtTL, PtBR : TPoint;
H, L, C : integer;
Str : String;
begin
// Get Canvas Rect . . .
Rect.TopLeft :=
Image1.ScreenToClient(Form1.ClientToScreen(Image1.BoundsRect.TopLeft));
Rect.BottomRight :=
Image1.ScreenToClient(Form1.ClientToScreen(Image1.BoundsRect.BottomRight));
// . . . & some text fo tests
Str := Edit1.Text;
with Image1 do begin
Canvas.FillRect(Rect);
if Str <>'' then begin
R:=Rect;
Canvas.FillRect(R);
Inc(R.Top,2);
Inc(R.Left,2);
H := DrawText(Canvas.Handle, PChar(Str),
-1, R, // No need to specify length with a PChar
DT_CALCRECT or DT_WORDBREAK); // < < < < <
// Debug code
ListBox1.Clear;
ListBox1.Items.Add(Str);
ListBox1.Items.Add('H='+inttostr(H));
ListBox1.Items.Add('L='+inttostr(Length(Str)));
ListBox1.Items.Add('C='+inttostr(Canvas.TextWidth(Str)));

DrawText(Canvas.Handle, PChar(Str),-1, R, DT_NOCLIP OR DT_WORDBREAK);
end;
end;
end;
end.
a***@aol.com
2010-05-16 13:13:15 UTC
Permalink
I wanted to send you graphics showing my results. As I cannot include
graphics to the newsgroup I have emailed you with them & a couple of
suggestions,

Basically I get the correct results & don't know why you don't <g>.

Alan Lloyd
Jamie
2010-05-16 14:37:39 UTC
Permalink
Post by a***@aol.com
I wanted to send you graphics showing my results. As I cannot include
graphics to the newsgroup I have emailed you with them & a couple of
suggestions,
Basically I get the correct results & don't know why you don't <g>.
Alan Lloyd
Font size differences on the PC?
small font/Large font, different country code?


I think using the base line of DrawText with the wrap and calculate
flags to then using the "PtInRect" API to determine if it's going to
fit works just fine..
BRoberts
2010-05-17 00:45:02 UTC
Permalink
Post by Jamie
Post by a***@aol.com
I wanted to send you graphics showing my results. As I cannot include
graphics to the newsgroup I have emailed you with them & a couple of
suggestions,
Basically I get the correct results & don't know why you don't <g>.
Alan Lloyd
Font size differences on the PC?
small font/Large font, different country code?
I think using the base line of DrawText with the wrap and calculate flags
to then using the "PtInRect" API to determine if it's going to
fit works just fine..
For correct dimension calculations you must set the Canvas.Font property
appropriately immediately before calling DrawText with the dt_CalcRect flag.

You may only calculate one dimension at a time - which, if you think about
it, makes perfect sense. To calculate the width you must include
dt_SingleLine and omit dt_WordBreak. To calculate the height you must
include dt_WordBreak and omit dt_SingleLine. When calculating the height the
lpRect parameter height returns the calculated value.
a***@aol.com
2010-05-17 08:11:36 UTC
Permalink
On 17 May, 01:45, "BRoberts" <***@caneris.ca> wrote:
<snip>
Post by BRoberts
When calculating the height the
lpRect parameter height returns the calculated value.
Not so - lpRect height is the _available_ height. The function
returned value is the _used_ height.

Alan Lloyd
a***@aol.com
2010-05-17 08:56:04 UTC
Permalink
Post by a***@aol.com
<snip>
Post by BRoberts
When calculating the height the
lpRect parameter height returns the calculated value.
Not so - lpRect height is the _available_ height. The function
returned value is the _used_ height.
Ah - we're both right. the height _is_ returned and the post-call
lpRect _is_ the actual rect required within the widrh of the pre-call
rect. The returned rect spaces the text in the pre-call with a 2 pixel
left & top margin (ie post-call rect is 2,2,?,?).

Alan Lloyd
Stark
2010-05-18 08:39:19 UTC
Permalink
Alan, I sent you the graphics of the test I made following your
suggestions.. Non changes.
Post by a***@aol.com
Post by a***@aol.com
<snip>
Post by BRoberts
When calculating the height the
lpRect parameter height returns the calculated value.
Not so - lpRect height is the _available_ height. The function
returned value is the _used_ height.
Ah - we're both right. the height _is_ returned and the post-call
lpRect _is_ the actual rect required within the widrh of the pre-call
rect. The returned rect spaces the text in the pre-call with a 2 pixel
left & top margin (ie post-call rect is 2,2,?,?).
Alan Lloyd
a***@aol.com
2010-05-18 10:40:37 UTC
Permalink
Solved (at last) DrawText with DT_WORDBREAK does just what it says, it
breaks _words_ onto the next line. If there are no spaces in the text
then it does _not_ split the word at the rect boundary, it just clips
it.

I really must read MS documents with an evil cynical mindset <g>

Alan Lloyd

Jamie
2010-05-14 00:31:29 UTC
Permalink
Post by Stark
In a DBGrid I show the memo field of my dBase file using the followin
DrawText(Canvas.Handle, PChar(Column.Field.AsString),
Length(Column.Field.AsString), R,
DT_WORDBREAK OR DT_NOPREFIX);
What I would like is to know if my string fills the space of the DBGrid
column. I it doesn't, may be I can do something about it.
But how do I calculate the space occupied by the string, given that a
font or another can be used, etc.
It must be over complicated, so I tried something and gave up after a
while. Can anyone help?
Use the DrawText function with the DT_CALCRECT flag only at first, this
will return a required RECT size..
Use the "PtInRect" API call with the REct.Width and REct.Height as the
Tpoint parameter to determine if it will first in your destination size.
Loading...