CListCtrl实现tooltip信息提示

CListCtrl实现tooltip信息提示当鼠标移动到CListCtrl的某一行时,提示一些信息。具体实现方法:1、头文件定义CToolTipCtrlm_tooltip;2、在OnInitDialog()中进行初始化EnableToolTips(TRUE);   m_tooltip.Create(this);   m_tooltip.SetMaxTipWidth(500);   m_tooltip.Act…

大家好,又见面了,我是你们的朋友全栈君。

当鼠标移动到CListCtrl的某一行时,提示一些信息。

具体实现方法:

1、头文件定义

CToolTipCtrl m_tooltip;

2、在OnInitDialog()中进行初始化

EnableToolTips(TRUE);
    m_tooltip.Create(this);
    m_tooltip.SetMaxTipWidth(500);
    m_tooltip.Activate(TRUE);

    LONG lStyle;
    lStyle  = GetWindowLong(m_listCourse.m_hWnd, GWL_STYLE);//获取当前窗口style
    lStyle  &= ~LVS_TYPEMASK; //清除显示方式位
    lStyle |= LVS_REPORT; //设置style
    SetWindowLong(m_listCourse.m_hWnd, GWL_STYLE, lStyle);//设置style
    DWORD dwStyle = m_listCourse.GetExtendedStyle();
    dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与report风格的listctrl)
    dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与report风格的listctrl)
    dwStyle |= LVS_EX_CHECKBOXES;//item前生成checkbox控件
    m_listCourse.SetExtendedStyle(dwStyle); //设置扩展风格

 

CRect rectangle;
        m_listCourse.GetWindowRect(&rectangle);
        int nWidth  =rectangle.Width();

        m_listCourse.InsertColumn( 0, _T(“”), LVCFMT_CENTER,-1, -1);
        m_listCourse.InsertColumn( 1, _T(“序号”), LVCFMT_CENTER,rectangle.Width()*0.1 , -1);
        m_listCourse.InsertColumn( 2, _T(“添加时间”), LVCFMT_CENTER,rectangle.Width()*0.2 , -1);
        m_listCourse.InsertColumn( 3, _T(“课程名称”), LVCFMT_CENTER,rectangle.Width()*0.25 , -1);
        m_listCourse.InsertColumn( 4, _T(“课程难度”), LVCFMT_CENTER,rectangle.Width()*0.2 , -1);
        m_listCourse.InsertColumn( 5, _T(“课程时长”), LVCFMT_CENTER,rectangle.Width()*0.25 , -1);
        m_listCourse.DeleteColumn(0);

3.添加数据

for(int j=0;j<10;j++)

{

m_listCourse.InsertItem(j,””);

           strValue.Format(“%d”,j);
            m_listCourse.SetItemText(j,0,strValue);
           strValue.Format(“%d”,j)+1;
            m_listCourse.SetItemText(j,1,strValue);
          strValue.Format(“%d”,j+2);
            m_listCourse.SetItemText(j,2,strValue);
           strValue.Format(“%d”,j+3);
            m_listCourse.SetItemText(j,3,strValue);
           strValue.Format(“%d”,j+4);
            m_listCourse.SetItemText(j,4,strValue);

            strValue.Format(“提示信息内容%d”,j+5);
            CRect rect;
            m_listCourse.GetItemRect(j, &rect, LVIR_BOUNDS);
            //为第j行添加提示文本内容
            m_tooltip.AddTool(&m_listCourse,”故障设置:\r\n”+strValue, &rect, j + 1);

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/152508.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号