How to change button text color in NM_CUSTOMDRAW (Win32 API question)

Vinod K Chandran kcvinu82 at gmail.com
Tue Mar 16 17:26:01 UTC 2021


Hi all,
I am creating a Button class with Win32 API functions. So far so 
good. I am using NM_CUSTOMDRAW message to change the back color 
of my buttons. It's really easy to change the back color in this 
way. But I can't change the text color of my button. This is my 
pseudo code.
```
uint setBtnBackColor( LPNMCUSTOMDRAW  lp) {

     SetTextColor(lp.hdc, RGB(102, 255, 51) )    // Not working

     if lp.uItemState & CDIS_SELECTED { //----------- btn clicked
         // Change back color using SelectObject & FillRect
         // Its Working. No probs.
         }
     elseif lp.uItemState & CDIS_HOT { //------------Mouse over
         // Change back color using SelectObject & FillRect
         // Its Working. No probs.
         }
     else { // ---------Default state of button
          // Change back color using SelectObject & FillRect
         // Its Working. No probs.
         }
     return CDRF_SKIPDEFAULT
}
```
What is wrong in my approach ?


More information about the Digitalmars-d-learn mailing list