CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 58
  1. #16
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: [win32] - avoid flicker and do a correct redraw

    Quote Originally Posted by Cambalinho View Post
    why isn't transparent?
    Who knows? You are expected to erase or not to erase. And return non-zero in first case, and 0 in the second case. You want Windows to erase for you, you just return 0, and not fidgeting with DefWindowProc. You want to call DefWindowProc yourself, you are to return what it returns. You do nothing similar, but something chaotic.
    Best regards,
    Igor

  2. #17
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - avoid flicker and do a correct redraw

    Quote Originally Posted by Igor Vartanov View Post
    Who knows? You are expected to erase or not to erase. And return non-zero in first case, and 0 in the second case. You want Windows to erase for you, you just return 0, and not fidgeting with DefWindowProc. You want to call DefWindowProc yourself, you are to return what it returns. You do nothing similar, but something chaotic.
    i'm confused

  3. #18
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: [win32] - avoid flicker and do a correct redraw

    If you want the default window erase process then you don't process WM_ERASEBKGND and just let DefWindowProc() do its thing. This assumes that the hbrBackground member of the WNDCLASS structure is defined and non-null.

    If you want to yourself process the background within WM_ERASEBKGND, then process the background as required within WM_ERASEBKGND and return a non-zero value.

    If you want to yourself process the background in WM_PAINT, then within WM_ERASEBKGND just return 0. Within the PAINTSTRUCT struct passed to WM_PAINT then the fErase member will be TRUE.
    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)

  4. #19
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - avoid flicker and do a correct redraw

    Quote Originally Posted by 2kaud View Post
    If you want the default window erase process then you don't process WM_ERASEBKGND and just let DefWindowProc() do its thing. This assumes that the hbrBackground member of the WNDCLASS structure is defined and non-null.

    If you want to yourself process the background within WM_ERASEBKGND, then process the background as required within WM_ERASEBKGND and return a non-zero value.

    If you want to yourself process the background in WM_PAINT, then within WM_ERASEBKGND just return 0. Within the PAINTSTRUCT struct passed to WM_PAINT then the fErase member will be TRUE.
    i need the control been complety clear and then:
    - if is transparent, don't show the brush color;
    - if isn't transparent, draw the brush color.

  5. #20
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: [win32] - avoid flicker and do a correct redraw

    Quote Originally Posted by Cambalinho View Post
    i'm doing it:
    Code:
    case WM_ERASEBKGND: 
                {
                    if(inst->blnTransparent==true)
                    {
                        SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND,(LONG_PTR)GetStockObject(NULL_BRUSH));
                    }
                    else
                    {
                        SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND,(LONG_PTR)CreateSolidBrush(inst->clrBackColor));
                    }
                    DefWindowProc(hwnd, msg, wParam, lParam);
                }
                break;
    but i'm doing 1 error. why isn't transparent?
    You are creating a new solid brush every time blnTransparent is not true but are not deleting it - so you have a resource leak.
    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)

  6. #21
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - avoid flicker and do a correct redraw

    Quote Originally Posted by 2kaud View Post
    You are creating a new solid brush every time blnTransparent is not true but are not deleting it - so you have a resource leak.
    that's true:
    Code:
    case WM_ERASEBKGND:
                {
                    HBRUSH bkBrush;
                    if(inst->blnTransparent==true)
                    {
                        bkBrush=(HBRUSH)GetStockObject(NULL_BRUSH);
                        SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND,NULL);
                    }
                    else
                    {
                        bkBrush=CreateSolidBrush(inst->clrBackColor);
                        SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND,(LONG_PTR)bkBrush);
                    }
                    DeleteBrush(bkBrush);
                    DefWindowProc(hwnd, msg, wParam, lParam);
                }
                break;
    but why the 1st brush isn't transparent?
    (i must clear the control and show a transparent brush)

  7. #22
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: [win32] - avoid flicker and do a correct redraw

    if is transparent, don't show the brush color;
    Then don't erase the background. You can't erase the background to transparent - nor set a solid brush as transparent. What have you got set as the background?
    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)

  8. #23
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - avoid flicker and do a correct redraw

    Quote Originally Posted by 2kaud View Post
    Then don't erase the background. You can't erase the background to transparent - nor set a solid brush as transparent. What have you got set as the background?
    in these case i'm doing wrong
    why WS_CLIPCHILDREN style on parent window(is what avoid the flicker), don't let the child control been clear?

  9. #24
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: [win32] - avoid flicker and do a correct redraw

    Unless you are using custom child controls, the extended windows style WS_EX_TRANSPARENT should deal with siblings standard controls. In WM_PAINT, SetBkMode() is used to set transparency for text, hatched brushes and pen styles that are not solid lines.

    Transparency just means that the background shows through rather than being the usual opaque. So what background do you want?
    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)

  10. #25
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - avoid flicker and do a correct redraw

    Quote Originally Posted by 2kaud View Post
    Unless you are using custom child controls, the extended windows style WS_EX_TRANSPARENT should deal with siblings standard controls. In WM_PAINT, SetBkMode() is used to set transparency for text, hatched brushes and pen styles that are not solid lines.

    Transparency just means that the background shows through rather than being the usual opaque. So what background do you want?
    depending the blnTransparent been true or false, i need show it transparent or with a brush with clrBackcolor(respectible)

  11. #26
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: [win32] - avoid flicker and do a correct redraw

    You can't show a background as 'transparent'. You either set a background or you leave the existing background. Transparency is simply setting a main background then first painting the window siblings (without changing the background) then that window (without changing the background). The window appears transparent because the bits of underlying sibling windows have already been painted.
    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)

  12. #27
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - avoid flicker and do a correct redraw

    Quote Originally Posted by 2kaud View Post
    You can't show a background as 'transparent'. You either set a background or you leave the existing background. Transparency is simply setting a main background then first painting the window siblings (without changing the background) then that window (without changing the background). The window appears transparent because the bits of underlying sibling windows have already been painted.
    i can make it transparent, but without the WS_CLIPCHILDREN. without it, i have flickers

  13. #28
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: [win32] - avoid flicker and do a correct redraw

    resolving flickering
    and transparency are totally unrelated issues.

    if you want to solve flickering
    - disable the WM_ERASEBKGND (check, you're doing this)
    - in WM_PAINT, draw both the background and the foreground in such a way that you never erase what was there before. This is typically, but not necessarily achieved by painting background and foreground to a bitmap, and then blitting the resultant bitmap as a single operation to the screen DC.
    But there are... MANY... MANY... other ways to achieve the desired effect by other means, all depending on what exactly you are painting on top of what.

  14. #29
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: [win32] - avoid flicker and do a correct redraw

    Quote Originally Posted by Cambalinho View Post
    i can make it transparent, but without the WS_CLIPCHILDREN. without it, i have flickers
    WS_CLIPCHILDREN excludes the area occupied by child windows when drawing occurs within the parent window. As you have discovered - and we all now know - this has an impact upon transparency using WS_EX_TRANSPARENT. Oh the joys of Windows APIs!

    Back to the drawing board!
    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)

  15. #30
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - avoid flicker and do a correct redraw

    let me ask 1 thing: using the WS_CLIPCHILDREN, why the control ins't clean before use the WM_PAINT?(i'm testing these too)

Page 2 of 4 FirstFirst 1234 LastLast

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