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

ListView Column Header

31 views
Skip to first unread message

Rob Panosh

unread,
Oct 21, 2002, 3:29:16 PM10/21/02
to
I posted the question listed below the other day and got one reply.... get
bBrowser ... thanks Geoff! That that is not an alternative for me right
now. I know this can be accomplished by subclassing the Header control (
which I can do ) and perform a custom draw of the Header control
using window API Drawtext() (which I am struggling with). So could
somebody please give me a code sample to get me started.

Question posted the other day:
-------------------------------
Does anybody have an example on how to put multiple lines in the header of a
ListViewColumn?

Thanks,
Rob Panosh

Paul Piko

unread,
Oct 21, 2002, 5:25:00 PM10/21/02
to
Rob,

> I posted the question listed below the other day and got one
reply.... get
> bBrowser ... thanks Geoff! That that is not an alternative for me
right
> now. I know this can be accomplished by subclassing the Header
control (
> which I can do ) and perform a custom draw of the Header control
> using window API Drawtext() (which I am struggling with). So could
> somebody please give me a code sample to get me started.

Does this help?

http://www.codeguru.com/listview/HeaderCtrlEx.shtml

There are also a few other header control examples on CodeGuru.

--
Paul
----
Paul Piko
Piko Computing Consultants
Phone: +61 3 9432 1222 Fax: +61 3 9432 1255
Email: pa...@piko.com.au Web: http://www.piko.com.au

Rob Panosh

unread,
Oct 22, 2002, 8:06:13 AM10/22/02
to
Paul,

I have already seen that example. The problem is that it is in Visual C++
and I am having troubles translating over to VO. Tried to find VB example
with no success.

Rob

"Paul Piko" <pa...@piko.com.au> wrote in message
news:Mg_s9.10558$DP6....@news-server.bigpond.net.au...

Karl-Heinz Rauscher

unread,
Oct 22, 2002, 1:33:08 PM10/22/02
to
Rob,

to make a quick working VO-sample is not as hard as it seems ( the harder
job will be to make a nice interface <g>.) The codeguru sample gives all
headeritems the ownerdraw style. Afterwards the owner of the header - the
listview - traps the WM_DRAWITEM msg. That´s the place where you draw the
multiline text.


// Here are some VO - tests ...

CLASS MyListView INHERIT ListView
PROTECT _oFontText AS Font

METHOD Dispatch ( oEvent ) CLASS MyListView
LOCAL struDrawItem AS _WINDRAWITEMSTRUCT
LOCAL struRect IS _winRECT
LOCAL hDC AS PTR
LOCAL pszItem AS PSZ
LOCAL hOldFont AS PTR
LOCAL aText := {"Line1" , "break" }
LOCAL i AS DWORD

IF oEvent:Message == WM_DRAWITEM

struDrawItem := PTR ( _CAST , oEvent:lParam )


hDC := struDrawItem.hDC
struRect := struDrawItem.rcItem

// select the "small" font ( only temporary ! )
hOldFont := SelectObject ( hDC , _oFontText:handle() )

FillRect ( hDC , @struRect , GetSysColorBrush ( COLOR_BTNFACE ) )

struRect.Left += 4
struRect.Right -= 4
struRect.Top += 2

FOR i := 1 UPTO ALen ( aText )

// two lines ....
pszItem := StringAlloc ( aText [ i ] )

// DT_CENTER , DT_LEFT or DT_RIGHT alignment
DrawText ( hDC, pszItem , PszLen ( pszItem ) ,;
@struRect , _or ( DT_CENTER , DT_SINGLELINE ) )

// next line ...
struRect.Top += 12

MemFree ( pszItem )

NEXT


struRect.Top -= 14


// select again the "large" Font
SelectObject ( hDC , hOldFont )

RETURN SELF:eventReturnValue := 1L


ENDIF

RETURN SUPER:Dispatch ( oEvent )

METHOD Init(oOwner, xID, oPoint, oDimension, kStyle) CLASS MyListView
LOCAL oFontHeader AS FONT
LOCAL hHeader AS PTR

// Text font
_oFontText := Font { , 8 , "Tahoma" }

oFontHeader := Font { ,17 , "Tahoma" }

SUPER:Init(oOwner, xID, oPoint, oDimension, kStyle )


hHeader := ListView_GetHeader ( SELF:Handle() )

// the "large" font ensures that 2 lines fit in a header
SendMessage ( hHeader , WM_SETFONT , DWORD ( _CAST , oFontHeader:handle() )
, MAKELONG ( 1, 0 ) )

// ---------------------------
// After all columns are attached call
// such a method to give the headeritems the
// ownerdraw style
// ---------------------------

METHOD MakeHeaderOD() CLASS DtaLV
LOCAL i AS DWORD
LOCAL hHeader AS PTR
LOCAL struHDItem IS _winHD_ITEM


hHeader := ListView_GetHeader ( oDCListView1:Handle() )


FOR i := 1 UPTO SendMessage ( hHeader , HDM_GETITEMCOUNT , 0 , 0L )

MemClear ( @struHDItem , _sizeof ( _winHD_ITEM ) )

struHDItem.mask := HDI_FORMAT

SendMessage ( hHeader , HDM_GETITEM , i-1 , LONG ( _CAST , @struHDItem ) )
struHDItem.fmt := _or ( struHDItem.fmt , HDF_OWNERDRAW )


SendMessage ( hHeader , HDM_SETITEM , i-1 , LONG ( _CAST , @struHDItem ) )


NEXT


--
regards
Karl-Heinz

http://people.freenet.de/KHRauscher/

Rob Panosh

unread,
Oct 22, 2002, 4:26:59 PM10/22/02
to
Thanks Karl_Heinz ... I REALLY appreciate you taking the time to put this
sample together for me.

Cheers,
Rob

"Karl-Heinz Rauscher" <khrausch...@compuserve.com> wrote in message
news:ap4271$rls1k$1...@ID-61886.news.dfncis.de...

Michael Rubinstein

unread,
Oct 22, 2002, 7:19:43 PM10/22/02
to
Rob, I'll share it with you, if you don't mind <g>. Thanks Karl-Heinz.

Michael

"Rob Panosh" <rob_p...@asdsoftware.com> wrote in message
news:3db5c33f$1...@news.splitrock.net...

Karl-Heinz Rauscher

unread,
Oct 23, 2002, 1:59:30 PM10/23/02
to
Rob,

>> ... you taking the time to put this
>> sample together for me.

yep ! .... only for you <G>

0 new messages