I have a problem when resizing the drop-down box in a combobox. I calculate the length of the longest string that I am inserting with GetTextExtentPoint32(), then set the size with a CB_SETDROPPEDWIDTH message. The list size does change, but it's always significantly wider than the longest string in the list. To test, on the CBN_DROPDOWN notification, I check the width with CB_GETDROPPEDWIDTH, then iterate through each string in the list to check size. They are the same, respectively, as when I set them; CB_GETDROPPEDWIDTH returns the same number as the longest string in the list, but the displayed list box is much wider than that string.
This is the code to set the width:
hDC = GetDC(m_handle);
GetTextExtentPoint32(hDC, pszText, strlen(pszText), &size);
SendMessage(m_handle, CB_SETDROPPEDWIDTH, (WPARAM) size.cx, 0L);