[winAPI] Zmiana koloru tekstu na przycisku
Ostatnio zmodyfikowano 2016-05-19 14:19
programirer Temat założony przez niniejszego użytkownika |
[winAPI] Zmiana koloru tekstu na przycisku » 2016-05-18 11:12:38 Witam, Jest możliwość, aby dynamicznie podczas trwania programu zmienić kolor tekstu na danym przycisku? Znalazłem w internecie ten kod, jednak działa tylko na początku (potem koloru nie da się zmienić): case WM_NOTIFY: { LPNMHDR nmhdr = reinterpret_cast < LPNMHDR >( lParam ); if( nmhdr->idFrom == ID_CUSTBUTTON && nmhdr->code == NM_CUSTOMDRAW ) { LPNMCUSTOMDRAW custDraw = reinterpret_cast < LPNMCUSTOMDRAW >( nmhdr ); if( custDraw->dwDrawStage == CDDS_PREPAINT ) { const int textLength =::GetWindowTextLength( custDraw->hdr.hwndFrom ); if( textLength > 0 ) { TCHAR * buttonText = new TCHAR[ textLength + 1 ]; SIZE dimensions = { 0 }; ::GetWindowText( custDraw->hdr.hwndFrom, buttonText, textLength + 1 ); ::GetTextExtentPoint32( custDraw->hdc, buttonText, textLength, & dimensions ); const int xPos =( custDraw->rc.right - dimensions.cx ) / 2; const int yPos =( custDraw->rc.bottom - dimensions.cy ) / 2; ::SetBkMode( custDraw->hdc, TRANSPARENT ); ::SetTextColor( custDraw->hdc, RGB( 255, 0, 0 ); ); ::TextOut( custDraw->hdc, xPos, yPos, buttonText, textLength ); delete[] buttonText; return CDRF_SKIPDEFAULT; } } return CDRF_DODEFAULT; } } break; Z góry dziękuję za odpowiedź. Pozdrawiam |
|
Monika90 |
» 2016-05-18 22:42:36 ::SetTextColor( custDraw->hdc, RGB( 255, 0, 0 ); );
W tym fragmencie musisz RGB(255, 0, 0) zastąpić zmienną typu COLORREF, której wcześniej przypisałeś pożądany kolor. Po każdej zmianie wartości tej zmiennej trzeba odświeżyć przycisk, np. funkcją InvalidateRect(uchwyt_przycisku, NULL, TRUE); |
|
programirer Temat założony przez niniejszego użytkownika |
» 2016-05-19 14:19:35 Dziękuję, zamykam. |
|
« 1 » |