亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? multiple_sel.shtml

?? mfc資源大全包含MFC編程各個方面的源碼
?? SHTML
字號:
<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>Allowing multiple selection</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td align=center><!--#exec cgi="/cgi/ads.cgi"--><td>
</tr>
</table>


<CENTER>
<H3>
<FONT COLOR="#AOAO99">Allowing multiple selection</FONT></H3></CENTER>

<CENTER>
<H3>

<HR></H3></CENTER>
The tree view control has very limited support for multiple selection. It provides a message to set and retrieve the selection state of an item. On the other hand it does not allow setting focus to a particular item without also selecting it. The side effect of this is that previous item is deselected. This causes a little bit of complication as you will see.

<P>Before we go on I'd like to point to a couple of other sources 
available to help implement multiple selection. The October 1996 
issue of MS Journal has an article by Paul DiLascia which gets you 
started on implementing multiple selection. Another source code 
availabe is from Bendik Engebretsen from his web site at 
<A HREF="http://www.techsoft.no/bendik/">http://www.techsoft.no/bendik/</A>.
He has provided a more full featured implementation and you may 
wish to study his code too before you implement this in your application. 

<H4>Step 1: Add member variable to track first item in selection set</H4>
To emulate the shift selection in a listbox and a list view control, we need to track the first item in the selection set. This is useful when the user changes the selection set further. Add a protected member in your class declaration and initialize it to NULL in the constructor.
<PRE><TT><FONT COLOR="#990000">
protected:
	HTREEITEM m_hItemFirstSel;		// Init to NULL in constructor
</FONT></TT></PRE>
<BR>
<H4>Step 2: Add code to WM_LBUTTONDOWN handler</H4>
We will add code to the WM_LBUTTONDOWN to handle multiple selection. There are a few things about the  tree view control that you should be aware of. When you call the the SelectItem() or when the control selects an item in response to a mouse click, the previous item is deselected. For our purposes we often have to reselect the previous item. Using SetItemState() does not have this side effect. You may ask why not use SetItemState() instead of using SelectItem() or letting the control handle the mouse click. The answer is that SetItemState() does not set focus to the item whereas the other alternatives do. Unlike the list view control, the tree view control does not have the counterpart of LVIS_FOCUSED to set focus to an item. 

<P>The second issue is drag and drop. If the control does not receive the WM_LBUTTONDOWN message, it will not initiate a drag operation. So if you want to support control drag-drop or shift drag-drop you could either let the control participate in the WM_LBUTTONDOWN handling or you could initiate the drag-drop in your own WM_MOUSEMOVE handler. I chose to take the former approach.

<P>The final issue is because of the decision to let WM_LBUTTONDOWN message pass on to the control. The built in handling causes a visible and momentary deselection of the previous item and if we use SetRedraw(FALSE), the control overrides it and causes the whole control to flicker. We could overcome this by calling the SetRedraw() function for the parent window but this can cause a redraw problem with the titletip. A titletip is the window that comes up when we move the cursor over an item that does not fit within the controls width. Its easier to let the momentary deselection remain.

<P>Our decision to pass on the message causes yet another. Clicking on an item that is already selected initiates an edit. This one is easily solved, we deselect the item before passing the message on.

<P>There are three different conditions we check for in this function. Let's cover them one by one. The first condition we check for is whether the control key is down. The usual behaviour of a control click is to toggle the selection state of the item. Before we try toggling the selection state we ascertain that the click is indeed on an item. We then determine the state of the item that will get the focus and the item that will lose the focus and set the appropriate state after calling the base class version of OnLButtonDown().

<P>The shift-click always results in one block of adjoining items being selected. We need to track the starting item of a shift-selected block. This helps when there is further activity with shift-click or shift-arrow keys. The SelectItems() is a helper function that goes through all the items in the tree control and selects the items that belong within the selection block and deselects the rest.

<P>Then there is the normal click with neither the control nor the shift key down. This is the simplest. We just clear any selection and let the default control behaviour do the job.

<PRE><TT><FONT COLOR="#990000">
void CTreeCtrlX::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// Set focus to control if key strokes are needed.
	// Focus is not automatically given to control on lbuttondown

	m_dwDragStart = GetTickCount();

	if(nFlags & MK_CONTROL ) 
	{
		// Control key is down
		UINT flag;
		HTREEITEM hItem = HitTest( point, &flag );
		if( hItem )
		{
			// Toggle selection state
			UINT uNewSelState = 
				GetItemState(hItem, TVIS_SELECTED) & TVIS_SELECTED ? 
							0 : TVIS_SELECTED;
            
			// Get old selected (focus) item and state
			HTREEITEM hItemOld = GetSelectedItem();
			UINT uOldSelState  = hItemOld ? 
					GetItemState(hItemOld, TVIS_SELECTED) : 0;
            
			// Select new item
			if( GetSelectedItem() == hItem )
				SelectItem( NULL );		// to prevent edit
			CTreeCtrl::OnLButtonDown(nFlags, point);

			// Set proper selection (highlight) state for new item
			SetItemState(hItem, uNewSelState,  TVIS_SELECTED);

			// Restore state of old selected item
			if (hItemOld && hItemOld != hItem)
				SetItemState(hItemOld, uOldSelState, TVIS_SELECTED);

			m_hItemFirstSel = NULL;

			return;
		}
	} 
	else if(nFlags & MK_SHIFT)
	{
		// Shift key is down
		UINT flag;
		HTREEITEM hItem = HitTest( point, &flag );

		// Initialize the reference item if this is the first shift selection
		if( !m_hItemFirstSel )
			m_hItemFirstSel = GetSelectedItem();

		// Select new item
		if( GetSelectedItem() == hItem )
			SelectItem( NULL );			// to prevent edit
		CTreeCtrl::OnLButtonDown(nFlags, point);

		if( m_hItemFirstSel )
		{
			SelectItems( m_hItemFirstSel, hItem );
			return;
		}
	}
	else
	{
		// Normal - remove all selection and let default 
		// handler do the rest
		ClearSelection();
		m_hItemFirstSel = NULL;
	}

   CTreeCtrl::OnLButtonDown(nFlags, point);
}
</FONT></TT></PRE>
<BR>
<H4>Step 3: Add code to the WM_KEYDOWN handler</H4>
The code in OnKeyDown will allow user to use the shift-up arrow and the shift-down arrow keys to create and modify the selection. If the key pressed is any other non control character, then the selection is cleared.

<PRE><TT><FONT COLOR="#990000">
void CTreeCtrlX::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if ( (nChar==VK_UP || nChar==VK_DOWN) && GetKeyState( VK_SHIFT )&0x8000)
	{
		// Initialize the reference item if this is the first shift selection
		if( !m_hItemFirstSel )
		{
			m_hItemFirstSel = GetSelectedItem();
			ClearSelection();
		}

		// Find which item is currently selected
		HTREEITEM hItemPrevSel = GetSelectedItem();

		HTREEITEM hItemNext;
		if ( nChar==VK_UP )
			hItemNext = GetPrevVisibleItem( hItemPrevSel );
		else
			hItemNext = GetNextVisibleItem( hItemPrevSel );

		if ( hItemNext )
		{
			// Determine if we need to reselect previously selected item
			BOOL bReselect = 
				!( GetItemState( hItemNext, TVIS_SELECTED ) & TVIS_SELECTED );

			// Select the next item - this will also deselect the previous item
			SelectItem( hItemNext );

			// Reselect the previously selected item
			if ( bReselect )
				SetItemState( hItemPrevSel, TVIS_SELECTED, TVIS_SELECTED );
		}
		return;
	}
	else if( nChar >= VK_SPACE )
	{
		m_hItemFirstSel = NULL;
		ClearSelection();
	}
	CTreeCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
</FONT></TT>
</PRE>
<BR>
<H4>Step 4: Add helper function to clear the selection</H4>
This function is called very often. Every time a user clicks on the tree view control without the shift or the control key pressed, this function gets called. The function as given below is very simple. It scans through all the items in the tree view control and deselects them individually. If the tree holds a lot of items, then this function can prove to be too slow. The <A HREF="get_next.shtml">GetNextItem()</A> function used below is an overloaded function and has been defined in a previous section.

<PRE><TT><FONT COLOR="#990000">
void CTreeCtrlX::ClearSelection()
{
	// This can be time consuming for very large trees 
	// and is called every time the user does a normal selection
	// If performance is an issue, it may be better to maintain 
	// a list of selected items
	for ( HTREEITEM hItem=GetRootItem(); hItem!=NULL; hItem=GetNextItem( hItem ) )
		if ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED )
			SetItemState( hItem, 0, TVIS_SELECTED );
}
</FONT></TT></PRE>
<BR>

<H4>Step 5: Add helper function to select a range of items</H4>
This helper function is used when the user shift-clicks on an item. It takes care of removing selection from items not within the range and selects the items inside the range.

<PRE><TT><FONT COLOR="#990000">
// SelectItems	- Selects items from hItemFrom to hItemTo. Does not
//		- select child item if parent is collapsed. Removes
//		- selection from all other items
// hItemFrom	- item to start selecting from
// hItemTo	- item to end selection at.
BOOL CTreeCtrlX::SelectItems(HTREEITEM hItemFrom, HTREEITEM hItemTo)
{
	HTREEITEM hItem = GetRootItem();

	// Clear selection upto the first item
	while ( hItem && hItem!=hItemFrom && hItem!=hItemTo )
	{
		hItem = GetNextVisibleItem( hItem );
		SetItemState( hItem, 0, TVIS_SELECTED );
	}

	if ( !hItem )
		return FALSE;	// Item is not visible

	SelectItem( hItemTo );

	// Rearrange hItemFrom and hItemTo so that hItemFirst is at top
	if( hItem == hItemTo )
	{
		hItemTo = hItemFrom;
		hItemFrom = hItem;
	}


	// Go through remaining visible items
	BOOL bSelect = TRUE;
	while ( hItem )
	{
		// Select or remove selection depending on whether item
		// is still within the range.
		SetItemState( hItem, bSelect ? TVIS_SELECTED : 0, TVIS_SELECTED );

		// Do we need to start removing items from selection
		if( hItem == hItemTo ) 
			bSelect = FALSE;

		hItem = GetNextVisibleItem( hItem );
	}

	return TRUE;
}
</FONT></TT></PRE>
<BR>

<H4>Step 6: Add utility functions</H4>
Provide utility functions to query on the first selected item and to traverse the list of selected items in either the forward direction or the reverse direction. Again, like the ClearSelection() function, these functions can be time consuming for large trees. 

<PRE><TT><FONT COLOR="#990000">
HTREEITEM CTreeCtrlX::GetFirstSelectedItem()
{
	for ( HTREEITEM hItem = GetRootItem(); hItem!=NULL; hItem = GetNextItem( hItem ) )
		if ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED )
			return hItem;

	return NULL;
}

HTREEITEM CTreeCtrlX::GetNextSelectedItem( HTREEITEM hItem )
{
	for ( hItem = GetNextItem( hItem ); hItem!=NULL; hItem = GetNextItem( hItem ) )
		if ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED )
			return hItem;

	return NULL;
}

HTREEITEM CTreeCtrlX::GetPrevSelectedItem( HTREEITEM hItem )
{
	for ( hItem = GetPrevItem( hItem ); hItem!=NULL; hItem = GetPrevItem( hItem ) )
		if ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED )
			return hItem;

	return NULL;
}
</FONT></TT></PRE>
<BR>

<P>
<HR>
<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>
</BODY>
</HTML>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美亚洲综合久久| 成人免费视频免费观看| 亚洲卡通动漫在线| 亚洲精品乱码久久久久久黑人 | 欧美xingq一区二区| 在线综合视频播放| 91精品在线麻豆| 精品99久久久久久| 欧美国产一区在线| 国产精品人成在线观看免费| 国产精品久久毛片a| 一区二区免费在线| 日本欧美一区二区| 国产成人精品午夜视频免费| 国产成人av电影在线| 91麻豆免费观看| 在线播放日韩导航| 精品国产百合女同互慰| 国产精品激情偷乱一区二区∴| 国产精品天美传媒沈樵| 亚洲制服丝袜在线| 久久99精品久久久| caoporn国产一区二区| 欧美精品在线视频| 久久久久国产精品人| 亚洲欧洲精品一区二区三区 | 色综合av在线| 678五月天丁香亚洲综合网| 2023国产精品视频| 亚洲日本韩国一区| 精品在线视频一区| 99精品久久只有精品| 日韩一二三区视频| 国产精品护士白丝一区av| 视频一区二区欧美| 成a人片国产精品| 制服.丝袜.亚洲.中文.综合| 亚洲国产精品v| 日韩中文字幕亚洲一区二区va在线| 韩日欧美一区二区三区| 欧美在线小视频| 国产欧美日韩亚州综合| 亚洲亚洲人成综合网络| 国产69精品久久777的优势| 678五月天丁香亚洲综合网| 亚洲视频1区2区| 国产精品一品二品| 日韩精品资源二区在线| 亚洲自拍偷拍网站| 成人黄色一级视频| 亚洲精品在线观| 奇米在线7777在线精品| 色天使久久综合网天天| 中文字幕精品三区| 国产一本一道久久香蕉| 91精品国产色综合久久不卡蜜臀| 亚洲人快播电影网| av在线免费不卡| 久久九九久久九九| 国产在线精品免费| 精品久久久久久久久久久久包黑料| 亚洲一区二区三区精品在线| 91视频在线观看| 中文字幕国产一区| 懂色av一区二区三区免费看| 久久久久久久久久久久电影| 蜜桃av一区二区| 日韩欧美视频在线| 精品系列免费在线观看| 日韩三级视频在线看| 奇米色777欧美一区二区| 欧美一区二区三区免费| 首页国产丝袜综合| 日韩欧美国产成人一区二区| 麻豆国产精品视频| 26uuu另类欧美亚洲曰本| 国产一区二区91| 国产偷v国产偷v亚洲高清| 韩国理伦片一区二区三区在线播放| 日韩小视频在线观看专区| 美国av一区二区| 久久久久国产一区二区三区四区| 国产精品一区二区91| 国产精品成人在线观看| 一本久道中文字幕精品亚洲嫩| 国产精品国产三级国产aⅴ入口 | 欧美一区二区在线视频| 久久爱www久久做| 国产日韩av一区二区| jizz一区二区| 亚洲福利视频一区二区| 日韩一区二区高清| 成人美女视频在线看| 一区二区三区在线观看视频| 欧美偷拍一区二区| 久久av资源站| 中文字幕一区二| 91精品在线观看入口| 国产成人免费视| 一区二区三区不卡在线观看| 欧美精品日韩一本| 国产一区二区三区四区五区入口| 国产精品女主播av| 欧美一卡二卡三卡| 99这里都是精品| 日本在线不卡一区| 国产精品国产三级国产三级人妇| 欧美在线免费观看亚洲| 国产一区二区在线观看免费| 亚洲日本护士毛茸茸| 欧美mv日韩mv国产| 欧美偷拍一区二区| 成人一区二区三区视频在线观看| 亚洲网友自拍偷拍| 国产精品毛片久久久久久| 欧美日韩国产大片| 不卡大黄网站免费看| 美女网站视频久久| 亚洲欧美另类小说| 久久久久久久久久久久久女国产乱 | 日本网站在线观看一区二区三区| 久久久久久免费| 欧美肥妇free| 欧美亚洲国产bt| 成人免费高清在线观看| 激情综合色丁香一区二区| 伊人性伊人情综合网| 久久精品一区二区三区不卡牛牛| 欧美精品在线视频| 欧美性受xxxx| 色婷婷久久综合| a美女胸又www黄视频久久| 国产一区二区在线视频| 精品一区二区三区视频在线观看 | 久久www免费人成看片高清| 亚洲午夜日本在线观看| 亚洲情趣在线观看| 中文字幕精品一区二区精品绿巨人| 日韩欧美国产1| 制服.丝袜.亚洲.中文.综合| 欧亚一区二区三区| 欧美色爱综合网| 91福利视频在线| 91成人免费网站| 欧美在线视频日韩| 欧美三级一区二区| 欧美日韩免费观看一区三区| 在线免费观看一区| 在线免费观看一区| 欧美日韩国产综合一区二区 | 久久亚洲免费视频| 日韩精品中文字幕在线不卡尤物| 69p69国产精品| 日韩精品专区在线影院观看| 日韩精品一区二区三区swag| 日韩三级电影网址| 久久毛片高清国产| 国产精品污www在线观看| 欧美激情资源网| 亚洲视频在线观看一区| 一区二区日韩av| 日韩精品亚洲一区二区三区免费| 日日夜夜一区二区| 激情综合色播激情啊| 成人精品视频一区二区三区尤物| 成人黄色网址在线观看| 色系网站成人免费| 欧美麻豆精品久久久久久| 日韩免费观看高清完整版| 久久天堂av综合合色蜜桃网| 久久久欧美精品sm网站| 亚洲日本青草视频在线怡红院| 亚洲综合清纯丝袜自拍| 日韩av一区二区三区四区| 国内成+人亚洲+欧美+综合在线| 成人动漫视频在线| 欧美人与z0zoxxxx视频| 26uuu国产在线精品一区二区| 中文字幕av免费专区久久| 一区二区三区国产豹纹内裤在线 | 中文字幕精品在线不卡| 亚洲一二三四区不卡| 美女看a上一区| 色综合色狠狠天天综合色| 欧美一级电影网站| 亚洲色图欧洲色图| 免费观看久久久4p| 91玉足脚交白嫩脚丫在线播放| 欧美日韩精品一区二区三区| 国产欧美久久久精品影院| 亚洲一区二区偷拍精品| 国产成人在线色| 91精品国产色综合久久ai换脸| 中文字幕一区二区三区乱码在线 | 97精品久久久午夜一区二区三区 | 99久久综合精品| 这里只有精品电影| 亚洲免费色视频| 国产美女在线观看一区| 欧美一区二区在线观看|