📄 01_9_14_9.asp.html
字号:
<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<TITLE>计算机世界网-在动态集中使用虚拟CListView</TITLE></HEAD>
<style>
.a14{font-size:14px;text-indent:25px;line-height:20px}
.f{font-size:18px;color=#0f3ccd}
img{border:0px;}
td,p,input{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<center>
<BODY topmargin=2 leftmargin=0>
<style>
.v12{font-size:10pt;color:"#ffffff";FONT-WEIGHT: bold}
.v14{font-size:14px;text-indent:25px;line-height:20px}
img{border:0px;}
td,p,input,select{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<style>
.v13{font-size:10pt;color:"#ffffff";FONT-WEIGHT: bold}
.v12{font-size:13px;color:"#4C029C";FONT-WEIGHT: bold}
.v14{font-size:14px;text-indent:25px;line-height:20px}
img{border:0px;}
td,p,input,select{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<!--头-->
<table align=center cellpadding="0" cellspacing="0" border="0" width="767">
<tr><td valign=bottom>
<table cellpadding="0" cellspacing="0" border=0>
<tr><td valign=top><img src="../../../../../center/image/ccwlogo.gif"></td></tr>
<tr><td height="27" valign=top><img src="../../../../../center/image/knowledge.gif" width="207" height="27"></td></tr>
</table></td>
<td valign=bottom width=556 bgcolor="#4c029c" height=96>
<table cellpadding="0" cellspacing="0" border=0 width=556 bgcolor="#4c029c" height=96>
<tr><td height=25 valign=bottom bgcolor="#ffffff" colspan=2 ><img src="../../../../../image2002/top.gif" usemap="#F"></td></tr>
<tr valign=middle >
<td align=center valign=middle height="60" align=center>
<!-- <a href="http://www.ccw.com.cn/search/" target=_blank><img src="../../../../../img2/esearch.GIF" border=0 width=468 height=60></a> --><a href="http://www.ccw.com.cn/html/search/thememail/" target=_blank><img src="../../../../../img2/topbanner_thememail.GIF" border=0 width=468 height=60></a>
</td>
<td align=center width=15%>
<table width=95%>
<tr><td><a href="mailto:center@ccw.com.cn?subject=我要投稿:" target=_blank><font class=v13>我要投稿</a><br><a href="mailto:center@ccw.com.cn?subject=编读往来"><font class=v13>编读往来</a><br><a href="javascript:AddBookMark('计算机世界网首页')"><font class=v13>加入收藏</a></font></td></tr>
</table>
</td>
</tr>
<tr><td bgcolor="#ffffff" height=1 colspan=2 ></td></tr>
<tr><td bgcolor="#b4aafc" height=2 colspan=2 ></td></tr></table>
<map name="F">
<area href="http://www.ccw.com.cn/" shape="rect" coords="29, 3, 61, 18" target=_blank>
<area href="http://www.ccw.com.cn/news1/" shape="rect" coords="72, 3, 143, 18" target=_blank>
<area href="http://www.ccw.com.cn/center/" shape="rect" coords="155, 2, 216, 18" target=_blank>
<area href="http://www.ccw.com.cn/work/" shape="rect" coords="225, 2, 299, 18" target=_blank>
<area href="http://www.ccw.com.cn/search/" shape="rect" coords="310, 3, 364, 19" target=_blank>
<area href="http://www3.ccw.com.cn/" shape="rect" coords="372, 2, 412, 19" target=_blank>
<area href="http://www2.ccw.com.cn/" shape="rect" coords="424, 2, 550, 18" target=_blank></map>
</td></tr>
<tr><td colspan=2 bgcolor="#b4aafc">
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr>
<td width=26% align=center><font class=v12>【2003年6月24日】 </font></td>
<td CLASS=V12> <a href="http://www.ccw.com.cn/center/topic.asp">专 题</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/tech.asp">技 术</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/prod.asp">产 品</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/app.asp">应 用</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/net.asp">网 络</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/prog.asp">编 程</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/skill.asp">技 巧</a> </td>
</tr>
</table>
</td></tr>
</table>
<table align=center width=728>
<tr><td align=center><br><h2><font color='#0f3ccd'>在动态集中使用虚拟CListView</font></h2>
<br><b>作者:Sam Fugarino 翻译:刘峰</b>
</td></tr><tr><td align=right>01-9-14 下午 02:47:25<br><hr size=1 width=718 color=#f46240></td></tr></table><br>
<table align=center width=728><tr><td valign=top width=600>
<table width=100% ><tr><td class=a14>这个例子举例说明了如何与IE4的虚列表视一起使用一个Access数据库文件。</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
加载大量数据到CListView派生类是一个非常慢的过程,甚至当数据在内存是也是如此。在数据库中存取数据时就更慢了。一个列表视的新的特点是当它需要数据是再加载的能力。下面是具体步骤。</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
你必须安装IE3以后版本的COMCTL32.DLL。</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
打开你的数据库文件。</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
使用你的文档对象打开你的数据库文件和记录集。在该例子中,我用了一个动态集类型的记录集。这样就允许我使用CDaoRecordSet的SetAbsolutePosition成员函数设置一个记录集对象的当前记录相对记录号。</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
BOOL CVirtualListDoc::OnOpenDocumentFile(LPCTSTR lpszPathname)</td></tr></table><table width=100% ><tr><td class=a14>
{</td></tr></table><table width=100% ><tr><td class=a14>
CString m_FileName = lpszPathname;</td></tr></table><table width=100% ><tr><td class=a14>
pDBase = new CDaoDatabase;</td></tr></table><table width=100% ><tr><td class=a14>
pDBase->Open(m_FileName);</td></tr></table><table width=100% ><tr><td class=a14>
CString strSQL = "SELECT * FROM TableName ORDER BY ColumnName";//Set up SQL statement</td></tr></table><table width=100% ><tr><td class=a14>
pRecordSet = new CDaoRecordset(pDBase);</td></tr></table><table width=100% ><tr><td class=a14>
pRecordSet->Open(dbOpenDynaset, strSQL);//Open recordset using SQL statement</td></tr></table><table width=100% ><tr><td class=a14>
pRecordSet->MoveLast();//you have to access the records in the dynaset to get GCDaoRecordSet::etRecordCount() to work</td></tr></table><table width=100% ><tr><td class=a14>
}</td></tr></table><table width=100% ><tr><td class=a14>
设置该列表视的风格为LVS_OWNERDATA;</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
BOOL CVirtualListView::PreCreateWindow(CREATESTRUCT& cs)</td></tr></table><table width=100% ><tr><td class=a14>
{</td></tr></table><table width=100% ><tr><td class=a14>
cs.lpszName = WC_LISTVIEW;</td></tr></table><table width=100% ><tr><td class=a14>
cs.style &= ~LVS_TYPEMASK;</td></tr></table><table width=100% ><tr><td class=a14>
cs.style |= LVS_REPORT;</td></tr></table><table width=100% ><tr><td class=a14>
cs.style |= LVS_EDITLABELS;</td></tr></table><table width=100% ><tr><td class=a14>
cs.style |= LVS_OWNERDATA;</td></tr></table><table width=100% ><tr><td class=a14>
CListView::PreCreateWindow(cs);</td></tr></table><table width=100% ><tr><td class=a14>
}</td></tr></table><table width=100% ><tr><td class=a14>
在列表中设置项的个数。你需要告诉列表视将包括多少项。这通过发送一个LVN_SETITEMCOUNT到该列表控制。在列表视的OnInitialUpdate()成员函数中来完成上述工作,并且设置列表视的列数。你能够发送一个LVM_SETEXTENDLISTVIEWSTYLE消息给该控件来设置一些新的扩展的列表视风格。</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
void CVirtualListView::OnInitialUpdate()</td></tr></table><table width=100% ><tr><td class=a14>
{</td></tr></table><table width=100% ><tr><td class=a14>
CListView::OnInitialUpdate();</td></tr></table><table width=100% ><tr><td class=a14>
/*set number of items in list to number of items in RecordSet*/</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
/* create image list*/</td></tr></table><table width=100% ><tr><td class=a14>
imageList.Create(IDB_IMAGELIST, 16, 1, RGB(0,0,0));</td></tr></table><table width=100% ><tr><td class=a14>
GetListCtrl().SetImageList(&imageList, LVSIL_SMALL);</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
/* set extended stlyes*/</td></tr></table><table width=100% ><tr><td class=a14>
DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | /*LVS_EX_SUBITEMIMAGES |*/</td></tr></table><table width=100% ><tr><td class=a14>
LVS_EX_HEADERDRAGDROP | LVS_EX_TRACKSELECT;</td></tr></table><table width=100% ><tr><td class=a14>
GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LPARAM(dwExStyle));</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
LV_COLUMN lvColumn;</td></tr></table><table width=100% ><tr><td class=a14>
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;</td></tr></table><table width=100% ><tr><td class=a14>
lvColumn.fmt = LVCFMT_LEFT;</td></tr></table><table width=100% ><tr><td class=a14>
lvColumn.cx = 120;</td></tr></table><table width=100% ><tr><td class=a14>
for(int i = 0; i < GetFieldCount(); i++) // set up columns</td></tr></table><table width=100% ><tr><td class=a14>
{</td></tr></table><table width=100% ><tr><td class=a14>
CDaoFieldInfo fieldinfo;</td></tr></table><table width=100% ><tr><td class=a14>
pRecordSet->GetFieldInfo(i, fieldinfo);//get field name</td></tr></table><table width=100% ><tr><td class=a14>
int len = fieldinfo.m_strName.GetLength();</td></tr></table><table width=100% ><tr><td class=a14>
CString temp = fieldinfo.m_strName;</td></tr></table><table width=100% ><tr><td class=a14>
TCHAR* szBuffer = new TCHAR[len + 1];</td></tr></table><table width=100% ><tr><td class=a14>
strcpy(szBuffer, temp.GetBuffer(len));</td></tr></table><table width=100% ><tr><td class=a14>
temp.ReleaseBuffer();</td></tr></table><table width=100% ><tr><td class=a14>
lvColumn.pszText = szBuffer;</td></tr></table><table width=100% ><tr><td class=a14>
GetListCtrl().InsertColumn(i, &lvColumn);//insert column</td></tr></table><table width=100% ><tr><td class=a14>
delete szBuffer;</td></tr></table><table width=100% ><tr><td class=a14>
}</td></tr></table><table width=100% ><tr><td class=a14>
/*set number of items in ListView*/</td></tr></table><table width=100% ><tr><td class=a14>
count = pRecordSet->GetRecordCount();//Get number of records</td></tr></table><table width=100% ><tr><td class=a14>
GetListCtrl().SendMessage(LVM_SETITEMCOUNT, (WPARAM)count, (LPARAM)LVSICF_NOINVALIDATEALL);</td></tr></table><table width=100% ><tr><td class=a14>
}</td></tr></table><table width=100% ><tr><td class=a14>
建立LVN_GETDISPINFO消息的处理函数:</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
void CVirtualListViewView::OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult) </td></tr></table><table width=100% ><tr><td class=a14>
{</td></tr></table><table width=100% ><tr><td class=a14>
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;</td></tr></table><table width=100% ><tr><td class=a14>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -