Re: [win32] - creating controls using class's
Quote:
Originally Posted by
2kaud
SetTextColor, SetBkColor etc take as parameter 1 a hdc which is available as wParam, so there is no need to use GetDC(). Just use
Code:
SetTextColor((HDC)wParam, inst->clrTextColor);
etc...
Also note that every time you process this message, you are creating a new brush without deleting the old brush. When a brush is no longer being used it should be deleted using DeleteObject(). See
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
When this message is processed, is the value of inst->clrTextColor the value it is supposed to be? Have you checked with the debugger to make sure this value is right?
For my test program, the code
Code:
case WM_CTLCOLORSTATIC:
{
SetTextColor((HDC)wParam, RGB(200, 0, 0));
SetBkColor((HDC)wParam, RGB(0,200,0));
SetBkMode((HDC)wParam, TRANSPARENT);
inst->clrBackColor = (UINT)GetStockObject(GRAY_BRUSH);
return (LRESULT)inst->clrBackColor;
}
produces red text on a transparent background. If the SetBkMode statement is commented out, it produces red text on a green background.
but i'm trying change the control\window backcolor :(
Re: [win32] - creating controls using class's
Quote:
Originally Posted by
Cambalinho
but i'm trying change the control\window backcolor :(
No. You seem to let other people on this Forum to write/debug code for you!
Again: did you check the return values of the API functions you are using? Did you debug your code to be sure all variables in use contain the expected values?
Re: [win32] - creating controls using class's
Quote:
Originally Posted by
VictorN
No. You seem to let other people on this Forum to write/debug code for you!
Again: did you check the return values of the API functions you are using? Did you debug your code to be sure all variables in use contain the expected values?
you make me think.. after more tests and go back in these thread, i put it to work:
Code:
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, inst->clrTextColor);
SetBkMode(hdcStatic, TRANSPARENT);
SetBkColor(hdcStatic,inst->clrBackColor);
g_hbrBackground = CreateSolidBrush(inst->clrBackColor);
return (LONG)g_hbrBackground;
}
break;
anotherthing: i'm not using that 'if' for the mouse move message 'bug' and now isn't happen... better ;)
maybe now i can do the rest.
thanks for all to all
Re: [win32] - creating controls using class's
But you still have a resource leak problem as you are creating a new brush every time you process this message. When you create the brush, you should delete the previous one.
Re: [win32] - creating controls using class's
Quote:
Originally Posted by
2kaud
But you still have a resource leak problem as you are creating a new brush every time you process this message. When you create the brush, you should delete the previous one.
Code:
case WM_CTLCOLORSTATIC:
{
DeleteObject(g_hbrBackground);
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, inst->clrTextColor);
SetBkMode(hdcStatic, TRANSPARENT);
SetBkColor(hdcStatic,inst->clrBackColor);
g_hbrBackground = CreateSolidBrush(inst->clrBackColor);
return (LONG)g_hbrBackground;
}
break;
i think is these. thanks