R
Rocklee
Unregistered / Unconfirmed
GUEST, unregistred user!
以下是D6的TListView中的TListItem.SetCaption代码:<br>procedure TListItem.SetCaption(const Value: string);<br>begin<br> if Value <> Caption then<br> begin<br> FCaption := Value;<br> if not Owner.Owner.OwnerData then<br> ListView_SetItemText(Handle, Index, 0, LPSTR_TEXTCALLBACK);<br> if ListView.ColumnsShowing and<br> (ListView.Columns.Count > 0) and<br> (ListView.Column[0].WidthType <= ColumnTextWidth) then<br> ListView.UpdateColumns;<br> if ListView.SortType in [stBoth, stText] then ListView.AlphaSort;<br> end;<br>end;<br><br>这一行重要:ListView_SetItemText(Handle, Index, 0, LPSTR_TEXTCALLBACK);<br><br>而ListView_SetItemText是个Macro,Delphi里的代码为:<br>function ListView_SetItemText(hwndLV: HWND; i, iSubItem: Integer;<br> pszText: PChar): Bool;<br>var<br> Item: TLVItem;<br>begin<br> Item.iSubItem := iSubItem;<br> Item.pszText := pszText;<br> Result := Bool( SendMessage(hwndLV, LVM_SETITEMTEXT, i, Longint(@Item)) );<br>end;<br>跟ListView_SetItemTextA是相同的代码(天杀的,一如既往不支持Unicode!),<br><br>pszText=LPSTR_TEXTCALLBACK, Item.pszText := pszText, ===>Item.pszText=LPSTR_TEXTCALLBACK,查MS api Help,LV_ITEM的pszText为LPSTR_TEXTCALLBACK时此Item为CallBack Item,叫我们不要将ListView设有LVS_SORTASCENDING 或 LVS_SORTDESCENDING 样式,仅此而已,那么为CallBack Item又如何处理呢?到这里Microsoft就故作神秘了。<br><br><br>而又有一处,当执行item.subitems.Add('.... ')后更新Subitems内容的:<br>procedure TSubItems.RefreshItem(Index: Integer);<br>begin<br> ListView_SetItemText(Handle, Owner.Index, Index, LPSTR_TEXTCALLBACK);<br> SetColumnWidth(Index);<br>end;<br>也是调用ListView_SetItemText,也是用LPSTR_TEXTCALLBACK。<br><br>跟踪到这里傻了眼,Delphi的VCL是如何将ListItem的Caption、Subitems的各节内容显示出来的呢,查了半天查不出个究竟。<br><br>各位高手,出来说说。