find_data.shtml

来自「mfc资源大全包含MFC编程各个方面的源码」· SHTML 代码 · 共 111 行

SHTML
111
字号
<HTML><!-- Header information--><HEAD>   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">   <!-- add your name in the CONTENT field below -->   <META NAME="Author" CONTENT="Gage Renzi">   <TITLE>TreeView - Finding an item (matching data instead of label)</TITLE></HEAD><!-- Set background properties --><body background="/fancyhome/back.gif" bgcolor="#FFFFFF"><!-- A word from our sponsors... --><table WIDTH="100%"><tr WIDTH="100%"><td align=center><td></tr></table><CENTER><H3><FONT COLOR="#AOAO99"><!-- Article Title -->Finding an item (matching data instead of label)</FONT></H3></CENTER><HR><!-- Author and contact details -->This article was contributed by <!-- Author Email --><A HREF="mailto:davisnb@gte.net"><!-- Author Name -->Nancy Davis</A>.<!-- Text / source code --><p><!-- The 'p' starts a paragraph of normal text -->FindItemData is another tree control searching function very similar to theFindItem function. Instead of matching  a substring of the label, itcompares the item's associated data. If an exact data match is found, thematching item is returned, otherwise NULL. This function uses the functions<A HREF="http://www.codeguru.com/treeview/get_next.shtml">GetNextItem</A>, <A HREF="http://www.codeguru.com/treeview/get_prev.shtml">GetPrevItem</A>, and <A HREF="http://www.codeguru.com/treeview/get_last.shtml">GetLastItem</A> seen previously.In order to use this function, your tree control items must have associateddata, which can be set using SetItemData. Also, the item'smask must include TVIF_PARAM.<!-- start a block of source code --><PRE><TT><FONT COLOR="#990000">// FindItemData  - Finds an item whose data matches the passed in lparam value.// Returns       - Handle to the item or NULL// lparam        - Data to search for// bDownDir      - Search direction - TRUE for down// hItem         - Item to start searching from. NULL for currently selected itemHTREEITEM CTreeCtrlX::FindItemData(DWORD lparam, BOOL bDownDir /*=TRUE*/, HTREEITEM hItem /*=NULL*/){	HTREEITEM htiSel = hItem ? hItem : GetSelectedItem();	HTREEITEM htiCur = bDownDir ? GetNextItem( htiSel ) :	GetPrevItem( htiSel );	if( htiCur == NULL )	{		if( bDownDir )			htiCur = GetRootItem();		else			htiCur = GetLastItem( NULL );	}	while( htiCur && htiCur != htiSel )	{		DWORD sItemData = GetItemData( htiCur );		if (sItemData == lparam )			return htiCur;		htiCur = bDownDir ? GetNextItem( htiCur ) : GetPrevItem( htiCur );		if( htiCur == NULL )		{			if( bDownDir )				htiCur = GetRootItem();			else				htiCur = GetLastItem( NULL );		}	}	return NULL;}<!-- end the block of source code --></FONT></TT></PRE><!-- create more blocks of source code as needed --><!-- Posted / Update  date mm/dd/yy - add to the list --><p>Date Posted: <!-- date here -->04/29/1998<P><HR><!-- Codeguru contact details --><TABLE BORDER=0 WIDTH="100%"><TR><TD WIDTH="33%"><FONT SIZE=-1><A HREF="http://www.codeguru.com">Goto HomePage</A></FONT></TD><TD WIDTH="33%"><CENTER><FONT SIZE=-2>&copy; 1998 Zafir Anjum</FONT>&nbsp;</CENTER></TD><TD WIDTH="34%"><DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A>&nbsp;</FONT></DIV></TD></TR></TABLE><!-- Counter --><CENTER><FONT SIZE=-2>175</FONT></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?