• Advertisement
Sign in to follow this  

win32 list box doesn't add strings

This topic is 1430 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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

Edited by Eliad Moshe

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

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.
 

Share this post


Link to post
Share on other sites

 

 

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement