win32 list box doesn't add strings

Started by
5 comments, last by Aardvajk 10 years, 1 month ago

So I created a win32 dialog with a list box in it, that has the id IDC_LIST1.

Then I just tried to add a string to it with:

SendDlgItemMessage(hDlg, IDC_LIST1, LB_ADDSTRING, 0, (LPARAM)L"test");

but nothing appears!

So I later added an edit box,and changed it's text,that,indicates that there is no hwnd problem or something like that. What could the problem be?

Advertisement

Could be a few things. Show the creation of the list box (is ID set properly?),

Which value is returned?

From MSDN:

The return value is the zero-based index of the string in the list box. If an error occurs, the return value is LB_ERR. If there is insufficient space to store the new string, the return value is LB_ERRSPACE.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I don't think it was the id,i checked it many times, and i even added other listboxes and tried with them too. I just restarted visual studio,deleted all the listboxes and just added a new one and it just worked...not sure what was wrong...

Maybe your project by default is set to MultiByte instead of unicode, try SendDlgItemMessageW.

Maybe your project by default is set to MultiByte instead of unicode, try SendDlgItemMessageW.

If SendDlgItemMessageA was being called, the code wouldn't compile with the L prefix on the test string.

Maybe your project by default is set to MultiByte instead of unicode, try SendDlgItemMessageW.

If SendDlgItemMessageA was being called, the code wouldn't compile with the L prefix on the test string.

See the function def at MSDN : http://msdn.microsoft.com/en-us/library/windows/desktop/ms645515%28v=vs.85%29.aspx
You need to cast the last parameter to LPARAM.

Maybe your project by default is set to MultiByte instead of unicode, try SendDlgItemMessageW.

If SendDlgItemMessageA was being called, the code wouldn't compile with the L prefix on the test string.

See the function def at MSDN : http://msdn.microsoft.com/en-us/library/windows/desktop/ms645515%28v=vs.85%29.aspx
You need to cast the last parameter to LPARAM.

Oh yeah, sorry. My mistake. Potential nastiness with UNICODE vs multibyte there with the cast, you're quite correct.

This topic is closed to new replies.

Advertisement