counting and then sending a message
I have added a list box on a dialog box with the name "IDLIST"
Now I want to change the text of that dialog when the item(s) are selected in the list box. I used the following code:
Code:
int count;
HWND hlist = GetDlgItem(hwnd, IDCLIST);
count = SendMessage(hlist, LB_GETSELCOUNT, 0,0);
int *buffer1 = GlobalAlloc(GPTR, sizeof(int) * count);
SendMessage(hlist, LB_GETSELITEMS, (WPARAM)count, (LPARAM)buffer1);
SetWindowText(hwnd, buffer1);
GlobalFree(buffer1);
But it gives me these errors:
cannot convert from 'void *' to 'int *'
error C2664: 'SetWindowTextA' : cannot convert parameter 2 from 'int *' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
error C2440: '=' : cannot convert from 'void *' to 'char *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Do you know why its giving me these errors and how can I fix them.
But What is the correct code you use
And
Quote:
Remember how C++ won't let you arbitrarily assign void* pointers to things
I did not understand what you meant by that.
It is a single selection listbox
Yes it is the second choice but I thought that it would work with both of them(single and muliselection) because if there is just one selection then it may count just 1.
Am I doing rong. If yes, then how do I do the other way?