-
January 6th, 2014, 01:13 PM
#151
Re: [win32] - creating controls using class's
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
-
January 6th, 2014, 01:35 PM
#152
Re: [win32] - creating controls using class's
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?
Victor Nijegorodov
-
January 6th, 2014, 02:19 PM
#153
Re: [win32] - creating controls using class's
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
-
January 6th, 2014, 03:14 PM
#154
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 6th, 2014, 03:18 PM
#155
Re: [win32] - creating controls using class's
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|