一个combobox控件在网页里,想要取得他们里的内容。

解决方案 »

  1.   

    首先用findwindow找到窗体句柄
    然后用我写的这个函数“FindControlHwndByClsName”找到combobox的句柄
    然后用sendmessage 发送cb_findstring消息如果返回非-1就可以再用sendmessage发送cb_selectstring就可以了Option Explicit
    Private Const GW_HWNDNEXT = 2
    Private Const GW_CHILD = 5
    Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongPublic Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
        Dim h As Long, strArr() As String, pid As Long, i As Integer
        If InStr(GetWindowCaption(hwnd), "辉煌在线管理团队 - 群") Then
            FindControlHwndByClsName hwnd, "SysListView32", h
            GetWindowThreadProcessId hwnd, pid
            If h <> 0 Then
                strArr = GetListViewTextArray(h, pid)
                For i = 0 To UBound(strArr)
                    MsgBox strArr(i)
                Next
            End If
        End If
        EnumWindowsProc = True
    End FunctionPrivate Function GetWindowCaption(ByVal hwnd As Long) As String
        Dim strText As String, ret As Long
        ret = GetWindowTextLength(hwnd)
        If ret > 0 Then
            strText = Space(ret)
            GetWindowText hwnd, strText, ret + 1
            strText = Left(strText, ret)
            GetWindowCaption = strText
        Else
            GetWindowCaption = ""
        End If
    End FunctionPrivate Function FindControlHwndByCaption(ByVal nHwnd As Long, ByVal findStr As String, outHwnd As Long)
        Dim fHwnd As Long, myStr As String, sHwnd As Long
        fHwnd = GetWindow(nHwnd, GW_CHILD)
        If fHwnd = 0 Then Exit Function
        Do While fHwnd > 0
            myStr = String(100, Chr$(0))
            GetWindowText fHwnd, myStr, 100
            
            If Left(myStr, InStr(myStr, Chr$(0)) - 1) = findStr Then
                outHwnd = fHwnd
                Exit Function
            End If
            sHwnd = GetWindow(fHwnd, GW_CHILD)
            If sHwnd > 0 Then
                FindControlHwndByCaption fHwnd, findStr, outHwnd
            End If
            fHwnd = GetWindow(fHwnd, GW_HWNDNEXT)
        Loop
    End FunctionPrivate Function FindControlHwndByClsName(ByVal nHwnd As Long, ByVal clsName As String, outHwnd As Long)
        Dim fHwnd As Long, myStr As String, sHwnd As Long, ret As Long, iss As Boolean
        fHwnd = GetWindow(nHwnd, GW_CHILD)
        If fHwnd = 0 Then Exit Function
        Do While fHwnd > 0
            myStr = String(100, Chr$(0))
            GetClassName fHwnd, myStr, 100
            If Left(myStr, InStr(myStr, Chr$(0)) - 1) = clsName Then
                outHwnd = fHwnd
                Exit Function
            End If
            sHwnd = GetWindow(fHwnd, GW_CHILD)
            If sHwnd > 0 Then
                FindControlHwndByClsName fHwnd, clsName, outHwnd
            End If
            fHwnd = GetWindow(fHwnd, GW_HWNDNEXT)
        Loop
    End Function
      

  2.   

    msdn2.microsoft.com/en-us/library/aa768875.aspx -
      

  3.   

    提示一下:引用Microsoft Internet Controls和 Microsoft HTML Object Library,顺便说一句,一楼可能理解错楼主的问题了,回答的根本不搭边
      

  4.   

    HTML 里面叫做  Select 组件,Yes Or No ?
      

  5.   

    No
    DHTML对象模型里面只有select元素