回 帖 发 新 帖 刷新版面

主题:请问怎么得到listctrl的用户选择的列表项?

在sdk中,我想请问一下各位,如何用api得到listctrl的用户所选择的列表项:
功能分为两个函数:
第一个是实现CListCtrl的GetFirstSelectedItemPosition()功能和GetNextSelectedItem(pos)的功能。
第二是是实现从知道第几个item去而去找出这个列表项.

敬请各位慷慨指教。

回复列表 (共3个回复)

沙发


如果是单选。
int nIndex = (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));

板凳

UINT nSelectCount = (UINT)::SendMessage(m_hWnd, LVM_GETSELECTEDCOUNT, 0, 0L);

        
        lResult = SendMessage(         // returns LRESULT in lResult
        (HWND) hWndControl,            // handle to destination control
        (UINT) LVM_GETNEXTITEM,        // message ID
        (WPARAM) wParam,               // = (WPARAM) (int) iStart
        (LPARAM) lParam                // = (LPARAM) MAKELPARAM ((UINT) flags, 0)
        );

Parameters

iStart
Index of the item to begin the search with, or -1 to find the first item that matches the specified flags. The specified item itself is excluded from the search.
flags
Specifies the relationship to the item specified in iStart. This can be one or a combination of the following values:

Searches by index.
LVNI_ALL
Searches for a subsequent item by index, the default value.

Searches by physical relationship to the index of the item where the search is to begin.
LVNI_ABOVE
Searches for an item that is above the specified item.
LVNI_BELOW
Searches for an item that is below the specified item.
LVNI_TOLEFT
Searches for an item to the left of the specified item.
LVNI_TORIGHT
Searches for an item to the right of the specified item.

The state of the item to find can be specified with one or a combination of the following values:
LVNI_CUT
The item has the LVIS_CUT state flag set.
LVNI_DROPHILITED
The item has the LVIS_DROPHILITED state flag set
LVNI_FOCUSED
The item has the LVIS_FOCUSED state flag set.
LVNI_SELECTED
The item has the LVIS_SELECTED state flag set.

If an item does not have all of the specified state flags set, the search continues with the next item.
Return Value

Returns the index of the next item if successful, or -1 otherwise.

3 楼

通常都不直接用SendMessage,用commctrl.h里的宏..

UINT ListView_GetSelectedCount(
    HWND hwnd
);

int ListView_GetNextItem(
    HWND hwnd,
    int iStart,
    UINT flags
);

我来回复

您尚未登录,请登录后再回复。点此登录或注册