Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Painting text problem

Status
Not open for further replies.

makaveliuk

Programmer
Dec 1, 2003
46
GB
I am trying to paint some text in a window and have it change colour when the mouse is over it, I am using the code:

case WM_PAINT:
{
HFONT pOldFont;
char *szBuffer;
CRect rcClient;
PAINTSTRUCT ps;
COLORREF col;
HFONT hNewFont;
BITMAP bm;

HDC hDC = BeginPaint(data->m_hWnd, &ps);
HDC hdcMem = CreateCompatibleDC(hDC);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem,m_biBackground);
GetObject((HBITMAP)>m_biBackground, sizeof(bm), &bm);

BitBlt(hDC, 0, 0, data->m_nWidth, data->m_nHeight, hdcMem, 0, 0, SRCCOPY);

SetBkMode(hDC, TRANSPARENT);

rcClient.DeflateRect(10,20,10,20);

if (m_bMouseIsOver)
{
col = RGB(GetRValue(m_crSelected),GetGValue(data->m_crSelected),GetBValue(data->m_crSelected));
hNewFont = (HFONT)data->m_hSelectedFont;
}
else
{
col = RGB(GetRValue(data->m_crNormal),GetGValue(data->m_crNormal),GetBValue(data->m_crNormal));
hNewFont = (HFONT)data->m_hNormalFont;
}

szBuffer=new char[strlen(data->m_strCaption)+10];
strcpy(szBuffer,m_strCaption);

pOldFont=(HFONT)SelectObject(hDC, &hNewFont);
SetTextColor(hDC, col);

DrawText(hDC, szBuffer,-1,data->m_rcText,DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_END_ELLIPSIS);

delete[] szBuffer;
SelectObject(hDC, pOldFont);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);

EndPaint(data->m_hWnd, &ps);

return 0;
}

I can see that it is selecting the correct colour because the variable 'col' contains the right value at the right time.

But the text displayed is always the first colour, I must be missing something simple, any ideas what???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top