win32項目 列表控件ListView的使用(一)


列表控件(ListView)的結構體,LVITEMA structure

typedef struct tagLVITEMA {
  UINT   mask;
  int    iItem;
  int    iSubItem;
  UINT   state;
  UINT   stateMask;
  LPSTR  pszText;
  int    cchTextMax;
  int    iImage;
  LPARAM lParam;
  int    iIndent;
  int    iGroupId;
  UINT   cColumns;
  PUINT  puColumns;
  int    *piColFmt;
  int    iGroup;
} LVITEMA, *LPLVITEMA;

成員變量

mask

Type: UINT

Set of flags that specify which members of this structure contain data to be set or which members are being requested. This member can have one or more of the following flags set:

指定此結構的哪些成員包含要設置的數據或正在請求的成員的標志集。此成員可以設置以下一個或多個標志:

Value Meaning
LVIF_COLFMT

Windows Vista and later. The piColFmt member is valid or must be set. If this flag is used, the cColumns member is valid or must be set.

Windows Vista及更高版本。piColFmt成員有效或必須設置。如果使用此標志,則cColumns成員有效或必須設置。

LVIF_COLUMNS

The cColumns member is valid or must be set.

cColumns成員有效或必須設置。

LVIF_DI_SETITEM

The operating system should store the requested list item information and not ask for it again. This flag is used only with the LVN_GETDISPINFO notification code.

操作系統應存儲請求的列表項信息,而不是再次請求。此標志僅用於LVN_GETDISPINFO通知代碼。

LVIF_GROUPID

The iGroupId member is valid or must be set. If this flag is not set when an LVM_INSERTITEM message is sent, the value of iGroupId is assumed to be I_GROUPIDCALLBACK.

iGroupId成員有效或必須設置。如果在發送LVM_INSERTITEM消息時未設置此標志,則假定iGroupId的值為I_GROUPIDCALLBACK。

LVIF_IMAGE

The iImage member is valid or must be set.

iImage成員有效或必須設置。

LVIF_INDENT

The iIndent member is valid or must be set.

iIndent成員有效或必須設置。

LVIF_NORECOMPUTE

The control will not generate LVN_GETDISPINFO to retrieve text information if it receives an LVM_GETITEM message. Instead, the pszText member will contain LPSTR_TEXTCALLBACK.

如果控件接收到LVM_GETITEM消息,則不會生成LVN_GETDISPINFO來檢索文本信息。相反,pszText成員將包含LPSTR_TEXTCALLBACK。

LVIF_PARAM

The lParam member is valid or must be set.

lParam成員有效或必須設置。

LVIF_STATE

The state member is valid or must be set.

state成員有效或必須設置。

LVIF_TEXT

The pszText member is valid or must be set.

pszText成員有效或必須設置。

iItem

Type: int

Zero-based index of the item to which this structure refers.

此結構引用的項的從零開始的索引。

iSubItem

Type: int

One-based index of the subitem to which this structure refers, or zero if this structure refers to an item rather than a subitem.

此結構引用的子項的一個基索引,如果此結構引用的是項而不是子項,則為零。

state

Type: UINT

Indicates the item's state, state image, and overlay image. The stateMask member indicates the valid bits of this member.

指示項的狀態、狀態圖像和覆蓋圖像。statemack成員指示此成員的有效位。

Bits 0 through 7 of this member contain the item state flags. This can be one or more of the item state values.

此成員的位0到7包含項狀態標志。這可以是一個或多個項狀態值。

Bits 8 through 11 of this member specify the one-based overlay image index. Both the full-sized icon image list and the small icon image list can have overlay images. The overlay image is superimposed over the item's icon image. If these bits are zero, the item has no overlay image. To isolate these bits, use the LVIS_OVERLAYMASK mask. To set the overlay image index in this member, you should use the INDEXTOOVERLAYMASK macro. The image list's overlay images are set with the ImageList_SetOverlayImage function.

此成員的位8到11指定基於一個的覆蓋圖像索引。全尺寸圖標圖像列表和小圖標圖像列表都可以有覆蓋圖像。覆蓋圖像疊加在項目的圖標圖像上。如果這些位為零,則該項沒有覆蓋圖像。要隔離這些位,請使用LVIS_OVERLAYMASK掩碼。若要在此成員中設置覆蓋圖像索引,應使用INDEXTOOVERLAYMASK宏。圖像列表的覆蓋圖像是使用image list_set overlay image函數設置的。

Bits 12 through 15 of this member specify the state image index. The state image is displayed next to an item's icon to indicate an application-defined state. If these bits are zero, the item has no state image. To isolate these bits, use the LVIS_STATEIMAGEMASK mask. To set the state image index, use the INDEXTOSTATEIMAGEMASK macro. The state image index specifies the index of the image in the state image list that should be drawn. The state image list is specified with the LVM_SETIMAGELIST message.

此成員的位12到15指定狀態圖像索引。狀態圖像顯示在項目圖標旁邊,指示應用程序定義的狀態。如果這些位為零,則該項沒有狀態圖像。要隔離這些位,請使用LVIS_STATEIMAGEMASK掩碼。要設置狀態圖像索引,請使用indextostatimagemask宏。狀態圖像索引指定應在狀態圖像列表中繪制的圖像的索引。狀態映像列表是用LVM_SETIMAGELIST消息指定的。

stateMask

Type: UINT

Value specifying which bits of the state member will be retrieved or modified. For example, setting this member to LVIS_SELECTED will cause only the item's selection state to be retrieved.

指定將檢索或修改狀態成員的位的值。例如,將此成員設置為LVIS_SELECTED將只檢索項目的選擇狀態。

This member allows you to modify one or more item states without having to retrieve all of the item states first. For example, setting this member to LVIS_SELECTED and state to zero will cause the item's selection state to be cleared, but none of the other states will be affected.

此成員允許您修改一個或多個項狀態,而無需首先檢索所有項狀態。例如,將此成員設置為LVIS_SELECTED且state設置為零將導致清除項的選擇狀態,但不會影響其他任何狀態。

To retrieve or modify all of the states, set this member to (UINT)-1.
要檢索或修改所有狀態,請將此成員設置為(UINT)-1。

You can use the macro ListView_SetItemState both to set and to clear bits.
您可以使用宏ListView_SetItemState來設置和清除位。

pszText

Type: LPTSTR

If the structure specifies item attributes, pszText is a pointer to a null-terminated string containing the item text. When responding to an LVN_GETDISPINFO notification, be sure that this pointer remains valid until after the next notification has been received.

如果結構指定項屬性,則pszText是指向包含項文本的以空結尾的字符串的指針。響應LVN_GETDISPINFO通知時,請確保此指針在收到下一個通知之前保持有效。

If the structure receives item attributes, pszText is a pointer to a buffer that receives the item text. Note that although the list-view control allows any length string to be stored as item text, only the first 259 TCHARs are displayed.
如果結構接收到項屬性,則pszText是指向接收項文本的緩沖區的指針。請注意,盡管列表視圖控件允許將任何長度字符串存儲為項文本,但僅顯示前259tchars。

If the value of pszText is LPSTR_TEXTCALLBACK, the item is a callback item. If the callback text changes, you must explicitly set pszText to LPSTR_TEXTCALLBACK and notify the list-view control of the change by sending an LVM_SETITEM or LVM_SETITEMTEXT message.
如果pszText的值為LPSTR_TEXTCALLBACK,則該項為回調項。如果回調文本更改,則必須將pszText顯式設置為LPSTR_text callback,並通過發送LVM_SETITEM或LVM_SETITEM text消息將更改通知列表視圖控件。

Do not set pszText to LPSTR_TEXTCALLBACK if the list-view control has the LVS_SORTASCENDING or LVS_SORTDESCENDING style.
如果列表視圖控件具有LVS-SORTASCENDING或LVS-SORTDESCENDING樣式,則不要將pszText設置為LPSTR-TEXTCALLBACK。

cchTextMax

Type: int

Number of TCHARs in the buffer pointed to by pszText, including the terminating NULL.
pszText指向的緩沖區中的TCHARs數,包括終止空值。

This member is only used when the structure receives item attributes. It is ignored when the structure specifies item attributes. For example, cchTextMax is ignored during LVM_SETITEM and LVM_INSERTITEM. It is read-only during LVN_GETDISPINFO and other LVN_ notifications.
此成員僅在結構接收到項屬性時使用。當結構指定項屬性時,它將被忽略。例如,在LVM_SETITEM和LVM_INSERTITEM期間忽略cchTextMax。它在LVN_GETDISPINFO和其他LVN_通知期間是只讀的。

Note Never copy more than cchTextMax TCHARs—where cchTextMax includes the terminating NULL—into pszText during an LVN_ notification, otherwise your program can fail.
注意:在LVNú通知期間,不要復制超過cchTextMax TCHARs的cchTextMax,其中cchTextMax將終止NULL包含到pszText中,否則您的程序可能會失敗。

iImage
Type: int

Index of the item's icon in the control's image list. This applies to both the large and small image list. If this member is the I_IMAGECALLBACK value, the parent window is responsible for storing the index. In this case, the list-view control sends the parent an LVN_GETDISPINFO notification code to retrieve the index when it needs to display the image.
控件圖像列表中項目圖標的索引。這適用於大圖像列表和小圖像列表。如果此成員是I_IMAGECALLBACK值,則父窗口負責存儲索引。在這種情況下,列表視圖控件在需要顯示圖像時向父級發送LVN_GETDISPINFO通知代碼以檢索索引。

lParam
Type: LPARAM

Value specific to the item. If you use the LVM_SORTITEMS message, the list-view control passes this value to the application-defined comparison function. You can also use the LVM_FINDITEM message to search a list-view control for an item with a specified lParam value.
特定於項的值。如果使用LVM_SORTITEMS消息,列表視圖控件會將此值傳遞給應用程序定義的比較函數。還可以使用LVM_FINDITEM消息在列表視圖控件中搜索具有指定lParam值的項。

iIndent

Type: int

Version 4.70. Number of image widths to indent the item. A single indentation equals the width of an item image. Therefore, the value 1 indents the item by the width of one image, the value 2 indents by two images, and so on. Note that this field is supported only for items. Attempting to set subitem indentation will cause the calling function to fail.
版本4.70。縮進項目的圖像寬度數。一個縮進等於項目圖像的寬度。因此,值1按一個圖像的寬度縮進項,值2按兩個圖像縮進項,依此類推。請注意,此字段僅支持項。試圖設置子項縮進將導致調用函數失敗。

iGroupId

Type: int

Version 6.0 Identifier of the group that the item belongs to, or one of the following values.
項所屬組的版本6標識符,或下列值之一。

 

Value Meaning
I_GROUPIDCALLBACK

The listview control sends the parent an LVN_GETDISPINFO notification code to retrieve the index of the group.

listview控件向父級發送LVN_GETDISPINFO通知代碼,以檢索組的索引。

I_GROUPIDNONE

The item does not belong to a group.

該項不屬於組。

cColumns

Type: UINT

Version 6.0 Number of data columns (subitems) to display for this item in tile view. The maximum value is 20. If this value is I_COLUMNSCALLBACK, the size of the column array and the array itself (puColumns) are obtained by sending a LVN_GETDISPINFO notification.
版本6.0要在平鋪視圖中為此項顯示的數據列(子項)數。最大值是20。如果此值為I_COLUMNSCALLBACK,則通過發送LVN_GETDISPINFO通知獲得列數組的大小和數組本身。

puColumns

Type: PUINT

Version 6.0 A pointer to an array of column indices, specifying which columns are displayed for this item, and the order of those columns.
版本6.0指向列索引數組的指針,指定為此項顯示哪些列以及這些列的順序。

piColFmt

Type: int*

Windows Vista: Not implemented. Windows 7 and later: A pointer to an array of the following flags (alone or in combination), specifying the format of each subitem in extended tile view.
Windows Vista:未實現。Windows7及更高版本:指向下列標志數組(單獨或組合)的指針,指定擴展平鋪視圖中每個子項的格式。

Value Meaning
LVCFMT_LINE_BREAK

Forces the column to wrap to the top of the next list of columns.

強制將列換行到下一列列表的頂部。

LVCFMT_FILL

Fills the remainder of the tile area. Might have a title.

填充平鋪區域的其余部分。可能有個標題。

LVCFMT_WRAP

Allows the column to wrap within the remaining space in its list of columns.

允許列在其列列表的剩余空間內換行。

LVCFMT_NO_TITLE

Removes the title from the subitem.

從子項中刪除標題。

LVCFMT_TILE_PLACEMENTMASK

Equivalent to a combination of LVCFMT_LINE_BREAK and LVCFMT_FILL.

相當於LVCFMT_LINE_BREAK和LVCFMT_FILL的組合。

iGroup

Type: int

Windows Vista: Group index of the item. Valid only for owner data/callback (single item in multiple groups).
Windows Vista:項的組索引。僅對所有者數據/回調有效(多個組中的單個項)。

Remarks

The LVITEM structure is used with several messages, including LVM_GETITEM, LVM_SETITEM, LVM_INSERTITEM, and LVM_DELETEITEM.
LVITEM結構用於多個消息,包括LVM_GETITEM、LVM_SETITEM、LVM_INSERTITEM和LVM_deleteeitem。

In tile view, the item name is displayed to the right of the icon. You can specify additional subitems (corresponding to columns in the details view), to be displayed on lines below the item name. The puColumns array contains the indices of subitems to be displayed. Indices should be greater than 0, because subitem 0, the item name, is already displayed. Column information can also be set in the LVTILEINFO structure when modifying the list item.
在平鋪視圖中,項目名稱顯示在圖標的右側。可以指定其他子項(對應於“詳細信息”視圖中的列),這些子項將顯示在項名稱下面的行上。puColumns數組包含要顯示的子項的索引。索引應大於0,因為已顯示項名稱子項0。在修改列表項時,還可以在LVTILEINFO結構中設置列信息。

Note Comctl32.dll version 6 is not redistributable but it is included in Windows or later. To use Comctl32.dll version 6, specify it in a manifest. For more information on manifests, see Enabling Visual Styles.
注意:Comctl32.dll版本6不可再發行,但它包含在Windows或更高版本中。要使用Comctl32.dll版本6,請在清單中指定它。有關清單的詳細信息,請參見啟用視覺樣式。

Requirements

Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Header commctrl.h

參考文檔:MSDN

個人見解:

新建win32項目之后,打開rc文件,通過工具箱拖拽ListView控件到對話框中。

通過GetDlgItem函數,獲取控件句柄。

然后設置LVITEM結構體,然后使用SendMessage函數發送此結構到控件上。

控件顯示結構體中設置的文字等信息。

還有一些別的結構體,如:LVCOLUMN.

SDK開發,就是通過這些結構體,使用Sendmessage,控制及實現控件的各種顯示效果。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM