[win32] - avoid flicker and do a correct redraw
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

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

  1. #1
    Join Date
    Apr 2009
    Posts
    719

    [win32] - avoid flicker and do a correct redraw

    for resize or readraw the control i do:
    Code:
    SetWindowPos(hwnd, 0, 0, 0, 0, 0,
                SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
                SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
    but theses flags: SWP_DRAWFRAME and SWP_FRAMECHANGED give me the flicker.
    if i have the control transparent and don't use these code, the control isn't redraw, when i change the text
    so how can redraw the control without flicker? or 'clean' correctly the control, before give it the next text?

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,049

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

    Quote Originally Posted by Cambalinho View Post
    for resize or readraw the control
    To redraw a control you need InvalidateRect.

    Besides, resizing hardly gets along with zero values and SWP_NOSIZE flag. There's definitely must be something about the resizing that I don't know or understand.

    As for the flicker, you need to read more about WM_ERASEBKGND
    Best regards,
    Igor

  3. #3
    Join Date
    Apr 2009
    Posts
    719

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

    Quote Originally Posted by Igor Vartanov View Post
    To redraw a control you need InvalidateRect.

    Besides, resizing hardly gets along with zero values and SWP_NOSIZE flag. There's definitely must be something about the resizing that I don't know or understand.

    As for the flicker, you need to read more about WM_ERASEBKGND
    "The DefWindowProc function erases the background by using the class background brush specified by the hbrBackground member of the WNDCLASS structure. If hbrBackground is NULL, the application should process the WM_ERASEBKGND message and erase the background.

    An application should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If the application returns zero, the window will remain marked for erasing. (Typically, this indicates that the fErase member of the PAINTSTRUCT structure will be TRUE.) "

    sorry... can you explain better?

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,049

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

    What part looks unclear to you? You need to get to a habit of reading MSDN on every single entity you meet in the text you are to understand. This literally means that to understand this fragment you need to have a background about DefWindowProc, WNDCLASS structure and related, PAINTSTRUCT and related, etc.

    So please don't wait until somebody digests everything for you. You have to learn to survive on your own having only a few hints from the community about possible directions.
    Best regards,
    Igor

  5. #5
    Join Date
    Apr 2009
    Posts
    719

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

    Quote Originally Posted by Igor Vartanov View Post
    What part looks unclear to you? You need to get to a habit of reading MSDN on every single entity you meet in the text you are to understand. This literally means that to understand this fragment you need to have a background about DefWindowProc, WNDCLASS structure and related, PAINTSTRUCT and related, etc.

    So please don't wait until somebody digests everything for you. You have to learn to survive on your own having only a few hints from the community about possible directions.
    "An application should return nonzero if it erases the background; otherwise, it should return zero."
    so:
    Code:
    case WM_ERASEBKGND:
            return true;//or even '1'... but must be diferent than '0' or don't clean it.
    what make me confuse is: if we are talking about controls, why the MSDN speaks about WM_PAINT message?
    (the WM_PAINT is for rebuild, for example, a new control and show images and work with HDC)

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,049

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

    WM_PAINT is sent to any window, including controls, which area became invalid.

    It might be invalid due to various reasons. For example, parent window was moved the way that the control or some part of it was displaced off the screen, and moved back to screen again. This way the window, or invalid part of it needs to be re-painted, and that's why WM_PAINT is sent.

    Or in case the window internally changes its state, e.g. the text it renders on screen, to be re-painted it declares itself invalid by calling InvalidateRect. This will again result in sending WM_PAINT to the window to be re-painted with the updated content.
    Best regards,
    Igor

  7. #7
    Join Date
    Apr 2009
    Posts
    719

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

    Quote Originally Posted by Igor Vartanov View Post
    WM_PAINT is sent to any window, including controls, which area became invalid.

    It might be invalid due to various reasons. For example, parent window was moved the way that the control or some part of it was displaced off the screen, and moved back to screen again. This way the window, or invalid part of it needs to be re-painted, and that's why WM_PAINT is sent.

    Or in case the window internally changes its state, e.g. the text it renders on screen, to be re-painted it declares itself invalid by calling InvalidateRect. This will again result in sending WM_PAINT to the window to be re-painted with the updated content.
    thanks for all

  8. #8
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,056

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

    Quote Originally Posted by Igor Vartanov View Post
    WM_PAINT is sent to any window
    Need to pick a nit here...

    WM_PAINT is never SENT to a window by Windows. (and you should never send it yourself either)

    The messagequeue has a flag that indicates that any part of the windows associated with said messagequeue have become invalidated and thus needs repainting.
    When you get messages from the queue, and the queue is empty) and the invalid flag is set, then GetMessage will return a WM_PAINT.

    This is why multiple invalidates only result in 1 WM_PAINT...
    ...and why WM_PAINT messages seem to be "pushed back" in the messagequeue and other messages get prioritized). If you invalidate a window and then send/post a message, you will first get the sent/posted message, then a WM_PAINT.

    There are other messages that equally don't actually get queued in the message queue but rather set a flag with the flag generating a returned message.
    Such as WM_TIMER, this works similarly, because if you don't get messages for X time (bad idea, but hey...), you won't suddenly get a flood of WM_TIMER messages you haven't been processing during that time).
    It's different to WM_PAINT in that a message is generated when you do GetMessage() and the timer flag is set rather than when the queue is empty. THere's several flags, but the point at which they generate a message is different.
    Last edited by OReubens; February 7th, 2014 at 08:16 AM.

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,049

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

    Quote Originally Posted by OReubens View Post
    WM_PAINT is never SENT to a window by Windows.
    WM_PAINT message

    The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function.
    The reality is a little bit trickier.
    Best regards,
    Igor

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center