Getting text from tab control item is failing
I'm trying to get the text from a tab control like this:
TCITEM itm;
itm.mask = TCIF_TEXT;
TabCtrl_GetItem(engineGL.controls.MainGlTab.MainTabHwnd,i,&itm);
but the psztext part of the structure is returning a bad 开发者_Go百科pointer (0xcccccccccc).
I create the tabs like this:
void OGLMAINTAB::AddTab( char *name )
{
TCITEM itm;
itm.cchTextMax = 30;
itm.pszText = name;
itm.mask = TCIF_TEXT;
int numitems = TabCtrl_GetItemCount(MainTabHwnd);
SendMessage(MainTabHwnd,TCM_INSERTITEM,numitems,(LPARAM)&itm);
}
why is it not returning the text as I want it to?
Thanks
When setting the text, cchTextMax is ignored.
When getting the text, you need to provide your own buffer and set cchTextMax accordingly. (Note that when the message returns, you need to use the itm.pszText pointer and not your own buffer since the control will sometimes change the pszText member to point to its internal buffer)
精彩评论