0

I have created an Owner-Drawn button . I use the WM_CTLCOLORBTN message in order to paint it :

//get the text of the button wchar_t buttonText[20]; int textLength = SendMessage((HWND)lParam,WM_GETTEXT,20,(LPARAM)buttonText); Font FootlightMTLight(L"Footlight MT Light",20,0,false,false,false,L"Black"); SelectObject((HDC)wParam,FootlightMTLight.getWindowHandle()); TextOut((HDC)wParam,30,15,buttonText,textLength); SetTextColor((HDC)wParam, RGB(0,0,0)); SetBkColor((HDC)wParam, RGB(229,255,229)); PatBlt((HDC)wParam,0,0,1,50,BLACKNESS); //x,y,width,height PatBlt((HDC)wParam,269/2-1,0,1,50,BLACKNESS); PatBlt((HDC)wParam,0,49,269/2,1,BLACKNESS); PatBlt((HDC)wParam,0,0,269/2,1,BLACKNESS); static HBRUSH handleToButtonBrush = CreateSolidBrush(RGB(229,255,229)); return (INT_PTR)handleToButtonBrush; 

"Font" is an object I created (I wrapped HFONT handle and CreateFont function with class etc. getWindowHandle() basically returns HFONT ).

the button renders nicely , yet pressing on it make the text-background turn white. I search the net for a reason and a solution yet I didn't find a concrete one. thanks in advanced!

1 Answer 1

2

You need to call those lines before the actual text drawing occurs

SetTextColor((HDC)wParam, RGB(0,0,0)); SetBkColor((HDC)wParam, RGB(229,255,229)); TextOut((HDC)wParam,30,15,buttonText,textLength); 
Sign up to request clarification or add additional context in comments.

1 Comment

Or SetBkMode to transparent so you don't have to remember what the background color is.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.