CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 11 of 11 FirstFirst ... 891011
Results 151 to 155 of 155
  1. #151
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - creating controls using class's

    Quote Originally Posted by 2kaud View Post
    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

  2. #152
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: [win32] - creating controls using class's

    Quote Originally Posted by Cambalinho View Post
    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

  3. #153
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - creating controls using class's

    Quote Originally Posted by VictorN View Post
    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

  4. #154
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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)

  5. #155
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - creating controls using class's

    Quote Originally Posted by 2kaud View Post
    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

Page 11 of 11 FirstFirst ... 891011

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured