Hello,
I am trying to get the string from a ListBox but am unable to do so.
I use LB_GETTEXT with the following syntax in eVB:

Dim hConnWin As Long
Dim count As Long ' number of items in the list box
Dim curIndx As Long ' index of the currently selected item
Dim itemtext As String ' text of that item
Dim textlen As Long ' length of the item text


hConnWin = FindWindow("listbox", "")
If hConnWin <> 0 Then
'Now I have the list-box
count = SendMessage(hConnWin, LB_GETCOUNT, CLng(0), CLng(0))
[I get a correct count]
curIndx = SendMessage(hConnWin, LB_GETCURSEL, 0, 0)
[I get the correct index]
textlen = SendMessage(hConnWin, LB_GETTEXTLEN, curIndx, CLng(0))
[I get the correct textlength]
itemtext = Space(textlen) & vbNullChar
textlen = SendMessage(hConnWin, LB_GETTEXT, curIndx, itemtext)
[ I don't get anything in itemtext!!]
itemtext = Mid(itemtext, 1, textlen)
End If

My SendMessage Declare function:
Public Declare Function SendMessage Lib "Coredll" Alias "SendMessageW" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Variant _
) As Long

What am I doing wrong? Is it wrong to use textlen to allocate space for the
itemtext String? Are there any UNICODE issues here?

NOTE: As you may have noticed this code is in a different process from the
one where the listbox is.
Is there any sort of an issue with LB_GETTEXT across processes?
Please help!
--
Regards,
Sami

Using SendMessage(hWnd, LB_GETTEXT, iIndex, vbTextStr) does not return a LMERR but I don't get any string returned. by Sami

Sami
Fri Feb 06 03:04:06 CST 2004

Hello,
I even tried this out in eVC++:

HWND hConnWin;
LONG count, curIndx, textlen;
TCHAR* itemtext = NULL;
char* mbitemtext = NULL;

hConnWin = FindWindow(_T("listbox"), _T(""));
if (hConnWin)
{
count = SendMessage(hConnWin, LB_GETCOUNT, 0, 0); [Here I have the
correct count]
curIndx = SendMessage(hConnWin, LB_GETCURSEL, 0, 0); [Here I have the
correct index]
textlen = SendMessage(hConnWin, LB_GETTEXTLEN, curIndx, 0); [Here I have
the correct length]
itemtext = new TCHAR[textlen + 1];
textlen = SendMessage(hConnWin, LB_GETTEXT, curIndx, (LPARAM)itemtext);
[Here I have the correct length but my buffer is empty!!]
}

NOTE: I am using OS: WinCE3.0 and PLATFORM: HPC2000.

--
Regards,
Sami
"Sami" <s8a2m9i1_i5s1l9a6m@hotmail.com> schrieb im Newsbeitrag
news:eZhQoUA7DHA.2416@TK2MSFTNGP10.phx.gbl...
> Hello,
> I am trying to get the string from a ListBox but am unable to do so.
> I use LB_GETTEXT with the following syntax in eVB:
>
> Dim hConnWin As Long
> Dim count As Long ' number of items in the list box
> Dim curIndx As Long ' index of the currently selected item
> Dim itemtext As String ' text of that item
> Dim textlen As Long ' length of the item text
>
>
> hConnWin = FindWindow("listbox", "")
> If hConnWin <> 0 Then
> 'Now I have the list-box
> count = SendMessage(hConnWin, LB_GETCOUNT, CLng(0), CLng(0))
> [I get a correct count]
> curIndx = SendMessage(hConnWin, LB_GETCURSEL, 0, 0)
> [I get the correct index]
> textlen = SendMessage(hConnWin, LB_GETTEXTLEN, curIndx, CLng(0))
> [I get the correct textlength]
> itemtext = Space(textlen) & vbNullChar
> textlen = SendMessage(hConnWin, LB_GETTEXT, curIndx, itemtext)
> [ I don't get anything in itemtext!!]
> itemtext = Mid(itemtext, 1, textlen)
> End If
>
> My SendMessage Declare function:
> Public Declare Function SendMessage Lib "Coredll" Alias "SendMessageW" ( _
> ByVal hwnd As Long, _
> ByVal wMsg As Long, _
> ByVal wParam As Long, _
> lParam As Variant _
> ) As Long
>
> What am I doing wrong? Is it wrong to use textlen to allocate space for
the
> itemtext String? Are there any UNICODE issues here?
>
> NOTE: As you may have noticed this code is in a different process from the
> one where the listbox is.
> Is there any sort of an issue with LB_GETTEXT across processes?
> Please help!
> --
> Regards,
> Sami
>
>



Re: Using SendMessage(hWnd, LB_GETTEXT, iIndex, vbTextStr) does not by Norman

Norman
Fri Feb 06 09:40:12 CST 2004

Sami wrote:
> Hello,
> I even tried this out in eVC++:
>
> HWND hConnWin;
> LONG count, curIndx, textlen;
> TCHAR* itemtext = NULL;
> char* mbitemtext = NULL;
>
> hConnWin = FindWindow(_T("listbox"), _T(""));
> if (hConnWin)
> {
> count = SendMessage(hConnWin, LB_GETCOUNT, 0, 0); [Here I have the
> correct count]
> curIndx = SendMessage(hConnWin, LB_GETCURSEL, 0, 0); [Here I have the
> correct index]
> textlen = SendMessage(hConnWin, LB_GETTEXTLEN, curIndx, 0); [Here I have
> the correct length]
> itemtext = new TCHAR[textlen + 1];
> textlen = SendMessage(hConnWin, LB_GETTEXT, curIndx, (LPARAM)itemtext);
> [Here I have the correct length but my buffer is empty!!]
> }
>
> NOTE: I am using OS: WinCE3.0 and PLATFORM: HPC2000.
>
> --
> Regards,
> Sami

The C++ code looks correct.

How do you determine that the buffer is empty?

If you're looking at the first byte and finding it equal to zero,
remember that Unicode uses two byte for each character and you don't
have a NUL terminator until you have both of them equal to zero.

Norm


Re: Using SendMessage(hWnd, LB_GETTEXT, iIndex, vbTextStr) does not return a LMERR but I don't get any string returned. by r_z_aret

r_z_aret
Fri Feb 06 15:50:34 CST 2004

On Fri, 06 Feb 2004 15:40:12 GMT, Norman Bullen
<norm@BlackCatAssociates.INVALID.com> wrote:

>Sami wrote:
>> Hello,
>> I even tried this out in eVC++:
>>
>> HWND hConnWin;
>> LONG count, curIndx, textlen;
>> TCHAR* itemtext = NULL;
>> char* mbitemtext = NULL;

clip

>> [Here I have the correct length but my buffer is empty!!]
>> }
>>
>> NOTE: I am using OS: WinCE3.0 and PLATFORM: HPC2000.
>>
>> --
>> Regards,
>> Sami
>
>The C++ code looks correct.
>
>How do you determine that the buffer is empty?
>
>If you're looking at the first byte and finding it equal to zero,
>remember that Unicode uses two byte for each character and you don't
>have a NUL terminator until you have both of them equal to zero.

For TCHAR arrays (such as itemtext), I use
itemtext[0] == _T( '\0' )
This works for Windows CE (UNICODE defined) and "big" Windows (UNICODE
not defined.

>
>Norm
>

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com