取得滑鼠座標

使用API

API名稱:GetCursorPos
動態連結程式庫: user32.dll


程式說明

取得滑鼠目前座標,雙螢幕時會有BUG。


特殊類別

使用類別:POINTAPI

vb6

Private Type POINTAPI
    X As Long
    Y As Long
End Type

vb.net

Structure POINTAPI
    Dim x As Integer
    Dim y As Integer
End Structure

VB6程式碼

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Sub Timer1_Timer()
    ' Display current mouse screen coordinates in pixels using a Label control.
    Dim lpPoint As POINTAPI
    GetCursorPos lpPoint
    lblMouseState = "X = " & lpPoint.X & "   Y = " & lpPoint.Y
    Text1.Text = lblMouseState
End Sub

VB.NET程式碼

Public Class Form1
    Structure POINTAPI
        Dim x As UInteger
        Dim y As UInteger
    End Structure

    Private Declare Function GetCursorPos Lib "user32" (ByRef point As POINTAPI) As Long

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim rect As POINTAPI
        GetCursorPos(rect)
        TextBox1.Text = "x:" & rect.x
        TextBox2.Text = "y:" & rect.y
    End Sub
End Class

下載