15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Flash when clearing CTreeCtrl

Grant Shirreffs Great Elk -- Grant.S@greatelk.com
Friday, November 15, 1996

Environment: VC++ 4.2-flat, Win NT 4.0

Does anyone know how to prevent the full-window flash when clearing a
CTreeCtrl using DeleteAllItems( )?  I have tried enclosing the call in
SetRedraw(FALSE)/SetRedraw(TRUE) thus:

	m_Tree.SetRedraw(FALSE);
	m_Tree.DeleteAllItems();
	m_Tree.SetRedraw(TRUE);
	m_Tree.Invalidate();

but this has the bizarre effect of, when the tree list is refilled,
making the last item in the root level not display until you expand it.

My app has a tree control being continually cleared and refilled in
response to user input, so the repeated flash from the DeleteAllItems( )
is very distracting.

Any suggestions?

Grant Shirreffs
The Great Elk Company Limited
http://www.greatelk.com




Jim Barry -- Jim.Barry@ilp.com
Monday, November 18, 1996

[Mini-digest: 2 responses]

On 15 November 1996 03:29, Grant Shirreffs (Great Elk)[SMTP:Grant.S@greatelk.com] wrote:
>Environment: VC++ 4.2-flat, Win NT 4.0
>
>Does anyone know how to prevent the full-window flash when clearing a
>CTreeCtrl using DeleteAllItems( )?  I have tried enclosing the call in
>SetRedraw(FALSE)/SetRedraw(TRUE) thus:
>
>	m_Tree.SetRedraw(FALSE);
>	m_Tree.DeleteAllItems();
>	m_Tree.SetRedraw(TRUE);
>	m_Tree.Invalidate();
>
>but this has the bizarre effect of, when the tree list is refilled,
>making the last item in the root level not display until you expand it.
>
>My app has a tree control being continually cleared and refilled in
>response to user input, so the repeated flash from the DeleteAllItems( )
>is very distracting.
>
>Any suggestions?
>
>Grant Shirreffs
>The Great Elk Company Limited
>http://www.greatelk.com

This is a known problem. See article Q130611 on MSDN or Books Online. Unfortunately, the only advice offered is to not use WM_SETREDRAW.

Jim Barry
Interactive Learning Productions
Newcastle upon Tyne, UK

-----From: "GoroKhM1" 

You wrote: 

> Does anyone know how to prevent the full-window flash when clearing 
> a CTreeCtrl using DeleteAllItems( )? 

The method from my app may help you. My app has a splitter with a tree 
view in left pane and a form view in right pane. In my app the current 
selection in a tree view controls form view.  I implemented that method
to reduce tree deletion time, but I think it will be helpful to prevent 
flashing.

void CMyTreeView::DeleteAllTree()
{
  if (m_hSelItem == NULL) // already empty
    return;

  // DeleteAllItems() works fine, with one problem.
  // Deletion process is sequentional, and if currently 
  // deleted item is selected, the next item will be
  // selected. It means that FormView will be updated.
  // If there are 100 items _below_ selected item, FormView
  // will be updated 100 times with all DoDataExchange()!
  // It's time consuming. To prevent this move selected
  // item to the highest level (without parents) and skip
  // it while deletion in a loop. 

  m_iLockSel++;
  // Move selection to the highest level (without parents)
  HTREEITEM hItem = m_hSelItem;
  while (m_pTree->GetParentItem(hItem))
    hItem = m_pTree->GetParentItem(hItem);
  m_pTree->SelectItem(hItem);
  m_hSelItem = hItem;

  // Delete all items except selected
  while (TRUE)
  {
    hItem = m_pTree->GetRootItem(); // first sibling without parents
    if ( hItem == m_hSelItem)
      hItem = m_pTree->GetNextSiblingItem(hItem);
    if (hItem)
      m_pTree->DeleteItem(hItem); // with all children
    else
      break;
  }

  // Delete the rest
  m_pTree->DeleteAllItems();

  m_hSelItem = NULL;
  m_iLockSel--;
} // CMyTreeView::DeleteAllTree()


Counter m_iLockSel is used to prevent not desired updates, eg:

void CMyTreeView::OnSelChanging(NMHDR* pNMHDR, LRESULT* pResult) 
{
  // TVN_SELCHANGING notification message.

  if (m_iLockSel)
    return;

  ...

} // CMyTreeView::OnSelChanging()

-mg

MarkG@usa.net





     





| Вернуться в корень Архива |