Use the LinedDa function to make simple animation

zhaozj2021-02-16  97

If a relatively simple animation effect is achieved in VB, many people will use Timer controls, in fact, there is a linedda in the API function, and the simple animation effect is not bad with this function. Because it is an API function, it is generally, so many languages ​​can use it to achieve simple animation.

The prototype of this function is as follows:

Bool Linedda (int NXStart, int NYSTART, INT NXEND, INT NYEND, LINEDDAPROC LPLINEFUNC, LPARAM LPDATA);

The parameters are as follows:

NxStart: X value of the starting point

NYSTART: The y value of the starting point

NXEND: X value of the end point

NYEND: Y value of the end point

LPLINEFUNC: Address of the callback function

LPDATA: User-defined parameters (this parameter is passed to the callback function)

This function and animation are actually nothing. Its function is to calculate the coordinates of each screen pixel on two-point line segment. The coordinates of these two points have been given in the first four parameters of the function. Each time a coordinate is calculated, the function calls the callback function referred to in the fifth parameter, we can complete some simple operations in the callback function to achieve the animation effect.

The prototype of the callback function is: Void Callback LinedDaproc (int X, int y, lparam lpdata);

The first two parameters are the coordinates of the point, and the third parameter is the custom parameters passed by LINEDDA, ​​which is specified by our own, and what is all. :)

The statement of the LINEDDA function in VB is:

Public Declare Function Linedda Lib "GDi32.dll" (Byval N1 As Long, Byval N3 As Long, Byval N4 As Long, BYVAL LPAR LPAR AS Long

Its callback function prototype is:

Public Sub LinedDaproc (byval x as long, byval y as long, byval lpdata as long

In VB, the callback function must be placed in the standard module, use the Addressof operator when the function address is transferred, and the function name is connected.

The VB source program is as follows:

Form module:

Option expedition

Private submmand1_click ()

'Circulating the LinedDa function, implement simple animation in its designated callback

DIM I as long

DIM POINT (9) as PointApi

For i = 0 to Ubound (Point) - 1

Point (i 1) .x = Point (i) .x 50

IF Point (i) .y = 0 THEN POINT (i 1) .y = 50 else Point (i 1) .y = 0

Linedda Point (i) .X, Point (i) .y, Point (i 1) .x, Point (i 1) .y, addressof lineddaproc, me.hdc

Next i

End Sub

Standard module:

Option expedition

'API function declaration

Public Declare Function LineDDA Lib "gdi32.dll" (ByVal n1 As Long, ByVal n2 As Long, ByVal n3 As Long, ByVal n4 As Long, ByVal lpLineDDAProc As Long, ByVal lParam As Long) As LongPublic Declare Function DrawText Lib "user32. DLL "Alias" DrawTexta "(Byval HDC As Long, Byval Ncount As Long, LPRECT AS RECT, BYVAL WFORMAT AS long) As long

Public Declare Sub Sleep Lib "kernel32.dll" (Byval dwmilliseconds as ring)

'API type declaration

Public Type Rect

LEFT As Long

Top as long

Right As long

Bottom as long

End Type

Public Type PointApi

X as long

Y as long

End Type

'API constant statement

Private const dt_center = & h1

Private const dt_vcenter = & h4

The callback function of 'Linedda function

'Parameters: x, y is point coordinates, LPDATA is custom parameters

Public Sub LinedDaproc (byval x as long, byval y as long, byval lpdata as long

DIM RCT AS Rect

IF x MOD 10 = 0 THEN

Rct.Left = X

Rct.right = rct.Left 18

Rct.top = Y

Rct.bottom = rct.top 18

DrawText LPDATA, "LPP", -1, RCT, DT_Center OR DT_VCENTER

Sleep (100)

Doevents

END IF

End Sub

The result of the above program is to display some text on the form, add a commandbutton to the form, and copy the code above. In fact, in the famous PGP encryption software, when the password enters an error, the window will be jitter, this effect can be implemented using the LINEDDA function, the key is to see our imagination. : D

This is the above source download address: http://9cbsgoodname008.51.net/LINEDDA.ZIP

* ------------------------------------------- *

* Please inform the author and indicate the source, 9CBS welcomes you! *

* Author: Lu Peipei (goodname008) *

* Email: GoodName008@163.com *

* Column: http://blog.9cbs.net/goodname008 *

* ------------------------------------------- *

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

New Post(0)