我在对话框上加了几条Line控件,然后在对话框上画图,已经采用了缓冲dc来画了,而且,基本上0.5秒才重画一次,第一次重画时闪烁不算严重,第二次闪烁就很明显了。
下面是完整代码(分模块和窗体) :Private Sub Form_Load()
Dim mRGN As Long, Cnt As Long, mBrush As Long
mDC = CreateCompatibleDC(GetDC(0))
mBitmap = CreateCompatibleBitmap(GetDC(0), Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY)
SelectObject mDC, mBitmap
SetBkMode mDC, TRANSPARENT
SetRect R, 0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY
FillRect mDC, R, GetSysColorBrush(COLOR_WINDOW)
DeleteObject SelectObject(mDC, CreateMyFont(1, 0))
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Timer1.Enabled = True Then Exit Sub
Dim i As Long, j As Long
i = (x - (x Mod 1000)) / 1000
j = (y - (y Mod 1000)) / 1000
Debug.Print arr(i, j)
If arr(i, j) = 0 Then Exit Sub
drops = drops - 1
Label1.Caption = drops
arr(i, j) = arr(i, j) + 1
calcDC
Me.Refresh
check
Timer1.Enabled = True
End Sub
Private Sub Form_Paint()
BitBlt Me.hdc, 0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY, mDC, 0, 0, vbSrcCopy
End Sub
Private Sub Form_Unload(Cancel As Integer)
DeleteDC mDC
DeleteObject mBitmap
End Sub