PDA

Click to See Complete Forum and Search --> : text from a message box


nswan
Jun 1st, 2001, 09:13 AM
I have a trading program running on my computer.

When a trade goes through a message box appears with details of the trade in a list box. Is it possible to get this information out of the list box?

Thanks
Nick:cool:

Vlatko
Jun 1st, 2001, 09:23 AM
It has a list box on it so it is not a standard messagebox. Get the handle of the list box and retrieve the text by sending the LB_GETTEXT message:

LB_GETTEXT
An application sends an LB_GETTEXT message to retrieve a string from a list box.

LB_GETTEXT
wParam = (WPARAM) index; // item index
lParam = (LPARAM) (LPCTSTR) lpszBuffer; // address of buffer

Parameters
index
Value of wParam. Specifies the zero-based index of the string to retrieve.
Windows 95 and Windows 98: The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more than 32,767 items. Although the number of items is restricted, the total size in bytes of the items in a list box is limited only by available memory.

lpszBuffer
Value of lParam. Pointer to the buffer that will receive the string. The buffer must have sufficient space for the string and a terminating null character. An LB_GETTEXTLEN message can be sent before the LB_GETTEXT message to retrieve the length, in characters, of the string.
Return Values
The return value is the length of the string, in characters, excluding the terminating null character. If index does not specify a valid index, the return value is LB_ERR.

nswan
Jun 1st, 2001, 09:39 AM
thanks,

how do I find out the ID of the box, and the handle of the listbox?

Thanks
Nick

crispin
Jun 1st, 2001, 09:48 AM
I'm assuming you didn't write this app, in which case you will need to use FindWindowEx to search for the app, then search again on all the child windows of the app to find the one you want, then use Vlatko's method...

Vlatko
Jun 1st, 2001, 09:51 AM
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

· hwndParent
Identifies the parent window whose child windows are to be searched.
If hwndParent is NULL, the function uses the desktop window as the parent window. The function searches among windows that are child windows of the desktop.

· hwndChildAfter
Identifies a child window. The search begins with the next child window in the Z order. hwndChildAfter must be a direct child window of hwndParent, not just a descendant window.
If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.
Note that if both hwndParent and hwndChildAfter are NULL, the function searches all top-level windows.

· lpszClass
Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpszClass; the high-order word must be zero.

· lpszWindow
Points to a null-terminated string that specifies the window name (the window’s title). If this parameter is NULL, all window names match.



Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

· lpClassName
Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero.

· lpWindowName
Points to a null-terminated string that specifies the window name (the window’s title). If this parameter is NULL, all window names match.

Vlatko
Jun 1st, 2001, 09:54 AM
Something like this:

Dim hnd as Long, lbhnd as Long
hnd = FindWindow(vbNullString,msgboxtitle)
lbhnd = FindWindowEx(hnd,vbNullString,LISTBOX,vbNullString)\
'lbhnd is the handle of the listbox

crispin
Jun 1st, 2001, 09:56 AM
cheers Vlatko, I couldn't find any sample code anywhere (honest...)