void CGetList::OnItemclick(NMHDR* pNMHDR, LRESULT* pResult)
{
HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
在上面有phdn如何获得有关的参数,例如列表中的第几行。
还HD_NOTIFY是怎样的结构?
{
HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
在上面有phdn如何获得有关的参数,例如列表中的第几行。
还HD_NOTIFY是怎样的结构?
HWND hwndFrom;
UINT idFrom;
UINT code;
} NMHDR;code Notification code. This member can be a control-specific notification code or it can be one of the common notification codes. The following values are not supported: NM_RCLICK
NM_RDBCLICK
-----------------------------------------------------------------
typedef struct _HD_ITEM { hdi
UINT mask;
int cxy;
LPSTR pszText;
HBITMAP hbm;
int cchTextMax;
int fmt;
LPARAM lParam;
} HD_ITEM;-----------------------------------------------------------------
typedef struct _HD_NOTIFY {
NMHDR hdr;
int iItem;
int iButton;
HD_ITEM FAR *pitem;
} HD_NOTIFY;iItem Zero-based index of the header item that is the focus of the notification message. iButton Index of the mouse button used to generate the notification message. It is one of the following values:Value Description
0 Left button
1 Right button
2 Middle button -----------------------------------------------------------------
一般WIN32中的 WM_NOTIFY 消息实际上会使用包含NMHDR型结构为第一个成员的结构指针,比如上面的 HD_NOTIFY, 因此在使用时必须先将其强制转换恢复本来面目。更多细节请参阅
MSDN:
TN061: ON_NOTIFY and WM_NOTIFY Messages
// GetSelectedListItem()
// return value:
// -1: no list item
// -2: no selected list item
// >=0: index of selected list item
//
int GetSelectedListItem(CListCtrl& ctrlList)
{
int nCount = ctrlList.GetItemCount();
if(nCount <= 0)
{
return -1; // no item
} if(ctrlList.GetSelectedCount() == 0)
{
return -2; // no selection
} LV_ITEM lvi;
lvi.mask = LVIF_STATE | LVIF_PARAM;
lvi.iSubItem = 0;
lvi.stateMask = 0xFFFF; // get all state flags
int nItemSel = -2; for (int i = 0; i < nCount; ++ i)
{
lvi.iItem = i;
ctrlList.GetItem(&lvi);
if((lvi.state & LVIS_SELECTED) != 0)
{
nItemSel = i;
break;
}
} return nItemSel;
}
// GetSelectedListItem()
// return value:
// -1: no list item
// -2: no selected list item
// >=0: index of selected list item
//
int GetSelectedListItem(CListCtrl& ctrlList)
{
int nCount = ctrlList.GetItemCount();
if(nCount <= 0)
{
return -1; // no item
} if(ctrlList.GetSelectedCount() == 0)
{
return -2; // no selection
} LV_ITEM lvi;
lvi.mask = LVIF_STATE | LVIF_PARAM;
lvi.iSubItem = 0;
lvi.stateMask = 0xFFFF; // get all state flags
int nItemSel = -2; for (int i = 0; i < nCount; ++ i)
{
lvi.iItem = i;
ctrlList.GetItem(&lvi);
if((lvi.state & LVIS_SELECTED) != 0)
{
nItemSel = i;
break;
}
} return nItemSel;
}
hdr
NMHDR structure that contains information about the notification message.
iItem
Zero-based index of the header item that is the focus of the notification message.
iButton
Value specifying the index of the mouse button used to generate the notification message. This member can be one of the following values: 0 Left button
1 Right button
2 Middle button pitem
Optional pointer to an HDITEM structure containing information about the item specified by iItem. The mask member of the HDITEM structure indicates which of its members are valid.
=========================================
以下是NM_CLICK相关
lpnmitem = (LPNMITEMACTIVATE) lParam;
信息:
typedef struct tagNMITEMACTIVATE{
NMHDR hdr;
int iItem;
int iSubItem;
UINT uNewState;
UINT uOldState;
UINT uChanged;
POINT ptAction;
LPARAM lParam;
UINT uKeyFlags;
} NMITEMACTIVATE, FAR *LPNMITEMACTIVATE;hdr
NMHDR structure that contains information about this notification message.
iItem
Index of the list view item. If the item index is not used for the notification, this member will contain -1.
iSubItem
One-based index of the subitem. If the subitem index is not used for the notification or the notification does not apply to a subitem, this member will contain zero.
uNewState
New item state. This member is zero for notification messages that do not use it.
uOldState
Old item state. This member is zero for notification messages that do not use it.
uChanged
Set of flags that indicate the item attributes that have changed. This member is zero for notifications that do not use it. Otherwise, it can have the same values as the mask member of the LVITEM structure.
ptAction
POINT structure that indicates the location at which the event occurred. This member is undefined for notification messages that do not use it.
lParam
Application-defined 32-bit value of the item. This member is undefined for notification messages that do not use it.
uKeyFlags
Modifier keys that were pressed at the time of the activation. This member contains zero or a combination of the following flags: LVKF_ALT The ALT key is pressed.
LVKF_CONTROL The CTRL key is pressed.
LVKF_SHIFT The SHIFT key is pressed.
SubitemHitTest