Reputation: 16724
I need to change the font color and background color of a static control. That colors is set by handling the WM_CTLCOLORSTATIC
message:
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC) wParam;
SetTextColor(hdcStatic, RGB(fColor.R, fColor.G,fColor.B));
SetBkMode(hdcStatic, TRANSPARENT);
if(hBrush) DeleteObject(hBruash); // free previous brush
hBrush = CreateSolidBrush(RGB(bColor.R, bColor.G, bColor.B));
return (LRESULT) hBrush;
}
I'm calling InvalidateRect()
like this, from a button click:
case WM_COMMAND:
switch(LOWORD(wParam))
{
case BUTTONA_ID:
InvalidateRect(hLabel, NULL, TRUE);
break;
}
break;
It this the proper way to ask to the label to be redraw and change its font and background colors?
Upvotes: 0
Views: 269
Reputation: 3890
It this the proper way to ask to the label to be redraw and change its font and background colors?
Yes,a static control doesn't necessarily erase its background prior to drawing the text.
So you can force the control to be invalid, so that you can easily redraw the text without having to perform other additional calls.
More reference: CStatic does not invalidate every time its text is changed
Upvotes: 1