简体   繁体   中英

Change the text color of button

Well i able to change the color of Button create using Createwindow control using the Custom draw.But button color is still black i want to change this color.Is there any property in CustomDraw to change the Text color. Here is my code for background color change

case WM_NOTIFY:
    switch (((LPNMHDR)lParam) -> code)
    {
        case NM_CUSTOMDRAW:
            if (((LPNMHDR)lParam) -> idFrom == 10002)
            {
                LPNMCUSTOMDRAW lpnmCD = (LPNMCUSTOMDRAW)lParam;
                switch (lpnmCD -> dwDrawStage)
                {
                    case CDDS_PREPAINT:
                        SetDCBrushColor(lpnmCD -> hdc, RGB(0, 255, 0));
                        SetDCPenColor(lpnmCD -> hdc, RGB(0, 255, 0));
                        SelectObject(lpnmCD -> hdc, GetStockObject(DC_BRUSH));
                        SelectObject(lpnmCD -> hdc, GetStockObject(DC_PEN));
                        RoundRect(lpnmCD -> hdc, lpnmCD -> rc.left + 3, lpnmCD -> rc.top + 3,
                        lpnmCD -> rc.right - 3, lpnmCD -> rc.bottom - 3, 5, 5);
                        return TRUE;
                }
            }
        }
    }

I think you'll have to draw the text yourself. Add that code after RoundRect

// Unicode, adapt for ansi
// -----------------------
wchar_t szBtnText[ 32 ] = { 0 };
GetWindowText( ((LPNMHDR)lParam) -> hwndFrom, szBtnText, sizeof(szBtnText) / sizeof(wchar_t) ); 
SetTextColor(lpnmCD -> hdc, RGB(255, 0, 0));
SetBkMode(lpnmCD -> hdc, TRANSPARENT);
DrawText(lpnmCD -> hdc, szBtnText, wcslen(pszBtnText), &lpnmCD -> rc,
         DT_CENTER | DT_SINGLELINE | DT_VCENTER);
return CDRF_SKIPDEFAULT;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM