求助,关于ListCtrl

kelvin0009 2006-07-26 10:54:42
新手提问,如何实现鼠标左键点击List框中的空白区域,则之前选择的item取消选择状态,即没有一个item为选中状态.小弟这段代码没有实现这个目标,错在哪里呢?
CRect rect1;
CRect rect2;
CRect rect3;

CPoint m_Point;

int i = GetItemCount();
GetItemRect(i-1,&rect1,LVIR_BOUNDS);

GetClientRect(&rect2);
rect3.top = rect1.bottom;
rect3.left = rect1.left;
rect3.bottom = rect2.bottom;

GetCursorPos(&m_Point);

if(rect3.PtInRect(m_Point))
{
...
}
...全文
176 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xqk 2006-07-26
  • 打赏
  • 举报
回复
在控件的NM_CLICK消息中处理:

if(-1 == m_list1.GetSelectionMark())
{
POSITION pos = pList->GetFirstSelectedItemPosition();
if (pos == NULL)
TRACE0("No items were selected!\n");
else
{
while (pos)
{
int nItem = pList->GetNextSelectedItem(pos);
TRACE1("No items were selected!\n");
SetItemState(pos-1, ...);
}
}


}
saz 2006-07-26
  • 打赏
  • 举报
回复
int list_index=0;
if(m_listnumber.GetItemState(list_index,LVIS_SELECTED)
!=LVIS_SELECTED && list_index<m_listnumber.GetItemCount())
{
list_index++;
}
if(list_index>=m_listnumber.GetItemCount())
{//超出范围
number_text="";
pwd_text="";
}
else
{//没有超出范围,取值
number_text=m_listnumber.GetItemText(list_index,1);
pwd_text=m_listnumber.GetItemText(list_index,2);
}


应该对你有帮助
kelvin0009 2006-07-26
  • 打赏
  • 举报
回复
已得出 pList->SetItemState(nItem,0,LVIS_FOCUSED | LVIS_SELECTED);可以消除item的selected和focused状态,但是怎么判断鼠标左键是否点击在ListCrtl空白区域?
kelvin0009 2006-07-26
  • 打赏
  • 举报
回复
怎么判断鼠标左键点击在ListCtrl中的空白区域,从而使之前选中的item状态变为正常?
吹雪 2006-07-26
  • 打赏
  • 举报
回复
NM_CLICK中
NMLISTVIEW *pList = ( NMLISTVIEW* )pNMHDR;
if( pList->item == -1 )
{
//表示没有选中项.
}

15,976

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧