Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB
Expertise: Advanced
Mar 24, 2008

Make Your Mouse Pointer Tremble

To make your mouse pointer appear to be trembling, you first create a form with ScaleMode = 3 - Pixel. Then use the following code:

Option Explicit
Private Type POINTAPI
    X As Long
    Y As Long
End Type

'Windows API functions to set the cursor position
Private Declare Function SetCursorPos Lib "User32" (ByVal X As Long,_
    ByVal Y As Long) As Long
    
Private Declare Function ClientToScreen Lib "User32" 
(ByVal hWnd As_ Long, lpPoint As POINTAPI) As Long


Dim lpPoint As POINTAPI

'To get the mouse position at every moment
Private Sub Form_MouseMove(Button As Integer, Shift As Integer,_
X As Single, Y As Single)
    lpPoint.X = X
    lpPoint.Y = Y
   
End Sub

Private Sub Timer_Timer()
    If lpPoint.X < Form1.ScaleWidth And lpPoint.Y < Form1.ScaleHeight Then
        lpPoint.X = lpPoint.X + Rand(-3, 3)
        lpPoint.Y = lpPoint.Y + Rand(-3, 3)
        ClientToScreen hWnd, lpPoint
        SetCursorPos lpPoint.X, lpPoint.Y
    End If
End Sub

'To create the random value
Function Rand(ByVal Low As Integer, ByVal High As Integer) As Integer
 Rand = ((High - Low) * Rnd) + Low
End Function
Frederico Cebrian
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap