yumorende 2014-09-09 03:18 采纳率: 0%
浏览 1032

NM_CUSTROMDRAW消息用于TOOLBAR如何设置高亮时按钮文本

在TOOLBAR中设置 NMTBCUSTOMDRAW结构体,以改变文本的颜色, 我已经成功改变TOOLBAR文本颜色, 但是 如何设置高亮文本 那就一头雾水 了

void MyToolBar::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult) //on draw item
{

   NMTBCUSTOMDRAW* pLVCD = reinterpret_cast<NMTBCUSTOMDRAW*> (pNMHDR);

   DWORD DW = *pResult;
   *pResult = 0;    // First thing - check the draw stage(阶段). If it's the control's prepaint(preprint)

    COLORREF crText; 
    COLORREF crHighText;
   if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )           //before a painting cycle begin 
   {
       *pResult = CDRF_NOTIFYITEMDRAW;                    //自己完成绘制
   }
   else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )          //before an item is draw
   {
       // This is the prepaint stage for an item. Here's where we set the
       // item's text color. Our return value will tell Windows to draw the
       // item itself, but it will use the new color we set here.
       // We'll cycle the colors through red, green, and light blue.

        crText = RGB(255,0,0);
        crHighText = RGB(0, 255, 0);
        pLVCD->clrText = crText;        // Tell Windows to paint the control itself.
        pLVCD->clrTextHighlight = crHighText;
        *pResult = CDRF_NEWFONT;

   }

}

如上, 我设置了,但是鼠标移动到TOOLBAR控件按钮上时, 文本颜色没有变化啊~

  • 写回答

1条回答 默认 最新

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-03-18 21:22
    关注

    该回答引用ChatGPT

    NM_CUSTOMDRAW 消息用于自定义绘制控件的外观。对于工具栏控件,为了改变高亮时按钮文本的颜色,你需要在 CDDS_ITEMPREPAINT 阶段的处理过程中,设置 clrHighlightHotTrack 属性为你想要的高亮文本颜色即可。修改后的代码如下:

    void MyToolBar::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult) //on draw item
    {
    
       NMTBCUSTOMDRAW* pLVCD = reinterpret_cast<NMTBCUSTOMDRAW*> (pNMHDR);
    
       DWORD DW = *pResult;
       *pResult = 0;    // First thing - check the draw stage(阶段). If it's the control's prepaint(preprint)
    
        COLORREF crText; 
        COLORREF crHighText;
       if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )           //before a painting cycle begin 
       {
           *pResult = CDRF_NOTIFYITEMDRAW;                    //自己完成绘制
       }
       else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )          //before an item is draw
       {
           // This is the prepaint stage for an item. Here's where we set the
           // item's text color. Our return value will tell Windows to draw the
           // item itself, but it will use the new color we set here.
           // We'll cycle the colors through red, green, and light blue.
    
            crText = RGB(255,0,0);
            crHighText = RGB(0, 255, 0);
            pLVCD->clrText = crText;       
            pLVCD->clrTextHighlight = crHighText;
            pLVCD->clrHighlightHotTrack = crHighText; // 设置高亮时的文本颜色
            *pResult = CDRF_NEWFONT;
    
       }
    }
    

    这样,当鼠标移动到按钮上时,文本颜色就会变成你所设置的高亮文本颜色。

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧