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

Hi Martin,
On Sunday, 18 May 1997 at 09:58:54, Martin Maat confused me
talking about: Owner draw listboxes to Simon Huggins
 MM>> Stop this immediately and check out the DrawTextEx
 MM>> API
 SH>> I'm using Delphi 1 (for compatibility reasons) at the
 SH>> moment but I found there's one called DrawText in the 3.1
 SH>> API.
 SH>> I still can't get this to work though. The height it
 SH>> returns is 0 :(
 MM> I'm not sure if it makes any difference in this case,
 MM> but you should use Control.Canvas.Handle instead of
 MM> hwnd(control). The canvas' handle is not the same as the
 MM> control's handle.
It did make a difference ;)
 MM> You're not changing Rect in DrawItem, so that should be
 MM> the Rect you want. In MeasureItem, rect's height is
 MM> irrelevant. Rect's width is important though, since height
 MM> is calculated wrapping text around. You initialise your rect
 MM> like this:
 MM> with (control as Tlistbox).canvas do
 MM> r:=rect(left,0,left+width,height);
 MM> which could be a lot shorter:
 MM>  r := Control.ClientRect;
 MM> but should be OK either way.
Well the second one's neater and it works at last. Here's the code:
temp:=(control as Tlistbox).items[index]+#0; {NB extra #0 char on end}
drawtext( (control as Tlistbox).canvas.handle, @temp, -1, Rect, 
T_WORDBREAK);
{NB -1 as length that way it can judge ;) }
in drawitem and...
temp:=(control as Tlistbox).items[index]+#0; {NB extra #0 char on end}
with (control as Tlistbox).canvas do
        r:=control.clientrect;
drawtext( (control as Tlistbox).canvas.handle,
          @temp,
          -1,        {NB -1 as length that way it can judge ;) }
          r,
          DT_WORDBREAK+DT_CALCRECT);
in measureitem
Consider yourself well and truely credited in my about box ;)
Cheers,
bfn,
si.
Fido : 2:440/7.15   or   Internet : huggie@dial.pipex.com
Web  : http://dialspace.dial.pipex.com/huggie
.!. The sooner you fall behind, the longer you have to catch up
--- 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™.