TIP: Click on subject to list as thread! ANSI
echo: delphi
to: MARTIN MAAT
from: SIMON HUGGINS
date: 1997-05-14 20:58:00
subject: Owner draw listboxes

Hi Martin,
On Saturday, 10 May 1997 at 10:19:20, Martin Maat confused me
talking about: Owner draw listboxes to Simon Huggins
 MM>> What is your problem exactly?
 SH>> Well, I've got long lines of text and I'm trying to
 SH>> find a way of displaying them in a listbox. I have worked
 SH>> and see if the temporary line plus this new word
 SH>> exceeds the boundary. Repeat until it does then do this a
 SH>> second time.
 MM> Stop this immediately and check out the DrawTextEx API
I'm using Delphi 1 (for compatibility reasons) at the moment but I found
there's one called DrawText in the 3.1 API.
 MM> function! :-) Notice the DT_WORDBREAK option. It returns the
 MM> height needed in pixels. Call this function once in
 MM> MeasureItem with DT_CALCRECT and assign the result to
 MM> Height. Then in DrawItem, use it to display your text.
I still can't get this to work though. The height it returns is 0 :(
Here's the code I'm using:
procedure Tdiaryfrm.left_listMeasureItem (Control: TWinControl;
  Index: Integer; var Height: Integer);
var
   temp:string;
   t:pchar;
   r:Trect;
begin
temp:=(control as Tlistbox).items[index];
t:=stralloc(length(temp)+2);
strpcopy(t,temp);
with (control as Tlistbox).canvas do
        r:=rect(left,0,left+width,height);
Height:=drawtext( hwnd(control), t, -1, r , DT_WORDBREAK+DT_CALCRECT);
strdispose(t);
end;
AND
procedure Tdiaryfrm.left_listDrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
     temp: string;
     t:pchar;
begin
temp:=(control as Tlistbox).items[index];
t:=stralloc(length(temp)+2);
strpcopy(t,temp);
drawtext( hwnd(control), t, length(temp), Rect, DT_WORDBREAK);
strdispose(t);
end;
Could it be that my rectangle is completely wrong?
I don't know how to find the rectangle in the MeasureItem bit.
Thanks for your help so far.
bfn,
si.
Fido : 2:440/7.15   or   Internet : huggie@dial.pipex.com
Web  : http://dialspace.dial.pipex.com/huggie
.!. Famous Last Words: "But I thought YOU did the backups..."
--- Terminate 4.00/Pro
---------------
* Origin: Fou, con et anglais! (2:440/7.15)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.