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;
    
       }
    }
    

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

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?