Per the documentation:
cchTextMax
Type: int
Size of the buffer pointed to by the pszText member, in characters. If this structure is being used to set item attributes, this member is ignored.
So, you don't use cchTextMax
to set the text of an item.
But to retrieve the text you need a buffer to receive it, and cchTextMax
is the buffer size, so this includes the terminating null. For example:
TVITEM tvi;
TCHAR sBuff[BUF_MAX];
.
.
tvi.pszText = sBuff;
tvi.cchTextMax = BUF_MAX; // Or:
tvi.cchTextMax = sizeof(sBuff)/sizeof(TCHAR);
EDIT:
If you insert callback items you don't insert text, instead you set pszText
to LPSTR_TEXTCALLBACK
, and you must process the TVN_GETDISPINFO
notification, ie the system is asking you "what text should I display for this item?". You can just set pszText
to point to a buffer or copy your data to the buffer already pointed by pszText
- you may copy up to cchTextMax
TCHARs in the latter case.