[RESOLVED] Get the updated (changed/cleared) region of WM_PAINT-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] Get the updated (changed/cleared) region of WM_PAINT

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2015
    Posts
    48

    Resolved [RESOLVED] Get the updated (changed/cleared) region of WM_PAINT

    To make the problem clearly to see. Make a new project, create a button named Command1 and paste this code into the form:

    Code:
    Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
    
    Private Sub Command1_Click()
    Dim strText As String
    strText = "THIS IS A TEST STRING . THIS IS A TEST STRING. THIS IS A TEST STRING. THIS IS A TEST STRING"
    TextOut Me.hDC, 0, 0, strText, Len(strText)
    End Sub
    Press F5 to Run. Click on Command1, you will see the text appear on the form. Do not resize the form or move anything overlap it.
    Now, Drag the form to the right - outermost of the screen so a part of it become disappear (go outside the screen). And then, drag it back a bit to the left and look at the form, the text is also cleared at the part you've made it go outside.

    It's easy to redraw the text by put a full redraw code at WM_PAINT event like this:
    Code:
    Private Sub Form_Paint()
    Dim strText As String
    strText = "THIS IS A TEST STRING . THIS IS A TEST STRING. THIS IS A TEST STRING. THIS IS A TEST STRING"
    TextOut Me.hDC, 0, 0, strText, Len(strText)
    End Sub
    But in another case when i need to draw something heavily (like a full screen image). To improve the performance, i just want to redraw the cleared/changed part. So I try to get the changed region to redraw it only.

    I've tried GetUpdateRect at the Form_Paint event but it always return RECT(0,0,0,0). What is the correct way to get this region?
    Last edited by vietnamvodich; Apr 18th, 2017 at 10:42 AM.

  2. #2
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,454

    Re: Get the updated (changed/cleared) region of WM_PAINT

    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    Interesting... have you tried using AutoRedraw?
    Last edited by DEXWERX; Apr 18th, 2017 at 11:01 AM.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,415

    Re: Get the updated (changed/cleared) region of WM_PAINT

    If this is in reference to your previous thread, a more specific answer might apply; otherwise, ignore my reply as it specifically pertains to your other thread. In that other thread, you are creating a rect region to update. Since you know the boundaries of that rect, you can update the changed area with calls to: InvalidateRect/InvalidateRgn followed UpdateWindow. Or simply try RedrawWindow since it allows a rect/region to be passed in its call
    Last edited by LaVolpe; Apr 18th, 2017 at 10:56 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VB and DPI Tutorial} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2015
    Posts
    48

    Re: Get the updated (changed/cleared) region of WM_PAINT

    It's my mistake. Finally , it seems I need to subclass the form and using GetUpdateRect at WM_ERASEBKGND event instead of WM_PAINT event.

    Code:
    If uMsg = WM_ERASEBKGND Then
    Dim r As RECT
    Call GetUpdateRect(Form1.hwnd, r, 0)
    End If
    Problem solved, thank you all very much for reply on my thread!
    Last edited by vietnamvodich; Apr 18th, 2017 at 11:00 AM.

  5. #5
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    521

    Re: Get the updated (changed/cleared) region of WM_PAINT

    Quote Originally Posted by vietnamvodich View Post
    I've tried GetUpdateRect at the Form_Paint event but it always return RECT(0,0,0,0). What is the correct way to get this region?
    When you make the call to the API, Windows considers that the whole window is updated, VB already painted the region of the form that was previously hidden. It doesn't know that you wanted to paint there something else instead.

    PS: OK, I opened to answer before I could see that you already solved it.

  6. #6
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,454

    Re: [RESOLVED] Get the updated (changed/cleared) region of WM_PAINT

    If you're gonna go the subclassing route - why not just subclass WM_PAINT and paint the form yourself?

    BeginPaint returns the invalidated rect. VB just doesn't pass the rect to the Paint() Event.

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2015
    Posts
    48

    Re: [RESOLVED] Get the updated (changed/cleared) region of WM_PAINT

    Quote Originally Posted by DEXWERX View Post
    If you're gonna go the subclassing route - why not just subclass WM_PAINT and paint the form yourself?

    BeginPaint returns the invalidated rect. VB just doesn't pass the rect to the Paint() Event.
    Yes, i haven't noticed that BeginPaint returns the invalidated rect. That is another good choice, thank you very much!

    Thank you all very much for trying to help me !

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.