Problem sending message to listbox

i'm having problem when using the
SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM) szString);

the szString contain the string that wanted to add into the listbox

the SendMessage is inside a function code..
when the main code run until a certain point, it enter the function and at the end of the function, it suppose to update the listbox with the text..but it's not updating..
here's the question...must the SendMessage be always in the WM_COMMAND or can be anywhere in the code..
thanks..
SendMessage() can be anywhere in the code.
but it's not updating the listbox though...
i have this in the function code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void Search(char *buf)
{
	beginword = (char*) malloc (wordlength); //allocate dynamic memory
			for(n = 0; n < FileSize ; n++)
			{
				if(buf[n] == matchedword[0])
				{
					memcpy(beginword,&buf[n],wordlength);
					beginword[wordlength] = 0;

					if(_strcmpi(beginword,matchedword) == 0)
					{
						
		                           SendMessage(hwndList, LB_ADDSTRING,0,(LPARAM)data.cFileName);
					
					}
				}
			}
}	


it suppose to update the listbox when the strcmp return true..
but it's now somehow..
Last edited on
Where have you gotten the handle to the listbox? Replace your code with this and see if it works --

SendDlgItemMessage(hwnd, ID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)data.cFileName);

Notice the extra parameter. The hwnd is the main window in which the listbox is situated. The ID_LISTBOX parameter is the ID value you assigned to the listbox.

I suspect you haven't properly gotten the handle to the listbox. The above code takes care of that.
thanks Lamblion =)
i found out why the reason it's not sending..i forgot to include the hwndList in the global variable =P but i'll use your method..it seem to be more efficient =)
Topic archived. No new replies allowed.