Results 1 to 4 of 4

Thread: GetWindowTex

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Hi,

    Frame -> Mdi - > Child Window -> Combobox

    I have the HWND of the Combobox. But getwindow
    text will only get the WINDOWS text. I need the
    text of a control (label, combobox, ext..) of
    another window. Now how can i do that?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    label, combobox are also windows.getwindowtext gets their text too.
    Code:
    Dim c As String
    c = Space(256)
    GetWindowText Combo1.hwnd, c, 255
    'c contains combo1 text
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    I'm assuming you want to get a list of strings inside a ComboBox that you only have the hWnd of.
    (If you want something else, please explain it again)
    Code:
    Option Explicit
    
    Private Const CB_GETCOUNT = &H146
    Private Const CB_GETLBTEXT = &H148
    Private Const CB_GETLBTEXTLEN = &H149
    
    Private Const CB_ERR = (-1)
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Function GetComboBoxItems(ByVal hWndComboBox As Long) As Variant
        Dim nCount As Long, I As Long, nLen As Long
        Dim sItems() As String
        
        nCount = SendMessage(hWndComboBox, CB_GETCOUNT, 0, 0)
        If (nCount = CB_ERR) Or (nCount = 0) Then Exit Function
        
        For I = 0 To nCount - 1
            ReDim Preserve sItems(0 To I) As String
            nLen = SendMessage(hWndComboBox, CB_GETLBTEXTLEN, I, 0)
            If nLen = CB_ERR Then Exit Function
            sItems(I) = String(nLen, vbNullChar)
            If SendMessage(hWndComboBox, CB_GETLBTEXT, I, ByVal sItems(I)) = CB_ERR Then Exit Function
        Next
        
        GetComboBoxItems = sItems
    End Function
    Here's how to use it:
    Code:
    Dim sItems As Variant
    Dim I As Long
    
    sItems = GetComboBoxItems(MyComboBox.hWnd) ' Does not have to be an hWnd in your app
    
    If IsArray(sItems) Then
        For I = LBound(sItems) To UBound(sItems)
            Debug.Print sItems(I) & " = " & I + 1 ' Item1 = 1, Item2 = 2, etc.
        Next
    Else
        Debug.Print "Error, or empty ComboBox."
    End If

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Or if you want to get the text from the TextBox part of the combobox, you would have to get the hwnd from the child window of the combobox, and use GetWindowText on that hwnd. The classname of this child is "Edit".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width