编程
在VB6中利用API对光标进行编程:
Option ExplicitPrivate Type POINTAPI X As Long Y As LongEnd TypePrivate Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As LongPublic Function GetXCursorPos() As Long Dim pt As POINTAPI GetCursorPos pt GetXCursorPos = pt.XEnd FunctionPublic Function GetYCursorPos() As Long Dim pt As POINTAPI GetCursorPos pt GetYCursorPos = pt.YEnd Function '得到光标在屏幕中的位置Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Label1.Caption = "X Screen Position = " & GetXCursorPos Label2.Caption = "Y Screen Position = " & GetYCursorPosEnd Sub'隐藏光标Private Sub Command1_Click() ShowCursor FalseEnd Sub'显示光标Private Sub Command2_Click() ShowCursor TrueEnd Sub
在VB.NET中利用Cursor 类很简单地对光标进行编程:(可以获取和设置光标的位置,设置光标的形状,显示和隐藏光标)
'隐藏光标 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Cursor.Hide() End Sub '得到光标在屏幕中的位置 Private Sub Form2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove Me.Label1.Text = "X Screen Position = " & Cursor.Position.X Me.Label2.Text = "Y Screen Position = " & Cursor.Position.Y End Sub '显示光标 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Cursor.Show() End Sub
很简单的东西,更多的实例,可以参考API手册和Framework的文档。