假设我现在窗口上有5个TEXT1控件,INDEX分别是0-4,我该怎么用API,或者其他方法,来获取他的INDEX值呢,当然,前提是我只有知道5个TEXT控件的HWND.谢谢

解决方案 »

  1.   

    遍历
    Private Sub Command1_Click()
       Dim lng As Long
       Dim ctl As Control
       
       lng = Text1(1).hWnd
       
       For Each ctl In Controls
            If ctl.hWnd = lng Then
                MsgBox ctl.Index
            End If
       Next
    End Sub
      

  2.   

    遍历
    Private Sub Command1_Click()
       Dim lng As Long
       Dim ctl As Control
       
       lng = Text1(1).hWnd
       
       For Each ctl In Controls
            If ctl.hWnd = lng Then
                MsgBox ctl.Index
            End If
       Next
    End Sub
      

  3.   

    遍历
    Private Sub Command1_Click()
       Dim lng As Long
       Dim ctl As Control
       
       lng = Text1(1).hWnd
       
       For Each ctl In Controls
            If ctl.hWnd = lng Then
                MsgBox ctl.Index
            End If
       Next
    End Sub
      

  4.   

    这方法不错,但我想最好能用API,但找不到.
      

  5.   

    那就使用GetCursorpos还取得当前拥有焦点的控件的hwnd,在结合楼上的方法得到其index
      

  6.   

    Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long