精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● 软件开发>>软件体系结构及资料汇编>>用Visual C++ 6.0 CListCtrl通过拖/放实现标题提示

主题:用Visual C++ 6.0 CListCtrl通过拖/放实现标题提示
发信人: chenjz(不再哭傲江湖)
整理人: zelor(2001-01-17 10:20:53), 站内信件
          用Visual C++ 6.0 CListCtrl通过拖/放实现标题提示

作者:Kevin Delgado   编译:刘峰

  我希望给 Visual C++ 6.0的CListCtrl类增加一标题提示类。然而像本站点先前指出的一样,对列表控制的LVS_EX_HEADERDRAGDROP风格的编程是很难的。使用新出的VC6的CListCtrl 类,我修改了Zafir Anjum先生的CellRectFromPoint()函数来处理标题这类情况。其编码如下:

int CTRListCtrl::CellRectFromPoint(CPoint & point, RECT * cellrect, int * col) 
{
int colnum;

// Make sure that the ListView is in LVS_REPORT
if( (GetStyle() & LVS_TYPEMASK) != LVS_REPORT )
return -1;

// Get the top and bottom row visible
int row = GetTopIndex();
int bottom = row + GetCountPerPage();
if( bottom > GetItemCount() )
bottom = GetItemCount();

// Get the number of columns
CHeaderCtrl* pHeader = CListCtrl::GetHeaderCtrl();
int nColumnCount = pHeader->GetItemCount();

// Loop through the visible rows
for( ;row <= bottom; row++)
{
// Get bounding rect of item and check whether point falls in it.
CRect rect;
GetItemRect( row, &rect, LVIR_BOUNDS );

// We use the rects of the header items to determine if the point falls in a
// given column. Thus, the order of the columns is no longer important.

CRect colRect;

if( rect.PtInRect(point) )
{
// Now find the column
for( colnum = 0; colnum < nColumnCount; colnum++ )
{
pHeader->GetItemRect(colnum, &colRect);

if(  (point.x >= colRect.left) && (point.x <= (colRect.left + colRect.Width()) ) )
{
// Found the column
RECT rectClient;
GetClientRect( &rectClient );
if( point.x > rectClient.right )
return -1;

if( col ) 
*col = colnum;

rect.right = colRect.left + colRect.Width();
rect.left = colRect.left;

if( rect.right > rectClient.right ) 
rect.right = rectClient.right;

*cellrect = rect;
return row;
}
}
}
}
return -1;
}

--------------------------------------------------------------------------------
 
VCSky网站版权所有,未经本站许可严禁转载!  刘峰制作
 
Copyright 2000 All Rights Reserved By www.vcsky.net
 
由于本站是一个完全免费的个人站点,所有资料均由我亲自从国外网站搜集翻译整理,并坚持每天上网回复论坛中网友所提问题。
 
如果您觉得本站对您还有所帮助,烦请点击本站的广告条,支持本站的长远发展。谢谢!!
 
 
Free Advertising from Click2Net!  



----
我能翻译善写作熟电脑会说话可是为什么没工作?

[关闭][返回]