 |
周松的意见:
源代码见附件 demo.rar。
Dim IsVisible As Boolean
Private Sub Form_Load()
Image1.Picture = Me.Icon
Image2.Picture = Me.Icon
End Sub
Private Sub Timer1_Timer()
IsVisible = Not IsVisible
Image2.Visible = IsVisible
Line1.Visible = IsVisible
If Image2.Left < 10 Then End
If Not IsVisible Then
Image2.Left = Image2.Left - 60
Line1.X1 = Line1.X1 - 60
Line1.X2 = Line1.X2 - 60
End If
End Sub
VB本身动画很难避免闪烁,以为REDRAW实在太慢。
考虑使用以下API,将最后一个参数设置为PATINVERT,可一定程度改善效果。
BOOL BitBlt(
HDC hdcDest, // handle to destination device context
int nXDest, // x-coordinate of destination rectangle's upper-left
// corner
int nYDest, // y-coordinate of destination rectangle's upper-left
// corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
HDC hdcSrc, // handle to source device context
int nXSrc, // x-coordinate of source rectangle's upper-left
// corner
int nYSrc, // y-coordinate of source rectangle's upper-left
// corner
DWORD dwRop // raster operation code
);
Lee Rambow的意见:
但是要完全不闪烁,我用过的方法只有使用DIRECT,SURFACE之间的FLIP完全可以产生平滑的动画效果。
参考IDirectDrawSurface3::Blt
此问题由周松等回答。
附加关键字:编程, 源程序, programming, source code, Visual Basic, VB, 图形、图象, picture, graph, image, draw。
|