Functions that can replace the form Refresh method

Source: Internet
Author: User
Function
VB open AutoRedraw can facilitate the establishment of double buffering, the use of APIs in the background drawing, the last one-time overall update to the foreground, to achieve a stable flicker-free animation effect, under normal circumstances, VB will automatically background to the foreground of the refresh, there are two main situations:
1, received wm_pait message
2, the code calls the Refresh method

The situation that can let VB receive wm_pait message mainly has
1, the form is obscured or hidden after the recurrence
2, call any VB internal graphics methods, including PaintPicture, Print, Cls, line, Circle, Pset
3, call some special methods related to graphics methods, such as: Point, TextWidth, TextHeight

Can be seen to allow VB Automatic Update the opportunity is a lot of, perhaps we can not care about the problem of the foreground update, but have this kind of design experience friends, must have noticed: if the drawing does not use any VB own graphics method, using pure API drawing, or do a continuous animation, and inconvenient to insert DoEvents, The front desk will not be updated. So we painted for half a day, but did not see the content.
Both form and PictureBox are designed to solve this situation, but the Refresh method sometimes feels wasteful, for example, when an object moves an animation, it just keeps drawing a small area of the object. The Refresh method no matter how much you rewrite in the background, even if only a small area, it is the entire client area of the whole redraw, this speed will naturally slow down.

The following function is written to replace the Refresh method, which is slightly faster than the Refresh method when the whole area is refreshed, but it will be much faster if used for partial refreshes.
Private Declare Function GetDC Lib "user32" (ByVal hWnd as long) as long
Private Declare Function releasedc Lib "user32" (ByVal hWnd as Long, ByVal HDC as long) as long
Private Declare Function BitBlt Lib "gdi32" (ByVal hdestdc as Long, ByVal X as Long, ByVal y as Long, ByVal nwidth as Long , ByVal nheight as Long, ByVal HSRCDC as Long, ByVal xsrc as Long, ByVal ysrc as Long, ByVal Dwrop as long) as long

Public Sub Boxrefresh (dhwd as Long, dhdc as long, X as long, y as Long, w as Long, h as Long)
Dim FDC as Long
FDC = GetDC (DHWD)
BitBlt FDC, X, Y, W, H, Dhdc, X, Y, vbsrccopy
ReleaseDC DHWD, FDC
End Sub

My machine 1024*768*32 when the form to maximize, with the Refresh method 3,000 times, use more than 8 seconds, but if only update 100x100 area, the Refresh method can do or full screen update, with the above Boxrefresh, just 78 milliseconds.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.