使用xe2时发现ListView切换ViewStyle时有问题,没有设置LargeImages和SmallImages,使用的系统图标,即:
FSmallImages := SHGetFileInfo('C:\', { Do not localize }
0, FileInfo, SizeOf(FileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
SendMessage(FListView.Handle, LVM_SETIMAGELIST, LVSIL_SMALL, FSmallImages);
结果,切换时不显示图标了,查看源码发现多了几行
procedure TCustomListView.SetViewStyle(Value: TViewStyle);
const
ViewStyles: array[TViewStyle] of Integer = (LVS_ICON, LVS_SMALLICON,
LVS_LIST, LVS_REPORT);
var
Style: Longint;
begin
if Value <> FViewStyle then
begin
FViewStyle := Value;
if HandleAllocated then
begin
Style := GetWindowLong(Handle, GWL_STYLE);
Style := Style and (not LVS_TYPEMASK);
Style := Style or Integer(ViewStyles[FViewStyle]);
SetWindowLong(Handle, GWL_STYLE, Style);
UpdateColumns;
case ViewStyle of
vsIcon,
vsSmallIcon:
if IconOptions.Arrangement = iaTop then
Arrange(arAlignTop) else
Arrange(arAlignLeft);
end;
//怀疑是以下两行代码导致窗口重建了
// if not (csLoading in ComponentState) then
// RecreateWnd;
end;
end;
end;
注释掉上面的几行后图标显示正常。