Vb6 如何将鼠标光标设置到标签上的指定位置?

Vb6 如何将鼠标光标设置到标签上的指定位置?,vb6,mouse,Vb6,Mouse,因此,我在VisualBasic6.0中开发了这个游戏,这是一个迷宫游戏,我希望我的鼠标光标设置在带有迷宫的表单的开始标签上,一旦表单被激活并获得焦点 Dim label1 As New label=Start 过去我使用Windows API完成过类似的任务。在下面的示例中,表单包含一个名为“Label1”的标签,该标签位于表单的某个位置。激活表单时,光标将位于“Label1”的中心: Option Explicit Private Declare Function GetWindowRe

因此,我在VisualBasic6.0中开发了这个游戏,这是一个迷宫游戏,我希望我的鼠标光标设置在带有迷宫的表单的开始标签上,一旦表单被激活并获得焦点

Dim label1 As New label=Start

过去我使用Windows API完成过类似的任务。在下面的示例中,表单包含一个名为“Label1”的标签,该标签位于表单的某个位置。激活表单时,光标将位于“Label1”的中心:

Option Explicit

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Sub Form_Activate()
    Dim wr As RECT
    Dim tb As Long
    Dim le As Long
    Dim x As Long
    Dim y As Long
    
    'calculate coordinates
    Call GetWindowRect(Me.hwnd, wr)                                    'window coordinates
    tb = (Me.Height - Me.ScaleHeight) - (Me.Width - Me.ScaleWidth) / 2 'title bar height
    le = (Me.Width - Me.ScaleWidth) * 0.5                              'left edge of client area
    
    'calculate center of label
    x = wr.Left + ScaleX(le + Label1.Left + Label1.Width * 0.5, Me.ScaleMode, vbPixels)
    y = wr.Top + ScaleY(tb + Label1.Top + Label1.Height * 0.5, Me.ScaleMode, vbPixels)
    SetCursorPos x, y
End Sub

过去我使用Windows API完成过类似的任务。在下面的示例中,表单包含一个名为“Label1”的标签,该标签位于表单的某个位置。激活表单时,光标将位于“Label1”的中心:

Option Explicit

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Sub Form_Activate()
    Dim wr As RECT
    Dim tb As Long
    Dim le As Long
    Dim x As Long
    Dim y As Long
    
    'calculate coordinates
    Call GetWindowRect(Me.hwnd, wr)                                    'window coordinates
    tb = (Me.Height - Me.ScaleHeight) - (Me.Width - Me.ScaleWidth) / 2 'title bar height
    le = (Me.Width - Me.ScaleWidth) * 0.5                              'left edge of client area
    
    'calculate center of label
    x = wr.Left + ScaleX(le + Label1.Left + Label1.Width * 0.5, Me.ScaleMode, vbPixels)
    y = wr.Top + ScaleY(tb + Label1.Top + Label1.Height * 0.5, Me.ScaleMode, vbPixels)
    SetCursorPos x, y
End Sub

你能说得更具体些吗?你说的是什么形式?你能更具体一点吗?你说的是什么形式?天哪,真的很感谢你!老兄,成功了,真的非常感谢你!