Click to See Complete Forum and Search --> : Help whit WM_GETMESAGE and LB_GETMESSAGE


Habatar
November 30th, 2005, 10:51 AM
Hello.

I am making a DLL that have functions to retrive the Text of a Control and of a ListBox. This are in two diferrent functions.

LPSTR HGUI_Control_Get_Texto(HWND hWnd)
{
char *stexto = new char[255];
SendMessage(hWnd,WM_GETTEXT,255,(LPARAM)(LPSTR)stexto);
MessageBox(NULL,stexto, "Text",MB_OK);
return stexto;
}

LPSTR HGUI_Control_ListBox_Get_Texto(HWND hWnd, int indice)
{
char sTexto[255];
SendMessage(hWnd, LB_GETTEXT, indice, (LPARAM)sTexto);
MessageBox(NULL,sTexto,"Text",MB_OK);
return sTexto;
}

I try it but dont work correctly. The text that return and show the MessageBox is something like: "面面面面面面面面面面面面面".
I am using Visual Studio C++ 2005 Express.

Anyone can help me?
Thanks.

golanshahar
November 30th, 2005, 11:50 AM
you code is buggy you create automatic variable and return it from the function so hence the garabge.


LPSTR HGUI_Control_ListBox_Get_Texto(HWND hWnd, int indice)
{
char sTexto[255];
SendMessage(hWnd, LB_GETTEXT, indice, (LPARAM)sTexto);
MessageBox(NULL,sTexto,"Text",MB_OK);
return sTexto;
}


so try this one instead:

void HGUI_Control_Get_Texto(HWND hWnd,char *lpszOut,int len)
{
if ( len > 0 )
::SendMessage(hWnd,WM_GETTEXT,len,(LPARAM)lpszOut);
}

void HGUI_Control_ListBox_Get_Texto(HWND hWnd, int indice,char *lpszOut,int len)
{
if ( len > 0 )
::SendMessage(hWnd, LB_GETTEXT, indice, (LPARAM)lpszOut);
}

//usage
char szTxt1[MAX_PATH]={0};
char szTxt2[MAX_PATH]={0};
HGUI_Control_Get_Texto(hwnd,szTxt1,sizeof(szTxt1));

HGUI_Control_ListBox_Get_Texto(hwnd, 0/*index*/,szTxt2,sizeof(szTxt2));


one question: are you attempting to get text from the controls on your process or from other process? casue if its from other process it wont work with ::SendMessage(..).

Cheers

Habatar
November 30th, 2005, 01:07 PM
Thanks for your answere.

I have try your code, but now I recibe an empty text using:"MessageBox(hwnd,szTxt1,"Text is",MB_OK);

This is a DLL that have functions to create controls: windows, editbox, statictext, listbox. This functions are called by other programming language (called "DarkBasicPro"). I suppose that is the same process.

golanshahar
November 30th, 2005, 04:41 PM
I have try your code, but now I recibe an empty text using:"MessageBox(hwnd,szTxt1,"Text is",MB_OK);

this is weird try to put breakpoint and see if ::SendMessage(..) is failing from some reason and if the buffer ok right after ::SendMessage(..).

what i changed doesnt suppose to give you empty strings!.

PS: if you can post more code of you use it and call the function it will be helpfull.

Cheers

Habatar
December 4th, 2005, 11:25 AM
Hello. Now works.

I use your functions whit no return value, and I create another functions that only return the value in the text char: char szTxt1[MAX_PATH]={0} ; whitout passing any parameters.

Great Thanks.