-
Apr 18th, 2017, 10:34 AM
#1
Thread Starter
Lively Member
[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.
-
Apr 18th, 2017, 10:42 AM
#2
Re: Get the updated (changed/cleared) region of WM_PAINT
Last edited by DEXWERX; Apr 18th, 2017 at 11:01 AM.
-
Apr 18th, 2017, 10:49 AM
#3
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.
-
Apr 18th, 2017, 10:56 AM
#4
Thread Starter
Lively Member
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.
-
Apr 18th, 2017, 10:59 AM
#5
Re: Get the updated (changed/cleared) region of WM_PAINT
Originally Posted by vietnamvodich
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.
-
Apr 18th, 2017, 11:32 AM
#6
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.
-
Apr 20th, 2017, 05:34 AM
#7
Thread Starter
Lively Member
Re: [RESOLVED] Get the updated (changed/cleared) region of WM_PAINT
Originally Posted by DEXWERX
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|