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

Jack jckj33 at gmail.com
Tue Mar 16 18:32:37 UTC 2021


On Tuesday, 16 March 2021 at 17:26:01 UTC, Vinod K Chandran wrote:
> 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 ?

I'm afraid you have to do everything yourself, including draw the 
text and call SetTextColor() on the associated HDC (that you have 
used in the DrawText() for exe)


More information about the Digitalmars-d-learn mailing list