WEB开发网
开发学院软件开发VC 在动态集中使用虚拟CListView 阅读

在动态集中使用虚拟CListView

 2010-06-04 20:39:26 来源:WEB开发网   
核心提示:建立LVN_GETDISPINFO消息的处理函数:void CVirtualListViewView::OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult){LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;TCHAR szValue[M

建立LVN_GETDISPINFO消息的处理函数:

void CVirtualListViewView::OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
TCHAR szValue[MAX_PATH];
COleVariant varValue;
long index = pDispInfo->item.iItem;
long subItem = pDispInfo->item.iSubItem;
if(pDispInfo->item.mask & LVIF_TEXT)
{
try
{
pRecordSet->SetAbsolutePosition(index);//Set the file to desired index
}
catch(CDaoException* e)
{
return;
}
try
{
if(subItem)
pRecordSet->GetFieldValue(subItem, varValue);
else
pRecordSet->GetFieldValue(0, varValue);
}
catch(CDaoException* e)
{
return;
}
const VARIANT* variant = LPCVARIANT(varValue);
switch(variant->vt)
{
case VT_I2:{ wsprintf(szValue, "%d", variant->iVal);
break;
}
case VT_I4:{ wsprintf(szValue, "%d", variant->lVal);
break;
}
case VT_R4:{ wsprintf(szValue, "%f", variant->fltVal);
break;
}
case VT_R8:{ wsprintf(szValue, "%f", variant->dblVal);
break;
}
case VT_CY:{ COleCurrency c(varValue);
CString s = c.Format();//ie. 1.00
strcpy(szValue, s.GetBuffer(s.GetLength()));
s.ReleaseBuffer();
break;
}
case VT_DATE:{ COleDateTime t(variant->date);
CString s = t.Format( "%A, %B %d, %Y" );//Day of Week, Month Day, Year
strcpy(szValue, s.GetBuffer(s.GetLength()));
s.ReleaseBuffer();
break;
}
case VT_BSTR:{ CString str = V_BSTRT( &varValue );//convert BSTR to CString
strcpy(szValue, str.GetBuffer(str.GetLength()));
str.ReleaseBuffer();
break;
}
case VT_BOOL:{ if(variant->boolVal)
strcpy(szValue, "TRUE");
else
strcpy(szValue, "FALSE");
break;
}
case VT_UI1:{ strcpy(szValue, (char*)variant->bVal);
break;
}
default: break;
}
lstrcpyn(pDispInfo->item.pszText, szValue, pDispInfo->item.cchTextMax);//set item text
}
if(pDispInfo->item.mask & LVIF_IMAGE)
pDispInfo->item.iImage = 0;//set image to first in list
*pResult = 0;
}

上一页  1 2 

Tags:动态 集中 使用

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接