Can replace the function of the Form Refresh method

xiaoxiao2021-03-05  28

From: http://blog.9cbs.net/homezj/archive/2005/04/16/349731.aspx

Open AutoRedRAW can be easily established in the background, using the API to draw in the background, the last one is updated to the front desk, achieving stable no flash animation effect, in general, VB will automatically perform the backstage to the front desk refresh, this mainly Two cases: 1, receive a WM_PAIT message 2, code call Refresh method

It can make VB to receive the WM_PAIT message. There are 1. The form is covered or hidden after reproducing 2, calling any graphical method of any VB, including PaintPicture, PRINT, CLS, LINE, CIRCLE, PSET3, call some and graphical methods Special approach, such as: Point, TextWidth, TextHeight

It can be seen that there is a lot of opportunities for VB automatic updates. Maybe we don't have to care about the front desk update problem, but there are friends with such design experiences. I must notice that if there is no VB my own graphics method in the drawing, use a pure API Draw, or make a continuous animation, it will not be updated when you are inserting doevents. This way we painted for a long time, but didn't see the content. All of Form and Picturebox are designed to solve this situation. However, the refresh method sometimes feels more waste, for example, when making an object movement, only a small area related to the object, can refresh method No matter how much content you have rewritten in the background, even a small area, it is also the overall red painting of the entire customer area, which will naturally slow down.

The following function is written in replacing the Refresh method. When it is refreshed in the area, it is slightly faster than the refresh method, but if it is used to partially refresh, it will be much faster. Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As LongPrivate Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As LongPrivate Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X 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, FDCEND SUB

When I have 1024 * 768 * 32, the form is maximized, with the refresh method 3000 times, it takes more than 8 seconds, but if only the 100x100 area is updated, the refresh method can do full screen update, with the above BoxRefresh, only It takes 78 milliseconds.

转载请注明原文地址:https://www.9cbs.com/read-34062.html

New Post(0)