get_next.shtml.htm
来自「mfc资料集合5」· HTM 代码 · 共 81 行
HTM
81 行
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Zafir Anjum">
<META NAME="GENERATOR" CONTENT="Mozilla/4.0 [en] (WinNT; I) [Netscape]">
<TITLE>Get next item in outline</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><td>
</tr>
</table>
<CENTER>
<H3>
<FONT COLOR="#AOAO99">Get next item in outline</FONT></H3></CENTER>
<CENTER>
<H3>
<HR></H3></CENTER>
Imagine that the outline is completely expanded. Pressing the down key
will take you down on line to the next item. Now imagine that instead of
expanding the outline and pressing the down key, you want to get to the
items in the same sequence programmatically. Although the CTreeView control
provides a GetNextItem() function, it does not provide direct support for
our needs. Listed below is an overloaded version of GetNextItem() taking
a single argument. Before we actually look at the function lets first look
at the declaration of the function in the CTreeView derived class.
<BR>
<PRE><TT><FONT COLOR="#990000"> HTREEITEM GetNextItem( HTREEITEM hItem, UINT nCode ){
return CTreeCtrl::GetNextItem( hItem, nCode );
}
HTREEITEM GetNextItem( HTREEITEM hItem);</FONT></TT></PRE>
It is important that we override the original function taking two arguments
otherwise our new version of the function will hide it. Now here is the
listing of the overloaded GetNextItem() function.
<BR>
<PRE><TT><FONT COLOR="#990000">// GetNextItem - Get next item as if outline was completely expanded
// Returns - The item immediately below the reference item
// hItem - The reference item
HTREEITEM CTreeCtrlX::GetNextItem( HTREEITEM hItem )
{
HTREEITEM hti;
if( ItemHasChildren( hItem ) )
return GetChildItem( hItem ); // return first child
else{
// return next sibling item
// Go up the tree to find a parent's sibling if needed.
while( (hti = GetNextSiblingItem( hItem )) == NULL ){
if( (hItem = GetParentItem( hItem ) ) == NULL )
return NULL;
}
}
return hti;
}</FONT></TT>
</PRE>
<P>
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="../index.htm" tppabs="http://www.codeguru.com/">Goto HomePage</A></FONT></TD>
<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>© 1997 Zafir Anjum</FONT> </CENTER>
</TD>
<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A> </FONT></DIV>
</TD>
</TR>
</TABLE>
<CENTER> <IMG SRC="../cgi/Count.cgi-ft=2&dd=E-df=tv_get_next.cnt" tppabs="http://www.codeguru.com/cgi/Count.cgi?ft=2&dd=E%7cdf=tv_get_next.cnt" ALIGN="BOTTOM" BORDER="0"></CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?