Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Invalid region - how does a program know about it?

Sorry to flood this board with naive questions. Windows is said to internally keep a "paint informatioin structure" for each window. the structure contains the smallest rectangle encompasses the invalid region. But the WM_PAINT message itself doesn't carry this structure, then in general how does the handler know about the invalid region?

I know that the BeginPaint function will properly set the clipping region for the device context (and even "materialize" the "paint informatioin structure" into a "real" PAINTSTRUCT). But some other functions, say GetDC, will not do this. Does that mean BeginPaint is more efficient as it won't paint to unnecessary region?

Thanks for help.


Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Sorry to flood this board with naive questions. Windows is said to internally keep a "paint informatioin structure" for each window. the structure contains the smallest rectangle encompasses the invalid region. But the WM_PAINT message itself doesn't carry this structure, then in general how does the handler know about the invalid region?
    :
    : I know that the BeginPaint function will properly set the clipping region for the device context (and even "materialize" the "paint informatioin structure" into a "real" PAINTSTRUCT). But some other functions, say GetDC, will not do this. Does that mean BeginPaint is more efficient as it won't paint to unnecessary region?
    :
    : Thanks for help.
    :
    :
    :
    [blue]No doubt, the invalid region is attached to HWND. You call:

    BeginPaint (hWnd, &ps);

    It is like saying: "use 'hWnd' to fill out 'ps' structure".

    Also, invalid region is set with call to:

    InvalidateRect (hWnd, &rect, TRUE);

    Which is: "take the contents of 'rect' and apply it to 'hWnd'". The WM_PAINT will be posted to the message queue for that 'hWnd'.

    Actually, you asked a good question. Sometimes, you can see code which paints the same thing twice: in response to WM_PAINT and using GetDC() when document is modified.

    The correct way is - when your document gets modified you refresh the invalid area with 'InvalidateRect()' and immediately call 'UpdateWindow()' to force WM_PAINT right away. This way your code draws ONLY in response to WM_PAINT and not twice as you see in non-professional code. It is easier to maintain[/blue]
  • galaxy3001galaxy3001 Member Posts: 11
    Maybe I didn't state my question clearly, the InvalidateRect function _adds_ a KNOWN region to the invalidate region of a window. What I was asking is how does a program know about the CURRENT invalid region of a window. The operating system keeps track of the invalid region of each window, but many GDI functions, say GetDC, seem never get this information. If you obtained a hdc using GetDC, but still want the painting to be done only for the invalid region, what can you do?

    : [blue]No doubt, the invalid region is attached to HWND. You call:
    :
    : BeginPaint (hWnd, &ps);
    :
    : It is like saying: "use 'hWnd' to fill out 'ps' structure".
    :
    : Also, invalid region is set with call to:
    :
    : InvalidateRect (hWnd, &rect, TRUE);
    :
    : Which is: "take the contents of 'rect' and apply it to 'hWnd'". The WM_PAINT will be posted to the message queue for that 'hWnd'.
    :
    : Actually, you asked a good question. Sometimes, you can see code which paints the same thing twice: in response to WM_PAINT and using GetDC() when document is modified.
    :
    : The correct way is - when your document gets modified you refresh the invalid area with 'InvalidateRect()' and immediately call 'UpdateWindow()' to force WM_PAINT right away. This way your code draws ONLY in response to WM_PAINT and not twice as you see in non-professional code. It is easier to maintain[/blue]
    :

  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    ____ ( http://forcoder.org ) free video tutorials and ebooks about < JavaScript C PL/SQL PHP Assembly Java Swift Visual Basic .NET Visual Basic Ruby C# Python Go Objective-C MATLAB Perl Scratch R Delphi C++ Erlang F# ML Julia D Logo VBScript Apex Lisp LabVIEW Prolog Transact-SQL Lua Alice FoxPro Kotlin Scala Ada Rust Hack Bash SAS Crystal Fortran Dart ABAP Clojure Scheme COBOL Awk /> ____________

Sign In or Register to comment.