Listboxes do not auto-resize. The best we’ve got is:
SendMessage(my_listbox, LB_SETHORIZONTALEXTENT, 1000, 0);
MS helpfully notes that “…a list box does not update its horizontal extent dynamically.”
(why the heck not…but I digress)
How can the width be set dynamically to avoid truncating the text of a message longer than 1000px?
if I understand the question… 🙂
You’ll essentially need to measure all of the items in the list box and calculate the maximum width of the list box contents, and then adjust the width of the listbox.
Here’s some code from this project (that adds a automatic horizontal scrollbar to listboxes). This snippet is called when the font changes but it demonstrates (roughly) what’s needed:
and…