|
-
Oct 27th, 2000, 12:35 PM
#1
Thread Starter
Frenzied Member
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?
-
Oct 27th, 2000, 02:07 PM
#2
Frenzied Member
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
-
Oct 27th, 2000, 02:10 PM
#3
Guru
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
-
Oct 27th, 2000, 03:55 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|