{"id":87,"date":"2007-05-12T13:48:34","date_gmt":"2007-05-12T11:48:34","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/listview-ownerdraw-of-headers\/"},"modified":"2007-05-12T13:48:35","modified_gmt":"2007-05-12T11:48:35","slug":"listview-ownerdraw-of-headers","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/listview-ownerdraw-of-headers\/","title":{"rendered":"ListView: OwnerDraw of Headers"},"content":{"rendered":"<p>Von: Damon Chandler<br \/>\nBetreff: Re: TListView Headers<br \/>\nDatum: Montag, 12. April 1999 07:38<\/p>\n<p>Sebastian,<br \/>\n\tWhay you need first is a handle to the ListView&#8217;s header control.  This<br \/>\ncan be done with a call to the API function GetDlgItem()&#8230;<\/p>\n<p>[code lang=&#8221;delphi&#8221;]HeaderHandle : HWND;<br \/>\nHeaderHandle := GetDlgItem(ListView1.Handle, 0);<br \/>\n[\/code]<br \/>\nNow that you have a handle to the header control, what you need to do is<br \/>\nchange the header control to owner-drawn.  This is done with a call to<br \/>\nthe SetHeader_Item API call&#8230;<\/p>\n<p>[code lang=&#8221;delphi&#8221;]    hdi : HD_ITEM; <\/p>\n<p>    for i := 0 to ListView1.Columns.Count &#8211; 1 do<br \/>\n    begin <\/p>\n<p>        hdi.mask := HDI_TEXT and HDI_FORMAT and HDI_WIDTH; <\/p>\n<p>        {Flag owner draw state}<br \/>\n        hdi.fmt := HDF_LEFT and HDF_OWNERDRAW and HDF_STRING; <\/p>\n<p>        hdi.cxy := Columns.Items[i].Width;<br \/>\n        hdi.cchTextMax := Columns.Items[i].Caption.Length(); <\/p>\n<p>        hdi.pszText := Columns.Items[i].Caption; <\/p>\n<p>        {Force the changes}<br \/>\n        Header_SetItem(HeaderHandle, index, hdi^); <\/p>\n<p>    end<br \/>\n[\/code]<br \/>\nNow that the headers are owner-drawn, Windows will send the ListView the<br \/>\nWM_DRAWITEM message which you have to trap in the ListView&#8217;s WindowProc<br \/>\n(or a derived unit from TListView) and decode.  The LParam of the<br \/>\nWM_DRAWITEM message is a DRAWITEM structure.  Its member will give you<br \/>\nvital info about how to draw the headers, including bounding rect and<br \/>\ndevice context.  Unfotunately, my Object Pascal is rusty so I can&#8217;t give<br \/>\nany more specifics, but if you can read C++, I have an article on how to<br \/>\ndo this using C++ Builder at&#8230;<\/p>\n<p>http:\/\/bcbcaq.freeservers.com<br \/>\nhttp:\/\/bcbcaq.freeservers.com<\/p>\n<p>in the &#8220;ListViews and TreeViews&#8221; section.  Good luck.<\/p>\n<p>\/\/Damon<\/p>\n<p>[tags]Delphi, Components, ListView[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Von: Damon Chandler Betreff: Re: TListView Headers Datum: Montag, 12. April 1999 07:38 Sebastian, Whay you need first is a handle to the&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[90,75,78],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-1p","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/87"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=87"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/87\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}