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

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

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能