Please dont duplicate posts...its against board rules and will earn you no friends........
The problem you have is the the return from LB_GETTEXT gives the number of chars....not the chars themselves
Anyway.....
Personally, I like MFC, but when I am doing this kind of stuff I prefer to use straight API calls....the MFC functions go through loads of ASSERTS before calling APIS, and as MFC was not really made to be used to break into other windows controlled by other processes its not the tool for the job!
I wrote this to look at the first entry of a list in a dialog based app I wrote....
Code:
#include <windows.h>
#include <iostream>
using namespace std;
int main(void)
{
HWND hMainWnd = FindWindow(NULL,"WinXRay");
if(!hMainWnd){
MessageBox(NULL,"Error with Main Wnd!",NULL,MB_OK);
return 1;
}
HWND hListWnd = FindWindowEx(hMainWnd,NULL,"ListBox",NULL);
if(!hListWnd){
MessageBox(NULL,"Error with Child Wnd!",NULL,MB_OK);
return 1;
}
DWORD dwCount = SendMessage(hListWnd,LB_GETTEXTLEN,0,0);
if(dwCount){
char* lpBuff = new char[dwCount+1];
if(!lpBuff){
MessageBox(NULL,"Error with memory!",NULL,MB_OK);
return 1;
}
if(LB_ERR != SendMessage(hListWnd,LB_GETTEXT,0,(LPARAM)lpBuff)){
cout << "First item in ListBox " << lpBuff << endl;
}
delete [] lpBuff;
}
return 0;
}
That's faily simple, but the complexity comes in where you have layeres of child windows and more than 1 child on a layer shares a windows class....then you need to compose some sort of logic to loop through the childeren until you find the one you need......in such a case - check the first child with FindWindowEx() with the second param to NULL..save the HWND...if that child isnt the one you need, go back, but this time use the previous call's HWND as the second param....that will then allow you to cycle through the childeren that share a class.......
I cant give you the anser as I dont have your details...but it shouldnt be difficult