问题:当我们在VS2005中把Unicode字符集改为多字节字符集后,GetHotItem返回总是-1;
解决:利用通知消息NM_CLICK(或双击消息)为例.
void CManagerUser::OnNMClickUserList(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE)pNMHDR;
m_UserList.SetHotItem(lpnmitem->iItem);
int nIndex=m_UserList.GetHotItem();
//没有热选项判断
if(nIndex==-1)
return;
//省略.......
}
MSDN中明确说到,参数pNMHDR中包含了响应该选项索引值,这是最可靠的.很多初学者直接利用GetHotItem返回,改变了其它条件后就不可靠了.当然在Unicode字符集下使用正常.
以下是NM_CLICK通知消息参数lParam传递的结构,说明如下:
NMITEMACTIVATE Structure
Contains information about an LVN_ITEMACTIVATE notification message.
Syntax
typedef struct tagNMITEMACTIVATE {
NMHDR hdr;
int iItem;
int iSubItem;
UINT uNewState;
UINT uOldState;
UINT uChanged;
POINT ptAction;
LPARAM lParam;
UINT uKeyFlags;
} NMITEMACTIVATE, *LPNMITEMACTIVATE;
Members
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 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 key is pressed.
LVKF_CONTROL- The key is pressed.
LVKF_SHIFT- The key is pressed.
Structure Information