建立一个工程,在窗体中加上一个Timer控件,Timer的时间间隔设置为100。窗体中加入以下代码,运行即可。Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Timer1_Timer() Dim Hdc1 As Long Hdc1 = GetDC(0) Dim i As Long For i = -5 To 5 Me.Caption = SetPixel(Hdc1, Screen.Width / Screen.TwipsPerPixelX / 2 + i, Screen.Height / Screen.TwipsPerPixelY / 2, RGB(255, 0, 0)) Me.Caption = SetPixel(Hdc1, Screen.Width / Screen.TwipsPerPixelX / 2, Screen.Height / Screen.TwipsPerPixelY / 2 + i, RGB(255, 0, 0)) Next i End Sub
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Timer1_Timer()
Dim Hdc1 As Long
Hdc1 = GetDC(0)
Dim i As Long
For i = -5 To 5
Me.Caption = SetPixel(Hdc1, Screen.Width / Screen.TwipsPerPixelX / 2 + i, Screen.Height / Screen.TwipsPerPixelY / 2, RGB(255, 0, 0))
Me.Caption = SetPixel(Hdc1, Screen.Width / Screen.TwipsPerPixelX / 2, Screen.Height / Screen.TwipsPerPixelY / 2 + i, RGB(255, 0, 0))
Next i
End Sub
还有,在DIRECTX中,可能会定义一个和桌面不同的分辨率,因此需要重新判断位置