|
-
Jun 21st, 2001, 01:46 PM
#1
Thread Starter
Black Cat
Get at another Window's list box.
How hard is it to get at a ListBox on another Window? Here's the catch: I'm communicating with a hardware device via API calls to a pseudo-driver DLL provided by the HW manufacturer, and they supplied a (poorly documented) .bas file with the "declares" for that DLL. I can synchronously call one of the functions, which displays a "connecting" window for 20 or more seconds, following by a window with a list box containing variable names of what the HW device is monitoring. When the user clicks close on that window, the function returns the value selected in the list box to me in a string buffer. The problem is the user needs to pick quite a few of the variable names, and since each call to the function can take up to a couple of minutes for each connection to the device, I'd like to just get at those variable names once, filter them, load them into a list box on a form I created, then let the user pick from there.
How feasible is this "user-friendlyness" tweak? I have the program working smoothly, and I'd like to make it as easy for the user as possible, but I don't want to spend too much time on it if its not worth it.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Jun 22nd, 2001, 03:54 AM
#2
Fanatic Member
Hi JoshT,
Heres what I use:
Code:
Option Explicit
Option Base 0
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
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal _
lParam As String)
Private Const LB_GETCOUNT = &H18B
Private Const LB_GETTEXT = &H189
Public Sub GetListBox()
Dim lhWnd&
Dim ltxthWnd&
Dim ltChars&
Dim aLBoxItems() As String
lhWnd = FindWindowEx(0&, 0&, vbNullString, "API Viewer - C:\Program Files\Microsoft Visual Studio\Common\Tools\Winapi\Win32api.txt")
If lhWnd Then
ltxthWnd = FindWindowEx(lhWnd, 0&, "ThunderRT6ListBox", vbNullString)
If ltxthWnd Then
Call ReturnList(ltxthWnd, aLBoxItems)
End If
Else
End If
End Sub
Public Sub ReturnList(hWnd As Long, ByRef sList() As String)
Dim iCount%
Dim lRet&
Dim lItems&
Dim sBuff$
sBuff = String(256, " ")
lItems = SendMessage(hWnd, LB_GETCOUNT, 0, 0)
For iCount = 0 To lItems - 1
ReDim Preserve sList(iCount)
lRet = SendMessageByStr(hWnd, LB_GETTEXT, iCount, sBuff)
sList(iCount) = Trim(sBuff)
Next iCount
End Sub
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Jun 22nd, 2001, 06:39 AM
#3
Thread Starter
Black Cat
ltxthWnd = FindWindowEx(lhWnd, 0&, "ThunderRT6ListBox", vbNullString)
Thunder* class names are VB, right? The classname for a standard listbox would just be "LISTBOX", right?
Thanks, crispin, that'll get me started. Now, I'm gonna have to get this to run on a separate thread...
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Jun 25th, 2001, 10:46 AM
#4
Thread Starter
Black Cat
Okay, I got this working. I'm using an API Timer to force a seperate thread. Now, my problem is that my app finds the ListBox and the Window while it is hidden and there's nothing in the ListBox...
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
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
|