【问题标题】:Delphi XE2: TListView as tile view not working in Windows XPDelphi XE2:TListView 作为平铺视图在 Windows XP 中不起作用
【发布时间】:2012-02-10 02:12:52
【问题描述】:

我有一个在 TListView 控件上使用 LV_VIEW_TILE 的代码:

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, ComCtrls, CommCtrl,
  StdCtrls;

procedure TileView(aListView: TListView);
var
  ti: TLVTILEINFO;
  Order: array of Integer;
  tvi: TLVTILEVIEWINFO;
  i: integer;
begin
  ListView_SetView(aListView.Handle, LV_VIEW_TILE);

  for i := 0 to aListView.Items.Count - 1 do begin
    FillChar(ti, SizeOf(ti), 0);
    ti.cbSize := SizeOf(ti);
    // First item
    ti.iItem := i;
    // Specifying the order for three columns
    ti.cColumns := 4;
    // Array initialization
    SetLength(order, ti.cColumns);
    // The order is 2nd, 3rd and 4th columns
    order[0] := 1;
    order[1] := 2;
    order[2] := 3;
    order[3] := 4;
    ti.puColumns := PUINT(order);
    ListView_SetTileInfo(aListView.Handle, ti);
  end;

  tvi.cbSize := Sizeof(tvi);
  tvi.dwMask := LVTVIM_COLUMNS;
  // Requesting space to draw the caption + 3 subitems
  tvi.cLines := aListView.Columns.Count;
  ListView_SetTileViewInfo(aListView.Handle, tvi);
end;

procedure TForm3.FormCreate(Sender: TObject);
var V: TListView;
    A: TListItem;
begin
  V := TListView.Create(Self);
  V.Parent := Self;
  V.Align := alClient;

  V.Columns.Add;

  A := V.Items.Add;
  A.Caption := 'Item A';
  A.SubItems.Add('Sub A');

  A := V.Items.Add;
  A.Caption := 'Item B';
  A.SubItems.Add('Sub B');

  TileView(V);
end;

用Delphi 2007编译构建代码,在Windows XP下运行应用程序,显示:

用Delphi XE2编译同样的代码,在Windows XP下运行,显示:

在 Delphi XE2 中编译时不显示子项。

Delphi 2007/XE2 应用程序均显示 Windows 7 中的平铺视图子项。

我已尝试将清单嵌入应用程序的资源或作为外部文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
  type="win32"
  name="DelphiApplication"
  version="1.0.0.0"
  processorArchitecture="*"/>
  <dependency>
  <dependentAssembly>
    <assemblyIdentity
    type="win32"
    name="Microsoft.Windows.Common-Controls"
    version="6.0.0.0"
    publicKeyToken="6595b64144ccf1df"
    language="*"
    processorArchitecture="*"/>
  </dependentAssembly>
  </dependency>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  <security>
    <requestedPrivileges>
    <requestedExecutionLevel
      level="asInvoker"
      uiAccess="false"/>
    </requestedPrivileges>
  </security>
  </trustInfo>
</assembly>

知道为什么 Delphi XE2 编译的应用程序在 Windows XP 中不显示平铺视图吗?

【问题讨论】:

标签: delphi delphi-xe2


【解决方案1】:

Delphi XE2 中的单元 Winapi.CommCtrl.pas 定义:

tagLVTILEINFO = record
  cbSize: UINT;
  iItem: Integer;
  cColumns: UINT;
  puColumns: PUINT;

  piColFmt: PInteger;

end;

但是MSDN API定义为:

typedef struct LVTILEINFO {
  UINT  cbSize;
  int   iItem;
  UINT  cColumns;
  PUINT puColumns;
#if (_WIN32_WINNT >= 0x0600)
  int   *piColFmt;
#endif 
} LVTILEINFO, *PLVTILEINFO;

piColFmt 不应在 Windows XP 平台中使用。删除 piColFmt 应该可以在 Windows XP 中使用。

【讨论】:

  • 我在 Windows 10 / Delphi 10.1 Berlin 上遇到了这个问题。 tagLVTILEINFO 在 Delphi 中的定义仍然相同。它实际上将标题放在每个图块的最底部,有一个很大的空白区域(启用 VCL 样式时)并在启用 VCL 样式未时垂直居中。
  • 从头开始,我想通了。每次加载任何项目时,我都需要致电TileView。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-12
  • 2012-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-28
相关资源
最近更新 更多