如何在 Windows 列表视图控件中自定义绘制所选项目行

发布于 2024-10-10 04:52:15 字数 137 浏览 0 评论 0原文

我已经创建了 NM_CUSTOMDRAW 消息处理程序来自定义绘制列表视图控件子项。差不多就OK了。但是,我无法自定义绘制选定的项目。我的自定义设置始终被忽略,并绘制蓝色 bkColor 上的默认白色文本。

我可以有机会自定义绘制选定的项目吗?

I have created NM_CUSTOMDRAW message handler to custom draw List-View control subitems. It is almost OK. However, I can't custom draw item which is selected. My custom settings are always ignored and default white text over blue bkColor is drawn.

Can I have any chance to custom draw selected items?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里寻她 2024-10-17 04:52:15

我已成功编写代码以在 OnCustomDraw() 处理程序的 CDDS_ITEMPREPAINT 绘制阶段中自定义绘制所选项目,并在绘制所选项目后返回 CDRF_SKIPDEFAULT:

int subitemCount = GetHeaderCtrl().GetItemCount();
CRect itemRect;
for (int i = 0; i < subitemCount; i++) // Draw individual subitem
{
    if (i == 0)
    {
        // My own function
        // calculate correct rect for first(index=0) subitem
        CalculateItemRect(nIndex, itemRect);
    }
    else if (!GetSubItemRect(nIndex, i, LVIR_BOUNDS, itemRect))
    {
        return;
    }

    // Adjust text rect to avoid overlapping with vertical grid line
    itemRect.left += 6;
    dc.DrawText(GetItemText(nIndex, i), itemRect, DT_LEFT | DT_NOCLIP | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
}

到目前为止,此代码工作得很好。热烈欢迎任何改进建议。

I have successfully written code to custom draw selected item in CDDS_ITEMPREPAINT draw stage of OnCustomDraw() handler, and return CDRF_SKIPDEFAULT after selected item drawn:

int subitemCount = GetHeaderCtrl().GetItemCount();
CRect itemRect;
for (int i = 0; i < subitemCount; i++) // Draw individual subitem
{
    if (i == 0)
    {
        // My own function
        // calculate correct rect for first(index=0) subitem
        CalculateItemRect(nIndex, itemRect);
    }
    else if (!GetSubItemRect(nIndex, i, LVIR_BOUNDS, itemRect))
    {
        return;
    }

    // Adjust text rect to avoid overlapping with vertical grid line
    itemRect.left += 6;
    dc.DrawText(GetItemText(nIndex, i), itemRect, DT_LEFT | DT_NOCLIP | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
}

This code works so far so good. Any improvement suggestion is warmly welcome.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文