CTabCtrl:
添加TAB:
............................
CString title = "TAB1";
CString lparamText = .......
TC_ITEM tItem;
tItem.mask = TCIF_TEXT | TCIF_PARAM | TCIF_IMAGE;
tItem.pszText = (LPSTR)title.GetBuffer();
title.ReleaseBuffer();
tItem.lParam = reinterpret_cast<DWORD>(new CString(lparamText));
tItem.cchTextMax = strlen(tItem.pszText);
mTab.InsertItem(0,&tItem);
.........................
获取TAB 的ITEM的LPARAM:
....................
CString *pString = reinterpret_cast<CString*>(tItem.lparam);
CString g = pString->GetBuffer(); //在RELEASE下这一行导致CRASH ,
pString->ReleaseBuffer();
return g;
添加TAB:
............................
CString title = "TAB1";
CString lparamText = .......
TC_ITEM tItem;
tItem.mask = TCIF_TEXT | TCIF_PARAM | TCIF_IMAGE;
tItem.pszText = (LPSTR)title.GetBuffer();
title.ReleaseBuffer();
tItem.lParam = reinterpret_cast<DWORD>(new CString(lparamText));
tItem.cchTextMax = strlen(tItem.pszText);
mTab.InsertItem(0,&tItem);
.........................
获取TAB 的ITEM的LPARAM:
....................
CString *pString = reinterpret_cast<CString*>(tItem.lparam);
CString g = pString->GetBuffer(); //在RELEASE下这一行导致CRASH ,
pString->ReleaseBuffer();
return g;
比如
tItem.lParam = reinterpret_cast <DWORD> (new CString(lparamText));
tItem.cchTextMax = strlen(tItem.pszText);不过个人觉得还不至于在拷贝pString-> GetBuffer();的时候会出错啊CString g = pString-> GetBuffer(); //在RELEASE下这一行导致CRASH ,
pString-> ReleaseBuffer();
return g;
这几句直接改
return *pString;看看
另外,不得不说,楼主对于CString的使用方式确实不值得提倡,完全违背了CString的设计意图。而且程序中的强转也使用过度,象CString g = pString-> GetBuffer();这样的拷贝完全没有必要使用非常量指针,如楼上所说直接返回*pString就足够了。