[win32] - creating controls using class's - Page 11
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

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

  1. #151
    Join Date
    Apr 2009
    Posts
    626

    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
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    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
    626

    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
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,328

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  5. #155
    Join Date
    Apr 2009
    Posts
    626

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center