PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: AfxGetComboBoxText  (Read 96 times)

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8848
  • Windows 10
    • PlanetSquires Software
AfxGetComboBoxText
« on: August 19, 2019, 03:00:19 PM »

Hi Jose,

Looks like AfxGetComboBoxText is returning a trailing NULL character. You probably need to modify the last line of the function similar to how you handle AfxGetWindowText.

Current code in AfxCtl.inc:
Code: [Select]
' ========================================================================================
' Gets a string from a list in a combo box.
' - hComboBox: A handle to the combobox.
' - nIndex: The zero-based index of the item.
' ========================================================================================
PRIVATE FUNCTION AfxGetComboBoxText (BYVAL hComboBox AS HWND, BYVAL nIndex AS LONG) AS CWSTR
   DIM nLen AS LONG = SendMessageW(hComboBox, CB_GETLBTEXTLEN, nIndex, 0)
   DIM cwsText AS CWSTR = SPACE(nLen + 1)
   SendMessageW(hComboBox, CB_GETLBTEXT, nIndex, cast(LPARAM, *cwsText))
   RETURN cwsText
END FUNCTION
' ========================================================================================

Maybe:
   RETURN cwsText

Should be:
  RETURN LEFT(**cwsText, LEN(cwsText) - 1)

Took me a while to find out why some of my Form files with ToolBars were not loading. Appears that the NULL was being inserted into the file causing the parsing on load to fail.

Thanks,

« Last Edit: August 19, 2019, 03:14:24 PM by Paul Squires »
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3200
Re: AfxGetComboBoxText
« Reply #1 on: August 19, 2019, 03:20:05 PM »

Done. Thanks for spotting it.