我的ClistCtrl是用来显示图标的,现在我想当鼠标移动到不同的图标上时显示该图标的具体信息,不知道该怎么处理OnMouseMove事件,怎样才知道鼠标移动到了哪个图标上。不能用单击事件处理的
谢谢!

解决方案 »

  1.   

    UINT uFlags;
    int nItem = pmyListCtrl->HitTest(myPoint, &uFlags);if (uFlags & LVHT_ONITEMICON )
    {
       ......
    }
      

  2.   

    http://www.codeproject.com/listctrl/quicklist.asp
      

  3.   

    http://www.codeproject.com/listctrl/ctooltiplistctrl.asp
      

  4.   

    多谢各位相助现在OnMouseMove事件处理已经可以了,继承一下CListCtrl就可以有那个事件了.但OnMouseMove方法中,只有参数
    OnMouseMove(UINT nFlags, CPoint point) 
    如何将这个point参数转换为我想实际处理中要用到的行列关系了?在这个onMouseMove方法中,怎么知道我的鼠标指向了哪个图标了?谢谢
      

  5.   

    OnMouseMove(UINT nFlags, CPoint point) 这里面的point的坐标已经是client坐标了,怎么由它得到我所指的每个图标了?还是没一点头绪
      

  6.   

    lixiaosan(小三) ( ) 信誉:150  2006-4-23 16:42:23  得分: 0  
       
    http://www.codeproject.com/listctrl/ctooltiplistctrl.asp
    多谢楼上老兄。用上面这个代码已经实现了每个listCtrl项的toolTip的提示信息了。但现在还有两个问题:
    1是如果让程序在我的listCtrl中的图标上有toolTip提示信息了?上面那个代码中只有在文字项上面才有提示,在图标上就没有提示了?2是如何让toolTip能够多行显示了?
    感觉感谢老兄。
    小弟刚从JAVA转过来学VC,很不适应啊,请各位老兄们多多指点了  
     
      

  7.   

    SetItemData可以设置更多的Item信息
    -----------------------------------------------
    MyCSDN 免费版 - http://community.csdn.net/Expert/TopicView1.asp?id=4608614
      

  8.   

    但现在还有两个问题:
    1是如果让程序在我的listCtrl中的图标上有toolTip提示信息了?上面那个代码中只有在文字项上面才有提示,在图标上就没有提示了?2是如何让toolTip能够多行显示了?
    郁闷,这问题还是没解决了或者有什么办法解决我想把鼠标移到不同的图标上可以显示每个图标不同的信息了?
    各位高手帮帮忙啊
      

  9.   

    Mark一下,看看有没有好的方法。
      

  10.   

    不需要处理WM_MOUSEMOVE消息,响应LVN_GETINFOTIP即可。下面的代码是我派生的一个列表类,用于显示图片的缩略图,仿照ACDSee V6.0的。
    ...
    ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnGetInfoTip)
    ...void CThumbnailListCtrl::OnGetInfoTip(NMHDR* pNMHDR, LRESULT* pResult) 
    {
    static TCHAR szTip[255] = {0};
    LPNMLVGETINFOTIP pGetInfoTip = (LPNMLVGETINFOTIP)pNMHDR; if(pGetInfoTip->dwFlags != 0)
    {
    CString strTip = MakeTooltip((PLVITEM_EXINFO)GetItemData(pGetInfoTip->iItem));
    strcpy(szTip, strTip); pGetInfoTip->cchTextMax = 255;
    pGetInfoTip->pszText = szTip;
    }
    pResult = 0;
    }CString CThumbnailListCtrl::MakeTooltip(IN PLVITEM_EXINFO pItemInfo)
    {
    ASSERT(pItemInfo != NULL);

    //创建时间
    CString strCreateTime(_T(""));
    SYSTEMTIME timeCreate = {0};
    FileTimeToSystemTime(&pItemInfo->FileInfo.ftCreationTime, &timeCreate);
    strCreateTime.Format("%d-%d-%d %.2d:%.2d:%.2d", timeCreate.wYear,
    timeCreate.wMonth,
    timeCreate.wDay,
    timeCreate.wHour,
    timeCreate.wMinute,
    timeCreate.wSecond); //最后存取时间
    CString strLastAccess(_T(""));
    SYSTEMTIME timeLastAccess = {0};
    FileTimeToSystemTime(&pItemInfo->FileInfo.ftLastAccessTime, &timeLastAccess);
    strLastAccess.Format("%d-%d-%d %.2d:%.2d:%.2d", timeLastAccess.wYear,
    timeLastAccess.wMonth,
    timeLastAccess.wDay,
    timeLastAccess.wHour,
    timeLastAccess.wMinute,
    timeLastAccess.wSecond);

    //最后写时间
    CString strLastWrite(_T(""));
    SYSTEMTIME timeLastWrite = {0};
    FileTimeToSystemTime(&pItemInfo->FileInfo.ftLastWriteTime, &timeLastWrite);
    strLastWrite.Format("%d-%d-%d %.2d:%.2d:%.2d", timeLastWrite.wYear,
    timeLastWrite.wMonth,
    timeLastWrite.wDay,
    timeLastWrite.wHour,
    timeLastWrite.wMinute,
    timeLastWrite.wSecond);

    //文件大小(KB)
    CString strLength(_T(""));
    DWORD dwLength = (pItemInfo->FileInfo.nFileSizeHigh) << 16;
    dwLength += pItemInfo->FileInfo.nFileSizeLow;
    strLength.Format("%0.1fKB", (float)dwLength/1024);

    CString strTip("位置: ");
    strTip += pItemInfo->szPath;
    strTip += "\n大小: " + strLength + "\n";
    strTip += "创建时间: " + strCreateTime +"\n";
    strTip += "修改时间: " + strLastWrite + "\n";
    strTip += "访问时间: " + strLastAccess;

    return strTip;
    }
      

  11.   

    多谢楼上老兄了。请问这个事件是加在listCtrl上吗?可我在我的listCtrl中没有找到这个事件,只有一个Getdispinfo了?我是在listCtrl的这个资源ID上没找到这个事件,也没有在listCtrl的派生类中找到这个事件了
      

  12.   

    试试打开ClassWizard,点击最后一个选项卡“Class Info”,左下角“Message Filter”下拉列表框,把它改成“Window”,再回去看看有没有出现这个消息。
    其实你可以直接在代码里插入而不用经过ClassWizard。只要改3个地方即可:
    1) 在你的列表类的头文件里添加:
       //{{AFX_MSG(CThumbnailListCtrl)
       ...
       afx_msg void OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult);
       ...
       //}}AFX_MSG2) 在列表类的cpp文件中添加:
       IMPLEMENT_DYNAMIC(CThumbnailListCtrl,CListCtrl)
       BEGIN_MESSAGE_MAP(CThumbnailListCtrl, CListCtrl)
    //{{AFX_MSG_MAP(CThumbnailListCtrl)
             ...
    ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnGetInfoTip)
             ...
    //}}AFX_MSG_MAP
       END_MESSAGE_MAP()3) 最后添加你的函数体:
    void CThumbnailListCtrl::OnGetInfoTip(NMHDR* pNMHDR, LRESULT* pResult) 
    {
    static TCHAR szTip[255] = {0};
    LPNMLVGETINFOTIP pGetInfoTip = (LPNMLVGETINFOTIP)pNMHDR; if(pGetInfoTip->dwFlags != 0)
    {
    CString strTip = MakeTooltip((PLVITEM_EXINFO)GetItemData(pGetInfoTip->iItem));
    strcpy(szTip, strTip); pGetInfoTip->cchTextMax = 255;
    pGetInfoTip->pszText = szTip;
    }
    pResult = 0;
    }
      

  13.   

    抱歉上面写错了,在头文件里添加的原型是:
    afx_msg void OnGetInfoTip(NMHDR* pNMHDR, LRESULT* pResult);
      

  14.   

    再次感谢楼上老兄的关注了。有classwizard中,还是没找到那个消息。不过我按你的说法把该函数加到我文件中去了,但是没有反应了。我在void CThumbnailListCtrl::OnGetInfoTip(NMHDR* pNMHDR, LRESULT* pResult) 
    的函数体中用了个MessageBox也没有任何的输出,另外,那个
    MakeTooltip(IN PLVITEM_EXINFO pItemInfo)方法中,那个参数说类型不认识。我测试的时候随便用了一个字符测的,鼠标在图标上移动的时候是没有反应的。不知道是哪里设置的不对了?
      

  15.   

    首先请看MSDN中的解释:
    LVN_GETINFOTIP
    Sent by a large icon view list-view control that has the LVS_EX_INFOTIP extended style. This notification is sent when the list-view control is requesting additional text information to be displayed in a ToolTip. It is sent in the form of a WM_NOTIFY message. LVN_GETINFOTIP
        pGetInfoTip = (LPNMLVGETINFOTIP)lParam;Parameters
    pGetInfoTip 
    Address of an NMLVGETINFOTIP structure that contains information about this notification. 
    Return Values
    The return value for this notification is not used. Res
    This notification is only sent by list-view controls that have the LVS_EX_INFOTIP extended style. The LVN_GETINFOTIP notification is sent for sub-items while in report mode only when the LVS_EX_FULLROWSELECT extended style is in use. Requirements 
      Version 4.71 and later of Comctl32.dll  Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 4.0 or later). 
      Windows 95/98/Me: Requires Windows 98 (or Windows 95 with Internet Explorer 4.0 or later). 
      Header: Declared in commctrl.h.
      

  16.   

    创建列表类的时候必须指定LVS_EX_INFOTIP风格。
      

  17.   

    LVITEM_EXINFO是我自己定义的结构体,你照搬过去当然说类型未定义了。
      

  18.   

    非常感谢 codewarrior(会思考的草) ( ) 信誉:131 终于可以有提示信息出来了,而且还支持 "\n\r"来换行的,两个问题都解决了再请弱弱问下小问题:那个弹出来的ToolTip提示框能不能设置它消失的时间?或者鼠标不动的时候它就一直显示在那里不消失,等鼠标移走再消失了,现在在我的应用中,弹出来的信息比较多,要看比较久,可是那个toolTip两三秒就自动消失了?该如何改了?
    再次感谢!
      

  19.   

    过两三秒后你发送一个其他的消息给列表窗口不就可以让Tooltip消失了么。